C++ Logo


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
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


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