220 33274 <1e3def09-89c9-49af-a126-722e35c8e34f@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Nicol Bolas <jmckesson@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Adding operator overloading case to structure binding
Date: Fri, 21 Jul 2017 09:18:52 -0700 (PDT)
Lines: 163
Approved: news@gmane.org
Message-ID: <1e3def09-89c9-49af-a126-722e35c8e34f@isocpp.org>
References: <d992c1f5-72f1-4127-9b53-3a4d360a58d6@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1506_2114818788.1500653932333"
X-Trace: blaine.gmane.org 1500653934 9195 195.159.176.226 (21 Jul 2017 16:18:54 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Fri, 21 Jul 2017 16:18:54 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCEKFTV6ZUMBB3OSZDFQKGQETH54AAA@isocpp.org Fri Jul 21 18:18:49 2017
Return-path: <std-proposals+bncBCEKFTV6ZUMBB3OSZDFQKGQETH54AAA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pg0-f69.google.com ([74.125.83.69])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBB3OSZDFQKGQETH54AAA@isocpp.org>)
	id 1dYadc-00025m-Px
	for gclcip-std-proposals@m.gmane.org; Fri, 21 Jul 2017 18:18:49 +0200
Original-Received: by mail-pg0-f69.google.com with SMTP id u7sf28206638pgo.6
        for <gclcip-std-proposals@m.gmane.org>; Fri, 21 Jul 2017 09:18:54 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        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;
        bh=cHQEdQgKTvCLLJDzDA/Fcd5vJUOL+JvEC/OZ00vO2zM=;
        b=csHI42yT0ljgyQ7FfPzgC96WJyPMyPMEUew3xDnAGUW2Ic/aCA+8oEPXKGAG+yMVDK
         zJjGIwETkeCNOJrMRPeDqiBznZYN1/yhF8oGLtsn46OHY65uhttP/Jj5UNzBTg+KRb1m
         M++WioHRlGh198jc9Y1ViDB7WuwipsbnY6ZIt9tbWSU1OzLflua1RJ4DOSyyuh3q+8Ew
         46EEI4BeiVuNN2vumjsHKvGuBWkTJ+D3WG2jSHli0kSdvp/JZLI2Bgryo3XUZ64updWw
         ormz514ylo7RQzYVYFLpuDsVtcxkbh4fYB9YznOXHFtUNnkLnpngW5CCVK91yg1kcRb9
         ncLA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        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;
        bh=cHQEdQgKTvCLLJDzDA/Fcd5vJUOL+JvEC/OZ00vO2zM=;
        b=u2WSFPy+dkpuRHfvNVuLM560RvX6hxRzmDoj73mjLP77KjsyAdKd/kTozNBAFIim+c
         +/mKuymFUw36WPbQdirFSb6AfnrQNnGM0TWC5qOXAbL7Tg1Bw74gJQnxszVw4cQRbsZ9
         MDoFyl8j7+ubcO/Q2w1gY5JzFeH+ADUVBu3+ppORRQw5TwQcUuuBcE0cCnjuVgeuDZa/
         /XdsuHAOf2ph/G38kkPNP9Jly8jZ/L67Y3qm6CTyFfR6I3bnv1KBH0C6Z0s49B5T2g59
         NZYd7FivM2r8LZ3702PHPGFNvr7KfM8oWW8rl6gvDwI95y3vdSS3rI/YBs+AC7v9qFfk
         jZUg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=cHQEdQgKTvCLLJDzDA/Fcd5vJUOL+JvEC/OZ00vO2zM=;
        b=RB/YfBDM1qdT9RKaGxMWHrP650DnpGAokYq/1t4ZRxxoOQ6YdYSk893Z0s99i3vWnU
         LZRyglaz9oM5jinlxHSyjNMpUjIXXZTIonzw7lv+SVFY3Wuq6KIOCMXdzHK67cVMb3Xf
         ejewws/DXqxX7V7F7w/NTUQpx2GmTaG6DydM+E8xyLdQd6diGgysFpDqU2NR09lDry7J
         e2m6AovzlA6OtstnQzYMo2aNmP0Wm5ycntALmENfFnOo5p7qGLrUDmmD/EdzCHir/+7E
         wY0w2KRXsK2CDKKFQi9lMd8P69OMAywGZ98Hci5XZl+xtfh5ZDk419um55qK1bBjTw32
         FLbg==
X-Gm-Message-State: AIVw110fxUiaqCEFkvGPjhV2pLo6HnAkvVw3CqfKZvwAB2NXawJg4pab
	NiVp3VayD95EtwW9
X-Received: by 10.99.96.73 with SMTP id u70mr5409507pgb.220.1500653934215;
        Fri, 21 Jul 2017 09:18:54 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.143.88 with SMTP id r85ls8287437iod.5.gmail; Fri, 21 Jul
 2017 09:18:53 -0700 (PDT)
X-Received: by 10.31.164.205 with SMTP id n196mr30974vke.22.1500653932953;
        Fri, 21 Jul 2017 09:18:52 -0700 (PDT)
In-Reply-To: <d992c1f5-72f1-4127-9b53-3a4d360a58d6@isocpp.org>
X-Original-Sender: jmckesson@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: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://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>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:33274
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/33274>

------=_Part_1506_2114818788.1500653932333
Content-Type: multipart/alternative; 
	boundary="----=_Part_1507_585357188.1500653932334"

------=_Part_1507_585357188.1500653932334
Content-Type: text/plain; charset="UTF-8"



On Friday, July 21, 2017 at 9:42:48 AM UTC-4, Logan Song wrote:
>
> According to the C++ standard, structure binding has three cases right now:
>
>    1. binding an array
>    2. binding a tuple-like type
>    3. binding to public data members
>
> For example:
> #include <cstddef>
> #include <tuple>
>
> class tag_ptr {
> private:
>     void* holder;
>
> public:
>     explicit operator ::std::tuple<void*, ::std::byte>() {
>         return ::std::tuple(ptr(), tag());
>     }
>
>     void* ptr() {...}
>     ::std::byte tag() {...}
> };
>
> tag_ptr tp;
>
> auto ptr = tp.ptr();
> auto tag = tp.tag(); //Uhhhh
>
> //error: cannot decompose non-public member 'holder' of 'tag_ptr'
> //auto [ptr, tag] = tp; 
>
> Assume we have a class tag_ptr. It could store some bits compressed with a 
> pointer, which we couldn't expose it directly.
> As we can see, it's very cumbrous to init variables one by one.
>
> But if we relax the restrictions of rule2 to allow binding type which has 
> tuple-like type cast operator.
> The code will be more clear and it could make interfaces more graceful.
>

.... why? Why go through the intermediate `tuple`? If you have the ability 
to add `operator tuple` overloads, then you have the ability to add the 
`get/tuple_element/tuple_size` machinery to your type.

Alternatively, why not simply have a `decompose` member function that 
returns said `tuple`?

-- 
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/1e3def09-89c9-49af-a126-722e35c8e34f%40isocpp.org.

------=_Part_1507_585357188.1500653932334
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Friday, July 21, 2017 at 9:42:48 AM UTC-4, Loga=
n Song wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-le=
ft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">=
According to the C++ standard,=C2=A0structure binding has three cases right=
 now:<div><ol><li>binding an array</li><li>binding a tuple-like type</li><l=
i>binding to public data members</li></ol></div><div>For example:</div><div=
><div style=3D"background-color:rgb(250,250,250);border:1px solid rgb(187,1=
87,187);word-wrap:break-word"><code><div><span style=3D"color:#800">#includ=
e</span><span style=3D"color:#000"> </span><span style=3D"color:#080">&lt;c=
stddef&gt;</span><span style=3D"color:#000"><br></span><span style=3D"color=
:#800">#include</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#080">&lt;tuple&gt;</span><span style=3D"color:#000"><br><br></span><spa=
n style=3D"color:#008">class</span><span style=3D"color:#000"> tag_ptr </sp=
an><span style=3D"color:#660">{</span><span style=3D"color:#000"><br></span=
><span style=3D"color:#008">private</span><span style=3D"color:#660">:</spa=
n><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:=
#008">void</span><span style=3D"color:#660">*</span><span style=3D"color:#0=
00"> holder</span><span style=3D"color:#660">;</span><span style=3D"color:#=
000"><br><br></span><span style=3D"color:#008">public</span><span style=3D"=
color:#660">:</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><sp=
an style=3D"color:#008">explicit</span><span style=3D"color:#000"> </span><=
span style=3D"color:#008">operator</span><span style=3D"color:#000"> </span=
><span style=3D"color:#660">::</span><span style=3D"color:#000">std</span><=
span style=3D"color:#660">::</span><span style=3D"color:#000">tuple</span><=
span style=3D"color:#660">&lt;</span><span style=3D"color:#008">void</span>=
<span style=3D"color:#660">*</span><font color=3D"#000000"><span style=3D"c=
olor:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:=
#660">::</span><span style=3D"color:#000">std</span><span style=3D"color:#6=
60">::</span><span style=3D"color:#008">byte</span></font><span style=3D"co=
lor:#660">&gt;()</span><span style=3D"color:#000"> </span><span style=3D"co=
lor:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 </span><span style=3D"color:#008">return</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#660">::</span><span style=3D"color:#000">s=
td</span><span style=3D"color:#660">::</span><span style=3D"color:#000">tup=
le</span><span style=3D"color:#660">(</span><span style=3D"color:#000">ptr<=
/span><span style=3D"color:#660">(),</span><span style=3D"color:#000"> tag<=
/span><span style=3D"color:#660">());</span><span style=3D"color:#000"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><span style=3D"colo=
r:#000"><br><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">void</span>=
<span style=3D"color:#660">*</span><span style=3D"color:#000"> ptr</span><s=
pan style=3D"color:#660">()</span><span style=3D"color:#000"> </span><span =
style=3D"color:#660">{...}</span><span style=3D"color:#000"><br>=C2=A0 =C2=
=A0 </span><span style=3D"color:#660">::</span><span style=3D"color:#000">s=
td</span><span style=3D"color:#660">::</span><span style=3D"color:#008">byt=
e</span><span style=3D"color:#000"> tag</span><span style=3D"color:#660">()=
</span><span style=3D"color:#000"> </span><span style=3D"color:#660">{...}<=
/span><span style=3D"color:#000"><br></span><span style=3D"color:#660">};</=
span><span style=3D"color:#000"><br><br>tag_ptr tp</span><span style=3D"col=
or:#660">;</span><span style=3D"color:#000"><br><br></span><span style=3D"c=
olor:#008">auto</span><span style=3D"color:#000"> ptr </span><span style=3D=
"color:#660">=3D</span><span style=3D"color:#000"> tp</span><span style=3D"=
color:#660">.</span><span style=3D"color:#000">ptr</span><span style=3D"col=
or:#660">();</span><span style=3D"color:#000"><br></span><span style=3D"col=
or:#008">auto</span><span style=3D"color:#000"> tag </span><span style=3D"c=
olor:#660">=3D</span><span style=3D"color:#000"> tp</span><span style=3D"co=
lor:#660">.</span><span style=3D"color:#000">tag</span><span style=3D"color=
:#660">();</span><span style=3D"color:#000"> </span><span style=3D"color:#8=
00">//Uhhhh</span><span style=3D"color:#000"><br><br></span><span style=3D"=
color:#800">//</span><span style=3D"font-family:Menlo;font-size:11px"><span=
 style=3D"color:#800">error: cannot decompose non-public member &#39;holder=
&#39; of &#39;tag_ptr&#39;</span><span style=3D"color:#000"><br></span></sp=
an><span style=3D"color:#800">//auto [ptr, tag] =3D tp; </span><span style=
=3D"font-family:Menlo;font-size:11px"><span style=3D"color:#000"><br></span=
></span></div></code></div><br></div><div>Assume we have a class tag_ptr. I=
t could store=C2=A0some bits compressed with a pointer, which we couldn&#39=
;t expose it directly.</div><div>As we can see, it&#39;s very cumbrous to i=
nit variables one by one.</div><div><br></div><div>But if we relax the rest=
rictions of rule2 to allow binding type which has tuple-like type cast oper=
ator.</div><div>The code will be more clear and it could make interfaces mo=
re graceful.</div></div></blockquote><div><br>... why? Why go through the i=
ntermediate `tuple`? If you have the ability to add `operator tuple` overlo=
ads, then you have the ability to add the `get/tuple_element/tuple_size` ma=
chinery to your type.</div><br>Alternatively, why not simply have a `decomp=
ose` member function that returns said `tuple`?<br></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/1e3def09-89c9-49af-a126-722e35c8e34f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/1e3def09-89c9-49af-a126-722e35c8e34f=
%40isocpp.org</a>.<br />

------=_Part_1507_585357188.1500653932334--

------=_Part_1506_2114818788.1500653932333--

.
