220 6059 <e41ce277-f6f9-4dbe-92f7-dc8510efb6d3@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: David Krauss <potswa@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Templates usage with *this
Date: Sat, 31 Aug 2013 19:26:42 -0700 (PDT)
Lines: 172
Approved: news@gmane.org
Message-ID: <e41ce277-f6f9-4dbe-92f7-dc8510efb6d3@isocpp.org>
References: <e0049c1d-1b02-42bc-a871-2f5749572c41@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_1511_23485993.1378002403000"
X-Trace: ger.gmane.org 1378002407 32464 80.91.229.3 (1 Sep 2013 02:26:47 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sun, 1 Sep 2013 02:26:47 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCW25A7E3QCRBZGLRKIQKGQE32MEXJA@isocpp.org Sun Sep 01 04:26:49 2013
Return-path: <std-proposals+bncBCW25A7E3QCRBZGLRKIQKGQE32MEXJA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ie0-f197.google.com ([209.85.223.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCW25A7E3QCRBZGLRKIQKGQE32MEXJA@isocpp.org>)
	id 1VFxNG-0001on-Bb
	for gclcip-std-proposals@m.gmane.org; Sun, 01 Sep 2013 04:26:46 +0200
Original-Received: by mail-ie0-f197.google.com with SMTP id c11sf1299243ieb.4
        for <gclcip-std-proposals@m.gmane.org>; Sat, 31 Aug 2013 19:26:44 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=VxDen5u57U0zVnYAtRLyWWldY1eNJB9+dNy7Doz4/Qs=;
        b=gzCHAzJw0/4mi5JoPk/d+JByv+KMjOQp+eOARad+SynQViOR/SLltMMIqKvJLQ9u3a
         BfwCEatcDInR6Gbm5PJAabzGzeWOyHAspBr3SOzLQU9bTkG/Y7MGTjrQfUTefcxTGv8P
         3l82w1ssyb2+aB2+2Gf8UqmQHqmxfsU1pcHuPYS0g2tCM25XxPW7hJLWFCNIFG6oCqhO
         2Y2VPo/BMYLJfsGbgADysrMNEDxcIWh/3rsWQH7TMhslAfjktDMLXRRRcjpG5Yvs3f2F
         ZfK4V6uIOOr0mH39u8TuYIl1YzQVYNlbv+bWz3rm2J/d4GHCo9EXwKDPOiFzYtx7ZiTI
         fLDw==
X-Received: by 10.50.36.42 with SMTP id n10mr10284815igj.0.1378002404739;
        Sat, 31 Aug 2013 19:26:44 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.126.10 with SMTP id mu10ls902517igb.37.gmail; Sat, 31 Aug
 2013 19:26:44 -0700 (PDT)
X-Received: by 10.50.6.98 with SMTP id z2mr393056igz.0.1378002404181;
        Sat, 31 Aug 2013 19:26:44 -0700 (PDT)
In-Reply-To: <e0049c1d-1b02-42bc-a871-2f5749572c41@isocpp.org>
X-Original-Sender: potswa@gmail.com
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: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:6059
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/6059>

------=_Part_1511_23485993.1378002403000
Content-Type: text/plain; charset=ISO-8859-1

I must admit I didn't read your entire post.

You can't get the actual type of the argument which initialized *this; as 
noted only templates can represent simultaneous types and otherwise you 
have all the combinations of cv-qualification and value category.

What you can do is forgo a member function and use ADL and a non-member 
function template with perfect forwarding regulated by SFINAE. This gets 
you not only cv-qualification and value category but also the static type 
from the call site.

struct s {
    int x;

    template< typename self >
    friend
    typename std::enable_if< std::is_base_of< s, typename std::decay< self 
>::type >::value,
        std::decltype( std::declval< self >().x ) >::type
    get_x( self && o )
        { return std::forward< self >( o ).x; }
};

If I were you, though, I'd just elaborate the accessor functions as before 
and delegate from the rvalue overload to the lvalue overload with an 
explicit move. As you mentioned, const rvalue isn't actually used for 
anything, so the const overload need not be ref-qualified. So the new 
change doesn't effectively double the complexity, but in usual practice 
only one new case is added, which essentially just forwards to an existing 
case.

(Standard disclaimer: accessor functions are evil. C++ has a perfectly good 
model for accessing members; do not roll your own unless you legitimately 
have a custom object model. It looks like OP here might.)

-- 

--- 
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_1511_23485993.1378002403000
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I must admit I didn't read your entire post.<br><br>You ca=
n't get the actual type of the argument which initialized *this; as noted o=
nly templates can represent simultaneous types and otherwise you have all t=
he combinations of cv-qualification and value category.<br><br>What you can=
 do is forgo a member function and use ADL and a non-member function templa=
te with perfect forwarding regulated by SFINAE. This gets you not only cv-q=
ualification and value category but also the static type from the call site=
..<br><br><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250=
, 250); border-color: rgb(187, 187, 187); border-style: solid; border-width=
: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"su=
bprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">str=
uct</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> s </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> x</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">template</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"> </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">self</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">friend</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">typename</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">e=
nable_if</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&l=
t;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify">is_base_of</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> s</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">typename</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">decay</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">self</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&gt;::</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">type </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">&gt;::</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">value</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nbsp; std</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">decltype</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" c=
lass=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">declval</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">se=
lf</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;().</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">x </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">&gt;::</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">type<br>&nbsp; &nbsp; get_x</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">self</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">&amp;&amp;</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> o </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nb=
sp; &nbsp; &nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">ret=
urn</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">forward</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">self</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&gt;(</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> o </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">).</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">x</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">};</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br></span></div></code></div><br>If I were yo=
u, though, I'd just elaborate the accessor functions as before and delegate=
 from the rvalue overload to the lvalue overload with an explicit <span sty=
le=3D"font-family: courier new,monospace;">move</span>. As you mentioned, c=
onst rvalue isn't actually used for anything, so the <span style=3D"font-fa=
mily: courier new,monospace;">const</span> overload need not be ref-qualifi=
ed. So the new change doesn't effectively double the complexity, but in usu=
al practice only one new case is added, which essentially just forwards to =
an existing case.<br><br>(Standard disclaimer: accessor functions are evil.=
 C++ has a perfectly good model for accessing members; do not roll your own=
 unless you legitimately have a custom object model. It looks like OP here =
might.)<br></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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_1511_23485993.1378002403000--

.
