C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] Template qualifiers
From: Phil Bouchard (phil_at_[hidden])
Date: 2019-09-29 15:50:59


[Please CC my personal email address in the replies otherwise I'll can't
properly follow-up]

So let's take a better example:

template <typename T>

 Â Â Â  struct construct<T>

 Â Â Â  {

 Â Â Â      // Let the compiler generate the most efficient code

 Â Â Â      template <qualifier Q>

 Â Â Â          inline T Q operator () (node_proxy & __y, T Q po)

 Â Â Â          {

 Â Â Â              return T(po);

 Â Â Â          }

 Â Â Â  };

struct ConstClass

{

 Â Â Â  constexpr ConstClass() {}

};

struct NonConstClass

{

 Â Â Â  NonConstClass() {}

};

// This will result in:

construct<ConstClass>()(ConstClass()); // constexpr expression

construct<NonConstClass>()(NonConstClass()); // not a constexpr expression

Thus qualifiers would be:

<nothing> (copy)

const

volatile

const volatile

const &

volatile &

const volatile &

<nothing> (copy) constexpr

const constexpr

volatile constexpr

const volatile constexpr

const constexpr &

volatile constexpr &

const volatile constexpr &

&&

Why the need? Because otherwise we can't have unique and syntactic sugar
functions to handle all possibilities efficiently.

-- 
*Phil Bouchard*
Founder
C.: (819) 328-4743
Fornux Logo <http://www.fornux.com>
On 9/29/19 2:48 PM, Tony V E wrote:
> Is there some reason to use assignment as your example? It seems a 
> strange example, since we don't normally assign to const objects, nor 
> build assignments that don't assign.
>
> Maybe a more motivating and less distracting example would be better.
>
> Sent from my BlackBerry portable Babbage Device
> *From: *Phil Bouchard via Std-Proposals
> *Sent: *Sunday, September 29, 2019 8:52 AM
> *To: *std-proposals_at_[hidden]
> *Reply To: *std-proposals_at_[hidden]
> *Cc: *Phil Bouchard
> *Subject: *[std-proposals] Template qualifiers
>
>
> Greetings,
>
>
> How many time did we have to redundantly write the same member 
> functions just to add a const version? Ex.:
>
> struct A
>
> {
>
>     A & operator = (A const &) { return * this; }
>
>     A const & operator = (A const &) const { return * this; }
>
> };
>
>
> What I would like to suggest would be to templatize those instances as 
> such:
>
> struct A
>
> {
>
>     template <qualifier Q>
>
>         A Q & operator = (A const &) Q { return * this; }
>
> };
>
>
> This would in instantiate on-the-fly the 2 (or 4) versions of the same 
> code.
>
>
> Thank you,
>
> -- 
>
> *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