220 33270 <d992c1f5-72f1-4127-9b53-3a4d360a58d6@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Logan Song <ashenveilsong@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Adding operator overloading case to structure binding
Date: Fri, 21 Jul 2017 06:42:48 -0700 (PDT)
Lines: 190
Approved: news@gmane.org
Message-ID: <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_1374_301074473.1500644568323"
X-Trace: blaine.gmane.org 1500644578 31069 195.159.176.226 (21 Jul 2017 13:42:58 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Fri, 21 Jul 2017 13:42:58 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCB7BYVF2AARBWUJZDFQKGQEZVYRWCA@isocpp.org Fri Jul 21 15:42:53 2017
Return-path: <std-proposals+bncBCB7BYVF2AARBWUJZDFQKGQEZVYRWCA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yw0-f199.google.com ([209.85.161.199])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCB7BYVF2AARBWUJZDFQKGQEZVYRWCA@isocpp.org>)
	id 1dYYCc-0007Rc-9N
	for gclcip-std-proposals@m.gmane.org; Fri, 21 Jul 2017 15:42:46 +0200
Original-Received: by mail-yw0-f199.google.com with SMTP id a4sf47704327ywm.12
        for <gclcip-std-proposals@m.gmane.org>; Fri, 21 Jul 2017 06:42:51 -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:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=qmCGir6RE/6omc72rs7+1LoSOOSzP97BhaFso9br73Y=;
        b=USdHQh0aEY29RZ73+REOPZyNZashJQZ3MT40JCC0OqvEvkcqhTchBeKW+DPWDgMZ4S
         GhPxGnX6ZMAW8Ys5ylXrjWq5tcctLQlI4M4RTZE8pMRJy2zL6GAsLzU0mEm0AMXanmYy
         edg0oJyRbpk1ShPkQE5f224n8HZbzcZQYNfPmL2oLYpXbwvZawHS5Ylw0m7z0ov0KtiS
         HVBvcXNopAT6AH5t+NeGXtNEr6pQILxyAqYLc+r+Beh+aYQs6VV2srDqZspBkDmIKM7o
         abFSUR+Sf4dIYj+/Bz8Qs+gTnR+by5kKriSnHhJ40emTejoUFDNffhpDxt8nX4TNkEB4
         fe7A==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:message-id:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=qmCGir6RE/6omc72rs7+1LoSOOSzP97BhaFso9br73Y=;
        b=vIcuIgygX0xT4avKY7Tvzv6gXGUe/M0mpEAZGhPdL1r19BGDeQHSIIDUnEXtGwCl+q
         UCmWYDddPTWPQUTav2qzOxlpNwLPRDUKBeZfsfnZKLUeQRqmYF0ppnTr8IcVmUA3XaXg
         SjG2ga8V1uuz1Zm7XqXwRQLsU8Uc87hsgUXOtOpUmaPEI9yGY5SZ191FnVfeqHnSsowc
         DiKz22oH+rrqkqjPjDxGCqoXzFU9UkMPTnk9FkThQE+AixE4gpzBihiEtn3ORQl7U7+B
         rvljsA28J/O/Q8PaP5mt5/LW/42gJ7hewoDPxI6tiQEperrMsXtw2aaQYkaWfSjsNAbZ
         GWOA==
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: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=qmCGir6RE/6omc72rs7+1LoSOOSzP97BhaFso9br73Y=;
        b=YUSE2Q2MQrfaTVaj9EMl9Us0uyi3tyoqK0MoZxAxCQ7fDXOBtgnZtHXzS2sGoYNuZk
         8x9R82sJfvjCRLiv77iHWVPEyrClCszXjN90h49kX8tIxNNAJ0bsA1SWLfSUxkgm4SHb
         oEDcFz6gHAazGB33spH9iDmeZl6DjvLHOjn3C/MZj86MmKZl4kgOuQYe6z5UHd06hgCw
         hvdWo1x+DJMCy4OOwN/hq7Au302yavDdUZs3M88tVvSKjcS3co3zXfTnL+cSsq5l19De
         oeZ5A+LYD8VUvw6RRWtZzw5CzEE/yUrAIFvu+t9gcZrKz01wVJOxe5E6dk/JsOw+1E4m
         6NHA==
X-Gm-Message-State: AIVw112OpX5QTTEThIyW4Ij+yaYNUI15REj8ka+kPDCT82QAidhIe1Za
	2BfbDMexsuxnwyg6
X-Received: by 10.129.177.68 with SMTP id p65mr4906296ywh.205.1500644571245;
        Fri, 21 Jul 2017 06:42:51 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.36.1.83 with SMTP id 80ls2901637itk.0.gmail; Fri, 21 Jul 2017
 06:42:49 -0700 (PDT)
X-Received: by 10.31.50.145 with SMTP id y139mr29693vky.17.1500644568790;
        Fri, 21 Jul 2017 06:42:48 -0700 (PDT)
X-Original-Sender: ashenveilsong@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:33270
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/33270>

------=_Part_1374_301074473.1500644568323
Content-Type: multipart/alternative; 
	boundary="----=_Part_1375_1433992213.1500644568324"

------=_Part_1375_1433992213.1500644568324
Content-Type: text/plain; charset="UTF-8"

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.

That's my proposal. :)

-- 
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/d992c1f5-72f1-4127-9b53-3a4d360a58d6%40isocpp.org.

------=_Part_1375_1433992213.1500644568324
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<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><li>binding to public data members</li></ol></div><div>For e=
xample:</div><div><div class=3D"prettyprint" style=3D"background-color: rgb=
(250, 250, 250); border: 1px solid rgb(187, 187, 187); word-wrap: break-wor=
d;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=
=3D"color: #800;" class=3D"styled-by-prettify">#include</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #080;" class=3D"styled-by-prettify">&lt;cstddef&gt;</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color:=
 #800;" class=3D"styled-by-prettify">#include</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #080;" cla=
ss=3D"styled-by-prettify">&lt;tuple&gt;</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> tag_ptr </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">private</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">void</span><span style=3D"color: #660;" class=3D"styled-by-prettify">*=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> holder</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">public</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">explicit</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">operator</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">std</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">tuple</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
lt;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">void</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><font=
 color=3D"#000000"><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">::</span><span s=
tyle=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: =
#008;" class=3D"styled-by-prettify">byte</span></font><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">&gt;()</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:=
 #008;" class=3D"styled-by-prettify">return</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">std</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>tuple</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">ptr</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">(),</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> tag</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">());</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br><br>=C2=A0 =C2=A0 </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">void</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">*</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> ptr</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">{...}</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::<=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">byte</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> tag</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">{...}</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"styl=
ed-by-prettify"><br><br>tag_ptr tp</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled-=
by-prettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> ptr </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> tp</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">ptr</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">();</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> tag </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> tp</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>tag</span><span style=3D"color: #660;" class=3D"styled-by-prettify">();</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #800;" class=3D"styled-by-prettify">//Uhhhh</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span styl=
e=3D"color: #800;" class=3D"styled-by-prettify">//</span><span style=3D"fon=
t-family: Menlo; font-size: 11px; text-indent: -12px;"><span style=3D"color=
: #800;" class=3D"styled-by-prettify">error: cannot decompose non-public me=
mber &#39;holder&#39; of &#39;tag_ptr&#39;</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span></span><span style=3D"color: #80=
0;" class=3D"styled-by-prettify">//auto [ptr, tag] =3D tp; </span><span sty=
le=3D"font-family: Menlo; font-size: 11px; text-indent: -12px;"><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span></span></div></co=
de></div><br></div><div>Assume we have a class tag_ptr. It could store=C2=
=A0some bits compressed with a pointer, which we couldn&#39;t expose it dir=
ectly.</div><div>As we can see, it&#39;s very cumbrous to init variables on=
e by one.</div><div><br></div><div>But if we relax the restrictions of rule=
2 to allow binding type which has tuple-like type cast operator.</div><div>=
The code will be more clear and it could make interfaces more graceful.</di=
v><div><br></div><div>That&#39;s my proposal. :)</div><div><br></div></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/d992c1f5-72f1-4127-9b53-3a4d360a58d6%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/d992c1f5-72f1-4127-9b53-3a4d360a58d6=
%40isocpp.org</a>.<br />

------=_Part_1375_1433992213.1500644568324--

------=_Part_1374_301074473.1500644568323--

.
