Topic: Adding operator overloading case to structure binding


Author: Logan Song <ashenveilsong@gmail.com>
Date: Fri, 21 Jul 2017 06:42:48 -0700 (PDT)
Raw View
------=_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--

.


Author: =?UTF-8?Q?Micha=C5=82_Dominiak?= <griwes@griwes.info>
Date: Fri, 21 Jul 2017 14:04:06 +0000
Raw View
--94eb2c18828a3c56940554d457c5
Content-Type: text/plain; charset="UTF-8"

There is currently a customization point (or, a set of customization
points...) for this feature in the language: std::tuple_size,
std::tuple_element, and get(). They aren't pretty to use, but I'm not
convinced your proposed way to customize the behavior is really better.

On Fri, Jul 21, 2017 at 3:42 PM Logan Song <ashenveilsong@gmail.com> 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.
>
> 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
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/d992c1f5-72f1-4127-9b53-3a4d360a58d6%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>

--
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/CAPCFJdSxx8TBEC%2BbdPr%2BMnZPBYvZKrFK350zOnwE7U7Ug0BmmQ%40mail.gmail.com.

--94eb2c18828a3c56940554d457c5
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">There is currently a customization point (or, a set of cus=
tomization points...) for this feature in the language: std::tuple_size, st=
d::tuple_element, and get(). They aren&#39;t pretty to use, but I&#39;m not=
 convinced your proposed way to customize the behavior is really better.</d=
iv><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Fri, Jul 21, 2017 at =
3:42 PM Logan Song &lt;<a href=3D"mailto:ashenveilsong@gmail.com">ashenveil=
song@gmail.com</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" st=
yle=3D"margin:0 0 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><li>binding to public data members</li></ol></div><div>For exampl=
e:</div><div><div class=3D"m_-5921142759629577877prettyprint" style=3D"back=
ground-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wrap:b=
reak-word"><code class=3D"m_-5921142759629577877prettyprint"><div class=3D"=
m_-5921142759629577877subprettyprint"><span style=3D"color:#800" class=3D"m=
_-5921142759629577877styled-by-prettify">#include</span><span style=3D"colo=
r:#000" class=3D"m_-5921142759629577877styled-by-prettify"> </span><span st=
yle=3D"color:#080" class=3D"m_-5921142759629577877styled-by-prettify">&lt;c=
stddef&gt;</span><span style=3D"color:#000" class=3D"m_-5921142759629577877=
styled-by-prettify"><br></span><span style=3D"color:#800" class=3D"m_-59211=
42759629577877styled-by-prettify">#include</span><span style=3D"color:#000"=
 class=3D"m_-5921142759629577877styled-by-prettify"> </span><span style=3D"=
color:#080" class=3D"m_-5921142759629577877styled-by-prettify">&lt;tuple&gt=
;</span><span style=3D"color:#000" class=3D"m_-5921142759629577877styled-by=
-prettify"><br><br></span><span style=3D"color:#008" class=3D"m_-5921142759=
629577877styled-by-prettify">class</span><span style=3D"color:#000" class=
=3D"m_-5921142759629577877styled-by-prettify"> tag_ptr </span><span style=
=3D"color:#660" class=3D"m_-5921142759629577877styled-by-prettify">{</span>=
<span style=3D"color:#000" class=3D"m_-5921142759629577877styled-by-prettif=
y"><br></span><span style=3D"color:#008" class=3D"m_-5921142759629577877sty=
led-by-prettify">private</span><span style=3D"color:#660" class=3D"m_-59211=
42759629577877styled-by-prettify">:</span><span style=3D"color:#000" class=
=3D"m_-5921142759629577877styled-by-prettify"><br>=C2=A0 =C2=A0 </span><spa=
n style=3D"color:#008" class=3D"m_-5921142759629577877styled-by-prettify">v=
oid</span><span style=3D"color:#660" class=3D"m_-5921142759629577877styled-=
by-prettify">*</span><span style=3D"color:#000" class=3D"m_-592114275962957=
7877styled-by-prettify"> holder</span><span style=3D"color:#660" class=3D"m=
_-5921142759629577877styled-by-prettify">;</span><span style=3D"color:#000"=
 class=3D"m_-5921142759629577877styled-by-prettify"><br><br></span><span st=
yle=3D"color:#008" class=3D"m_-5921142759629577877styled-by-prettify">publi=
c</span><span style=3D"color:#660" class=3D"m_-5921142759629577877styled-by=
-prettify">:</span><span style=3D"color:#000" class=3D"m_-59211427596295778=
77styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008" c=
lass=3D"m_-5921142759629577877styled-by-prettify">explicit</span><span styl=
e=3D"color:#000" class=3D"m_-5921142759629577877styled-by-prettify"> </span=
><span style=3D"color:#008" class=3D"m_-5921142759629577877styled-by-pretti=
fy">operator</span><span style=3D"color:#000" class=3D"m_-59211427596295778=
77styled-by-prettify"> </span><span style=3D"color:#660" class=3D"m_-592114=
2759629577877styled-by-prettify">::</span><span style=3D"color:#000" class=
=3D"m_-5921142759629577877styled-by-prettify">std</span><span style=3D"colo=
r:#660" class=3D"m_-5921142759629577877styled-by-prettify">::</span><span s=
tyle=3D"color:#000" class=3D"m_-5921142759629577877styled-by-prettify">tupl=
e</span><span style=3D"color:#660" class=3D"m_-5921142759629577877styled-by=
-prettify">&lt;</span><span style=3D"color:#008" class=3D"m_-59211427596295=
77877styled-by-prettify">void</span><span style=3D"color:#660" class=3D"m_-=
5921142759629577877styled-by-prettify">*</span><font color=3D"#000000"><spa=
n style=3D"color:#660" class=3D"m_-5921142759629577877styled-by-prettify">,=
</span><span style=3D"color:#000" class=3D"m_-5921142759629577877styled-by-=
prettify"> </span><span style=3D"color:#660" class=3D"m_-592114275962957787=
7styled-by-prettify">::</span><span style=3D"color:#000" class=3D"m_-592114=
2759629577877styled-by-prettify">std</span><span style=3D"color:#660" class=
=3D"m_-5921142759629577877styled-by-prettify">::</span><span style=3D"color=
:#008" class=3D"m_-5921142759629577877styled-by-prettify">byte</span></font=
><span style=3D"color:#660" class=3D"m_-5921142759629577877styled-by-pretti=
fy">&gt;()</span><span style=3D"color:#000" class=3D"m_-5921142759629577877=
styled-by-prettify"> </span><span style=3D"color:#660" class=3D"m_-59211427=
59629577877styled-by-prettify">{</span><span style=3D"color:#000" class=3D"=
m_-5921142759629577877styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 <=
/span><span style=3D"color:#008" class=3D"m_-5921142759629577877styled-by-p=
rettify">return</span><span style=3D"color:#000" class=3D"m_-59211427596295=
77877styled-by-prettify"> </span><span style=3D"color:#660" class=3D"m_-592=
1142759629577877styled-by-prettify">::</span><span style=3D"color:#000" cla=
ss=3D"m_-5921142759629577877styled-by-prettify">std</span><span style=3D"co=
lor:#660" class=3D"m_-5921142759629577877styled-by-prettify">::</span><span=
 style=3D"color:#000" class=3D"m_-5921142759629577877styled-by-prettify">tu=
ple</span><span style=3D"color:#660" class=3D"m_-5921142759629577877styled-=
by-prettify">(</span><span style=3D"color:#000" class=3D"m_-592114275962957=
7877styled-by-prettify">ptr</span><span style=3D"color:#660" class=3D"m_-59=
21142759629577877styled-by-prettify">(),</span><span style=3D"color:#000" c=
lass=3D"m_-5921142759629577877styled-by-prettify"> tag</span><span style=3D=
"color:#660" class=3D"m_-5921142759629577877styled-by-prettify">());</span>=
<span style=3D"color:#000" class=3D"m_-5921142759629577877styled-by-prettif=
y"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660" class=3D"m_-59211427=
59629577877styled-by-prettify">}</span><span style=3D"color:#000" class=3D"=
m_-5921142759629577877styled-by-prettify"><br><br>=C2=A0 =C2=A0 </span><spa=
n style=3D"color:#008" class=3D"m_-5921142759629577877styled-by-prettify">v=
oid</span><span style=3D"color:#660" class=3D"m_-5921142759629577877styled-=
by-prettify">*</span><span style=3D"color:#000" class=3D"m_-592114275962957=
7877styled-by-prettify"> ptr</span><span style=3D"color:#660" class=3D"m_-5=
921142759629577877styled-by-prettify">()</span><span style=3D"color:#000" c=
lass=3D"m_-5921142759629577877styled-by-prettify"> </span><span style=3D"co=
lor:#660" class=3D"m_-5921142759629577877styled-by-prettify">{...}</span><s=
pan style=3D"color:#000" class=3D"m_-5921142759629577877styled-by-prettify"=
><br>=C2=A0 =C2=A0 </span><span style=3D"color:#660" class=3D"m_-5921142759=
629577877styled-by-prettify">::</span><span style=3D"color:#000" class=3D"m=
_-5921142759629577877styled-by-prettify">std</span><span style=3D"color:#66=
0" class=3D"m_-5921142759629577877styled-by-prettify">::</span><span style=
=3D"color:#008" class=3D"m_-5921142759629577877styled-by-prettify">byte</sp=
an><span style=3D"color:#000" class=3D"m_-5921142759629577877styled-by-pret=
tify"> tag</span><span style=3D"color:#660" class=3D"m_-5921142759629577877=
styled-by-prettify">()</span><span style=3D"color:#000" class=3D"m_-5921142=
759629577877styled-by-prettify"> </span><span style=3D"color:#660" class=3D=
"m_-5921142759629577877styled-by-prettify">{...}</span><span style=3D"color=
:#000" class=3D"m_-5921142759629577877styled-by-prettify"><br></span><span =
style=3D"color:#660" class=3D"m_-5921142759629577877styled-by-prettify">};<=
/span><span style=3D"color:#000" class=3D"m_-5921142759629577877styled-by-p=
rettify"><br><br>tag_ptr tp</span><span style=3D"color:#660" class=3D"m_-59=
21142759629577877styled-by-prettify">;</span><span style=3D"color:#000" cla=
ss=3D"m_-5921142759629577877styled-by-prettify"><br><br></span><span style=
=3D"color:#008" class=3D"m_-5921142759629577877styled-by-prettify">auto</sp=
an><span style=3D"color:#000" class=3D"m_-5921142759629577877styled-by-pret=
tify"> ptr </span><span style=3D"color:#660" class=3D"m_-592114275962957787=
7styled-by-prettify">=3D</span><span style=3D"color:#000" class=3D"m_-59211=
42759629577877styled-by-prettify"> tp</span><span style=3D"color:#660" clas=
s=3D"m_-5921142759629577877styled-by-prettify">.</span><span style=3D"color=
:#000" class=3D"m_-5921142759629577877styled-by-prettify">ptr</span><span s=
tyle=3D"color:#660" class=3D"m_-5921142759629577877styled-by-prettify">();<=
/span><span style=3D"color:#000" class=3D"m_-5921142759629577877styled-by-p=
rettify"><br></span><span style=3D"color:#008" class=3D"m_-5921142759629577=
877styled-by-prettify">auto</span><span style=3D"color:#000" class=3D"m_-59=
21142759629577877styled-by-prettify"> tag </span><span style=3D"color:#660"=
 class=3D"m_-5921142759629577877styled-by-prettify">=3D</span><span style=
=3D"color:#000" class=3D"m_-5921142759629577877styled-by-prettify"> tp</spa=
n><span style=3D"color:#660" class=3D"m_-5921142759629577877styled-by-prett=
ify">.</span><span style=3D"color:#000" class=3D"m_-5921142759629577877styl=
ed-by-prettify">tag</span><span style=3D"color:#660" class=3D"m_-5921142759=
629577877styled-by-prettify">();</span><span style=3D"color:#000" class=3D"=
m_-5921142759629577877styled-by-prettify"> </span><span style=3D"color:#800=
" class=3D"m_-5921142759629577877styled-by-prettify">//Uhhhh</span><span st=
yle=3D"color:#000" class=3D"m_-5921142759629577877styled-by-prettify"><br><=
br></span><span style=3D"color:#800" class=3D"m_-5921142759629577877styled-=
by-prettify">//</span><span style=3D"font-family:Menlo;font-size:11px"><spa=
n style=3D"color:#800" class=3D"m_-5921142759629577877styled-by-prettify">e=
rror: cannot decompose non-public member &#39;holder&#39; of &#39;tag_ptr&#=
39;</span><span style=3D"color:#000" class=3D"m_-5921142759629577877styled-=
by-prettify"><br></span></span><span style=3D"color:#800" class=3D"m_-59211=
42759629577877styled-by-prettify">//auto [ptr, tag] =3D tp; </span><span st=
yle=3D"font-family:Menlo;font-size:11px"><span style=3D"color:#000" class=
=3D"m_-5921142759629577877styled-by-prettify"><br></span></span></div></cod=
e></div><br></div><div>Assume we have a class tag_ptr. It could store=C2=A0=
some bits compressed with a pointer, which we couldn&#39;t expose it direct=
ly.</div><div>As we can see, it&#39;s very cumbrous to init variables one b=
y one.</div><div><br></div><div>But if we relax the restrictions of rule2 t=
o 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.</div><=
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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">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&amp;utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/d992c1f5-72f1-=
4127-9b53-3a4d360a58d6%40isocpp.org</a>.<br>
</blockquote></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/CAPCFJdSxx8TBEC%2BbdPr%2BMnZPBYvZKrFK=
350zOnwE7U7Ug0BmmQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAPCFJdSxx8TB=
EC%2BbdPr%2BMnZPBYvZKrFK350zOnwE7U7Ug0BmmQ%40mail.gmail.com</a>.<br />

--94eb2c18828a3c56940554d457c5--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Fri, 21 Jul 2017 17:15:24 +0300
Raw View
On 21 July 2017 at 17:04, Micha=C5=82 Dominiak <griwes@griwes.info> wrote:
> There is currently a customization point (or, a set of customization
> points...) for this feature in the language: std::tuple_size,
> std::tuple_element, and get(). They aren't pretty to use, but I'm not
> convinced your proposed way to customize the behavior is really better.

Right, however, in general, types convertible to types that can be
structured-bound aren't supported by structured
bindings. If you have
struct X : tuple<int, int> {};
you can't do structured bindings on it.

On the other hand, allowing conversions gets tricky; what if I have
data members in X? Then it 'obviously' shouldn't
do structured bindings via a conversion to tuple, so what we would get
via the conversions is not necessarily better.
It would certainly make the rules more complex.

>
> On Fri, Jul 21, 2017 at 3:42 PM Logan Song <ashenveilsong@gmail.com> wrot=
e:
>>
>> According to the C++ standard, structure binding has three cases right
>> now:
>>
>> binding an array
>> binding a tuple-like type
>> 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 =3D tp.ptr();
>> auto tag =3D tp.tag(); //Uhhhh
>>
>> //error: cannot decompose non-public member 'holder' of 'tag_ptr'
>> //auto [ptr, tag] =3D 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 ha=
s
>> 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 Group=
s
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n
>> 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-72=
f1-4127-9b53-3a4d360a58d6%40isocpp.org.
>
> --
> 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/CAPCFJdSxx8T=
BEC%2BbdPr%2BMnZPBYvZKrFK350zOnwE7U7Ug0BmmQ%40mail.gmail.com.

--=20
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 e=
mail 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/CAFk2RUa%2B-_mw2QNh_pYR-QakwEh60OgoeCMaGsWW1yans=
RrV%2Bw%40mail.gmail.com.

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Fri, 21 Jul 2017 09:18:52 -0700 (PDT)
Raw View
------=_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--

.