C++ Logo


Advanced search

Subject: Re: P2320: "The Syntax of Static Reflection" feedback request
From: Roland Bock (rbock_at_[hidden])
Date: 2021-02-21 02:58:23

On 19.02.21 15:34, David Rector wrote:
> Here is another class of non-trivial examples to consider:
> ```
> template<class T, class U>
> class Sum {
>   T t;
>   U u;
> public:
>   Sum(T &t, U u) : t(t), u(u) {}
>   // Methods: the union of the methods of T and U.
>   // Wherever they "share" a method, such that names and
>   // signatures of method reflections m_t and m_u are the same
>   // (not necc. via inheritance) that method is implemented
>   // to return t.[:m:](…) + u.[:m:](…).  Otherwise, it returns
>   // t.[:m:](…) or u.[:m:](…) individually.
>   // Conversion operators: construct from the relevant fields,
>   // but for any data T shares with U, need to add in the other’s
>   // data to the initializer.
>   explicit operator T();
>   explicit operator U();
> };

I understand the composition with forwarding functions. But what would
be a real-world use case for `t.[:m:](…) + u.[:m:](…)`?

Note that `operator+` might not be defined for the return type. Also,
the signatures might differ in just the return type.

SG7 list run by sg7-owner@lists.isocpp.org

Older Archives on Google Groups