C++ Logo

std-proposals

Advanced search

[std-proposals] Regarding P2826 Replacement function

From: Михаил Найденов <mihailnajdenov_at_[hidden]>
Date: Sun, 23 Apr 2023 11:47:04 +0300
Hello, I believe P2826R0 should also be seen/discussed from the
viewpoint of interface implementation.

Say QSize wants to implement an interface, which expects a "property-like",
unified access in the form of `int width() const` and `void width(int)`
required for a tool or a library.

Then QSize could do `width(int) = setWidth`, overloading the existing
width() const.

Sure, here the argument is just an int, but for more complicated arguments,
the motivation of P2826R applies.

In general, zero overhead function renaming could even be one of the
stepping stones of some sort of out of class protocol/concepts
implementation.
We will need a way to point to the real implementation w/o wrapping - be it
in-class or not (which will be the case of the default implementation).

Handwavy scratch:

class interface Swappable {
  void swap(this Swappable&, Swappable&) = std::swap; //< default impl
};

class QVector {...};

QVector : Swappable { //< out of calss
   void swap(this Swappable&, Swappable&) = QVector::swap; //< specific impl
};




<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Няма
вирусиwww.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

Received on 2023-04-23 08:47:17