C++ Logo

std-proposals

Advanced search

Re: Generic template 'this'

From: Gašper Ažman <gasper.azman_at_[hidden]>
Date: Sat, 7 Mar 2020 18:35:55 +0000
P0847

On Sat, Mar 7, 2020, 18:33 Phil Bouchard via Std-Proposals <
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
>
> [image: Fornux Logo] <http://www.fornux.com>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2020-03-07 12:38:56