C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] Generic template 'this'
From: Phil Bouchard (phil_at_[hidden])
Date: 2020-03-07 13:04:53


The syntaxes are way different:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p0847r4.html

In your case the compiler will have to change all of its rules for the
number of parameters "operator" overloads. For example:

struct A

{

 Â Â Â  int value;

 Â Â Â  ...

 Â Â Â  template <typename Self>

 Â Â Â      bool operator < (this Self && self, A const & a) // 2
parameters... ok

 Â Â Â      {

 Â Â Â          return self.value < a.value;

 Â Â Â      }

 Â Â Â      bool operator < (A const & a) // 1 parameter... ok

 Â Â Â      {

 Â Â Â          return value < a.value;

 Â Â Â      }

};

-- 
*Phil Bouchard*
Founder
C.: (819) 328-4743
Fornux Logo <http://www.fornux.com>
On 3/7/20 1:35 PM, Gašper Ažman wrote:
> P0847
>
> On Sat, Mar 7, 2020, 18:33 Phil Bouchard via Std-Proposals 
> <std-proposals_at_[hidden] 
> <mailto:std-proposals_at_[hidden]>> wrote:
>
>     Alright, I'm pretty sure this is not implemented yet. Suppose you
>     have:
>
>     struct A
>
>     {
>
>         int value;
>
>         ...
>
>         template <typename T>
>
>             int compare(T const & t) const;
>
>     }
>
>
>     struct B
>
>     {
>
>         int value;
>
>         ...
>
>         template <typename T>
>
>             int compare(T const & t) const;
>
>     }
>
>
>     Then a generic way to define the same functionality for all
>     classes would be to have a "template 'this'":
>
>     template <typename C, typename T>
>
>             inline int C::compare(T const & t) const
>
>             {
>
>                 return value == t.value ? 0 : value < t.value ? -1 : 1;
>
>             }
>
>
>     (Please include my email address in your replies)
>
>
>     -- 
>
>     *Phil Bouchard*
>     Founder
>     C.: (819) 328-4743
>
>     Fornux Logo <http://www.fornux.com>
>     -- 
>     Std-Proposals mailing list
>     Std-Proposals_at_[hidden] <mailto:Std-Proposals_at_[hidden]>
>     https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>


STD-PROPOSALS list run by herb.sutter at gmail.com

Standard Proposals Archives on Google Groups