C++ Logo

STD-PROPOSALS

Advanced search

Subject: [std-proposals] Generic template 'this'
From: Phil Bouchard (phil_at_[hidden])
Date: 2020-03-07 12:33:45


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 list run by herb.sutter at gmail.com

Standard Proposals Archives on Google Groups