220 15458 <683eba24-3371-4c96-960d-361e34b7e1e6@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: R.HL@gmx.net
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Adding a remove_cv_reference type trait
Date: Sun, 4 Jan 2015 15:15:37 -0800 (PST)
Lines: 176
Approved: news@gmane.org
Message-ID: <683eba24-3371-4c96-960d-361e34b7e1e6@isocpp.org>
References: <5880acc5-8236-40a0-bd5d-dfa6d9284572@isocpp.org>
 <CAB+4KH+0Zy1hfW6baW2kEWT+Lw7H53yd7UQGZMf0MpfC19WpCw@mail.gmail.com>
 <7c1ddf8b-051b-4fa8-9c00-8fe239890edc@isocpp.org>
 <CAB+4KHLh548QV4doYHiBP5C2F0GvZKqTc89Dh7gmMO6Qok3zhw@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_350_1423860656.1420413337827"
X-Trace: ger.gmane.org 1420413345 5801 80.91.229.3 (4 Jan 2015 23:15:45 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sun, 4 Jan 2015 23:15:45 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDRN5RPSR4MRBGUTU6SQKGQESHPHYEQ@isocpp.org Mon Jan 05 00:15:40 2015
Return-path: <std-proposals+bncBDRN5RPSR4MRBGUTU6SQKGQESHPHYEQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f198.google.com ([209.85.214.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDRN5RPSR4MRBGUTU6SQKGQESHPHYEQ@isocpp.org>)
	id 1Y7uOa-00036w-6G
	for gclcip-std-proposals@m.gmane.org; Mon, 05 Jan 2015 00:15:40 +0100
Original-Received: by mail-ob0-f198.google.com with SMTP id vb8sf508064164obc.1
        for <gclcip-std-proposals@m.gmane.org>; Sun, 04 Jan 2015 15:15:39 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:content-type:x-original-sender:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=50BSIrq9R88yzHPPuYrnz5X/jcC2rNkE/NJdLyHbo/w=;
        b=WMlhTo94uko45+DTvtnEEzbF8eHldgeM/IqHPxVuQuQQUXhmokBuTT23UAyWc7LNJD
         feNmKqQVJ04znB9zp3N6iL2crUeZD9ohMKiEOSKQM8VPaHCRqJceQ52qNrdZanzrWVCO
         UyahwN8K5OX90vIMqjnjNWCdnhZBdx+I7jyLd8OSGKyODZ1xwt7HAiRLTT98nbmn6rWZ
         gEp9oMHlnY0txMEetWsVdng9MsBzrPN2zVyZXIseJEAVicRlWJyZwaAbdi/uwua2CdNo
         O3Wbyd9QGMsK4WGTGA1I6Df2DqYTPPb+DE7CytIf8UhQimTOxomsvpnKEl3N4LckZOKi
         kISg==
X-Gm-Message-State: ALoCoQmWzHN8isLF4E/b6OvIupIpl/QjV2agFlfSdxEklZ/zC4plp3qE0R0Smn2JXdlpdMP3ylXL
X-Received: by 10.42.75.196 with SMTP id b4mr68218806ick.7.1420413338843;
        Sun, 04 Jan 2015 15:15:38 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.92.22 with SMTP id a22ls648256qge.83.gmail; Sun, 04 Jan
 2015 15:15:38 -0800 (PST)
X-Received: by 10.140.27.197 with SMTP id 63mr85763qgx.6.1420413338067;
        Sun, 04 Jan 2015 15:15:38 -0800 (PST)
In-Reply-To: <CAB+4KHLh548QV4doYHiBP5C2F0GvZKqTc89Dh7gmMO6Qok3zhw@mail.gmail.com>
X-Original-Sender: R.HL@gmx.net
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:15458
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/15458>

------=_Part_350_1423860656.1420413337827
Content-Type: multipart/alternative; 
	boundary="----=_Part_351_1415766871.1420413337827"

------=_Part_351_1415766871.1420413337827
Content-Type: text/plain; charset=UTF-8

Unfortunately I don't have many. Recently I came across an application of 
SFINAE in conjunction with reference parameters: If you want to restrict 
the type set you have to get the underlying type of the reference, 
excluding cv-qualifiers.

template <typename T>
std::enable_if_t<std::is_same<std::remove_cv_t<std::remove_reference_t<T>>, 
MyType>{}> foo(T&& t)
{/* Some operations */ bar(std::forward<T>(t));}
(Possibly with is_base_of instead of is_same)
Of course expression SFINAE could be applied but would have a different 
effect on overload resolution as it would take anything that the parameter 
is initialize-able with, whereas this overly choosy function template only 
takes MyTypes (or subclasses, if desired).

I then thought of simplifying the above by splitting up the enable_if-part:

template <typename T, typename U>
using enable_if_compatible = std::enable_if_t<std::is_same<std::remove_cv_t<
std::remove_reference_t<T>>, MyType>{}>

I wondered why there is no trait to get the underlying, cv-unqualified type 
of a reference. This is how I ended up proposing it in here. I don't know 
whether it is often used but it is a lot more idiomatic to write 
remove_cv_reference instead of remove_cv<remove_reference<>>, which also 
seems to confuse people 
<http://stackoverflow.com/questions/17295169/stdremove-reference-or-stdremove-cv-first>
..

-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_351_1415766871.1420413337827
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Unfortunately I don't have many. Recently I came across an=
 application of SFINAE in conjunction with reference parameters: If you wan=
t to restrict the type set you have to get the underlying type of the refer=
ence, excluding cv-qualifiers.<div><br></div><div><div class=3D"prettyprint=
" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; bac=
kground-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><font color=3D"#660066"><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">template</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">typename</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>st=
d</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">enable_if_t</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify">std</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">is_same</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify">std</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">remove_cv_t</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">std</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">remo=
ve_reference_t</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">T<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;&gt;,</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #606;" class=3D"styled-by-prettify">MyType</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">&gt;{}&gt;</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> foo</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">&amp;&amp;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> t</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">{</span><span style=3D"color: #800;" class=3D"styled-by-prettify">/* Som=
e operations */</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> bar</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">forward</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&gt;(</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">t</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">));}</span></font></div></code></div><span style=3D"color=
: rgb(0, 0, 0); background-color: rgb(250, 250, 250);">(Possibly with&nbsp;=
</span><font face=3D"courier new, monospace" style=3D"color: rgb(0, 0, 0); =
background-color: rgb(250, 250, 250);">is_base_of</font><span style=3D"colo=
r: rgb(0, 0, 0); background-color: rgb(250, 250, 250);">&nbsp;instead of&nb=
sp;</span><font face=3D"courier new, monospace" style=3D"color: rgb(0, 0, 0=
); background-color: rgb(250, 250, 250);">is_same</font><span style=3D"colo=
r: rgb(0, 0, 0); background-color: rgb(250, 250, 250);">)</span><br>Of cour=
se expression SFINAE could be applied but would have a different effect on =
overload resolution as it would take anything that the parameter is initial=
ize-able with, whereas this overly choosy function template only takes <fon=
t face=3D"courier new, monospace">MyTypes (or subclasses, if desired)</font=
>.</div><div><br></div><div>I then thought of simplifying the above by spli=
tting up the <font face=3D"courier new, monospace">enable_if</font>-part:</=
div><div><br></div><div><div class=3D"prettyprint" style=3D"border: 1px sol=
id rgb(187, 187, 187); word-wrap: break-word; background-color: rgb(250, 25=
0, 250);"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">template</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">typename</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> U</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">using</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> enable_if_compatible=
 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">enable_if_t</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">std</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">is_same</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">std</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">remove_cv_t</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">st=
d</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">remove_reference_=
t</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">T</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">&gt;&gt;,</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #606;" class=3D"styled-by-prettify">MyType</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">&gt;{}&gt;</span></div></code></div><s=
pan class=3D"styled-by-prettify" style=3D"background-color: rgb(250, 250, 2=
50);"><div><br></div><div><font color=3D"#000000">I wondered why there is n=
o trait to get the underlying, cv-unqualified type of a reference. This is =
how I ended up proposing it in here. I don't know whether it is often used =
but it is a lot more idiomatic to write <font face=3D"courier new, monospac=
e">remove_cv_reference</font> instead of <font face=3D"courier new, monospa=
ce">remove_cv&lt;remove_reference&lt;&gt;&gt;</font>, which also<a href=3D"=
http://stackoverflow.com/questions/17295169/stdremove-reference-or-stdremov=
e-cv-first"> seems to confuse people</a>.</font></div></span></div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_351_1415766871.1420413337827--
------=_Part_350_1423860656.1420413337827--

.
