Topic: Simple tuples thanks to structured binding
Author: m.cencora@gmail.com
Date: Mon, 15 Feb 2016 08:19:03 -0800 (PST)
Raw View
------=_Part_188_324494382.1455553143549
Content-Type: multipart/alternative;
boundary="----=_Part_189_1823778077.1455553143550"
------=_Part_189_1823778077.1455553143550
Content-Type: text/plain; charset=UTF-8
Hi,
I think the structured binding proposal opens a possibility for major
simplification of std::tuple implementation.
Let's take following "implementation" as an example:
template <typename ...T>
struct __tuple_struct;
template <typename T1>
struct __tuple_struct<T1>
{
T1 _1;
template <typename ...Args, typename = decltype(__tuple_struct<Args...>{
_1 })>
operator __tuple_struct<Args...>()
{
return __tuple_struct<Args...>{ _1 };
}
void swap(__tuple_struct& other);
};
template <typename T1, typename T2>
struct __tuple_struct<T1, T2>
{
T1 _1;
T2 _2;
template <typename ...Args, typename = decltype(__tuple_struct<Args...>{
_1, _2 })>
operator __tuple_struct<Args...>()
{
return __tuple_struct<Args...>{ _1, _2 };
}
void swap(__tuple_struct& other);
};
template <typename ...Ts>
using tuple = __tuple_struct<Ts...>;
The tuple struct is almost implementable with variadic templates in C++14 -
except for the data members.
If that's not clear yet, following implementation is almost dead simple and
you get most of current std::tuple functionality for free - perfect
initialization, copy/move assignement, copy/move construction, get<N>.
There is only one thing that I don't know how to support - the "old" direct
initialization syntax with parentheses instead of curly braces i.e.
tuple<Ts...>( args...).
I hope that supporting it does not require the full-fledged implementation
as we have now (with constructors complexity/problems).
I am not an C++ expert, so I am most probably missing something here that
makes it infeasible.
Anyway, what do you think?
BTW, is there already a proposal for default (builtin) conversion operator
for compatible structs? In a similar fashion to default comparison
operators, it would be provided only if there is no user-provided one
already.
Something along the lines:
template <typename __other_struct, typename = decltype(__other_struct{ get<
Ints...>(), ... })>
operator __other_struct<Args...>()
{
return __other_struct<Args...>{ get<Ints...>()...};
}
Regards,
Maciej Cencora
--
---
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 https://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_189_1823778077.1455553143550
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hi,<div><br></div><div>I think the structured binding prop=
osal opens a possibility for major simplification of std::tuple implementat=
ion.</div><div><br></div><div>Let's take following "implementation=
" as an example:</div><div><div class=3D"prettyprint" style=3D"border:=
1px solid rgb(187, 187, 187); word-wrap: break-word; background-color: rgb=
(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"subprettyprint"=
><div style=3D"font-family: Arial, Helvetica, sans-serif; background-color:=
rgb(255, 255, 255);"><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">template</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">typename</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">T</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">></span></div><div style=3D"font-f=
amily: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"=
><span style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> __tuple_struct</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span></div><=
div style=3D"font-family: Arial, Helvetica, sans-serif; background-color: r=
gb(255, 255, 255);"><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br></span></div><div style=3D"font-family: Arial, Helvetica, sans-serif=
; background-color: rgb(255, 255, 255);"><span style=3D"color: #008;" class=
=3D"styled-by-prettify">template</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify"><</span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">typename</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> T1</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
></span></div><div style=3D"font-family: Arial, Helvetica, sans-serif; b=
ackground-color: rgb(255, 255, 255);"><span style=3D"color: #008;" class=3D=
"styled-by-prettify">struct</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> __tuple_struct</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">T1</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">></span></div><div style=3D"font-family: Arial, Helvetica, san=
s-serif; background-color: rgb(255, 255, 255);"><span style=3D"color: #660;=
" class=3D"styled-by-prettify">{</span></div><div style=3D"font-family: Ari=
al, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> =C2=A0 =C2=A0T1 _1</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">;</span></div><di=
v style=3D"font-family: Arial, Helvetica, sans-serif; background-color: rgb=
(255, 255, 255);"><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br></span></div><div style=3D"font-family: Arial, Helvetica, sans-serif; =
background-color: rgb(255, 255, 255);"><span style=3D"color: #000;" class=
=3D"styled-by-prettify">=C2=A0 =C2=A0 </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">template</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify"><</span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">typename</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
....</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Args</s=
pan><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: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">decltype</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">__tuple_struct</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify"><</span><span style=3D"color: #606;" class=3D"styled-by-pretti=
fy">Args</span><span style=3D"color: #660;" class=3D"styled-by-prettify">..=
..>{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> _1 =
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">})></sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></d=
iv><div style=3D"font-family: Arial, Helvetica, sans-serif; background-colo=
r: rgb(255, 255, 255);"><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">operator</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> __tuple_struct</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify"><</span><span style=3D"color: #606;" class=3D"styled-by-pr=
ettify">Args</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">...>()</span></div><div style=3D"font-family: Arial, Helvetica, sans-s=
erif; background-color: rgb(255, 255, 255);"><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> =C2=A0 =C2=A0</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">{</span></div><div style=3D"font-family: Ar=
ial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> =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: #000;" class=3D"styled-by-prettify"> __tuple_st=
ruct</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</=
span><span style=3D"color: #606;" class=3D"styled-by-prettify">Args</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">...>{</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> _1 </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">};</span></div><div style=
=3D"font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 2=
55, 255);"><span style=3D"color: #000;" class=3D"styled-by-prettify"> =C2=
=A0 =C2=A0</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
}</span></div><div style=3D"font-family: Arial, Helvetica, sans-serif; back=
ground-color: rgb(255, 255, 255);"><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br></span></div><div style=3D"font-family: Arial, Helvet=
ica, sans-serif; background-color: rgb(255, 255, 255);"><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">=C2=A0 =C2=A0 </span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">void</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> swap</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">__tuple_struct</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">&</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> other</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">);</span></div><div style=3D"font-family: Arial, Helvet=
ica, sans-serif; background-color: rgb(255, 255, 255);"><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">};</span></div><div style=3D"font-fa=
mily: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div>=
<div style=3D"font-family: Arial, Helvetica, sans-serif; background-color: =
rgb(255, 255, 255);"><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">template</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">typename</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> T1</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: #=
008;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> T2</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">></span></div><div style=3D"font-family: Arial=
, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"><span style=
=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> __tuple_struct</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">T1</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> T2</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">></span></div><div style=3D"font-family: Arial, Helvet=
ica, sans-serif; background-color: rgb(255, 255, 255);"><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">{</span></div><div style=3D"font-fam=
ily: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> =C2=A0 =C2=A0T1 _=
1</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><=
/div><div style=3D"font-family: Arial, Helvetica, sans-serif; background-co=
lor: rgb(255, 255, 255);"><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> =C2=A0 =C2=A0T2 _2</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">;</span></div><div style=3D"font-family: Arial, Helvetica=
, sans-serif; background-color: rgb(255, 255, 255);"><span style=3D"color: =
#000;" class=3D"styled-by-prettify"><br></span></div><div style=3D"font-fam=
ily: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"><=
span style=3D"color: rgb(136, 0, 0);"><span style=3D"color: #000;" class=3D=
"styled-by-prettify">=C2=A0 =C2=A0</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">template</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify"><</span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">typename</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">..=
..</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Args</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">decltype</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">__tuple_struct</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify"><</span><span style=3D"color: #606;" class=3D"styled-by-prettify=
">Args</span><span style=3D"color: #660;" class=3D"styled-by-prettify">...&=
gt;{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> _1</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> _2 </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">})></span></span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div><div sty=
le=3D"font-family: Arial, Helvetica, sans-serif; background-color: rgb(255,=
255, 255);"><span style=3D"color: #000;" class=3D"styled-by-prettify">=C2=
=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>operator</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
__tuple_struct</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy"><</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Ar=
gs</span><span style=3D"color: #660;" class=3D"styled-by-prettify">...>(=
)</span></div><div style=3D"font-family: Arial, Helvetica, sans-serif; back=
ground-color: rgb(255, 255, 255);"><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> =C2=A0 =C2=A0</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span></div><div style=3D"font-family: Arial, Hel=
vetica, sans-serif; background-color: rgb(255, 255, 255);"><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> =C2=A0 =C2=A0 =C2=A0 =C2=A0</spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">return</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> __tuple_struct</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><sp=
an style=3D"color: #606;" class=3D"styled-by-prettify">Args</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">...>{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> _1</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> _2 </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">};</span></div><div style=3D"font-family: Arial, H=
elvetica, sans-serif; background-color: rgb(255, 255, 255);"><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> =C2=A0 =C2=A0</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">}</span></div><div style=3D=
"font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255,=
255);"><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></spa=
n></div><div style=3D"font-family: Arial, Helvetica, sans-serif; background=
-color: rgb(255, 255, 255);"><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">void</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> swap</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">__tu=
ple_struct</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
&</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> othe=
r</span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span>=
</div><div style=3D"font-family: Arial, Helvetica, sans-serif; background-c=
olor: rgb(255, 255, 255);"><span style=3D"color: #660;" class=3D"styled-by-=
prettify">};</span></div><div style=3D"font-family: Arial, Helvetica, sans-=
serif; background-color: rgb(255, 255, 255);"><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br></span></div><div style=3D"font-family: Ar=
ial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div><div sty=
le=3D"font-family: Arial, Helvetica, sans-serif; background-color: rgb(255,=
255, 255);"><span style=3D"color: #008;" class=3D"styled-by-prettify">temp=
late</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">typename</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: =
#606;" class=3D"styled-by-prettify">Ts</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">></span></div><div style=3D"font-family: Ari=
al, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">using</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> tuple </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> __tuple_struct</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #60=
6;" class=3D"styled-by-prettify">Ts</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">...>;</span></div></div></code></div><br><br></=
div><div>The tuple struct is almost implementable with variadic templates i=
n C++14 - except for the data members.</div><div><br></div><div><br></div><=
div>If that's not clear yet, following implementation is almost dead si=
mple and you get most of current std::tuple functionality for free - perfec=
t initialization, copy/move assignement, copy/move construction, get<N&g=
t;.</div><div><br></div><div>There is only one thing that I don't know =
how to support - the "old" direct initialization syntax with pare=
ntheses instead of curly braces i.e. tuple<Ts...>( args...).</div><di=
v>I hope that supporting it does not require the full-fledged implementatio=
n as we have now (with constructors complexity/problems).</div><div><br></d=
iv><div>I am not an C++ expert, so I am most probably missing something her=
e that makes it infeasible.</div><div><br></div><div>Anyway, what do you th=
ink?</div><div><br></div><div>BTW, is there already a proposal for default =
(builtin) conversion operator for compatible structs? In a similar fashion =
to default comparison operators, it would be provided only if there is no u=
ser-provided one already.</div><div>Something along the lines:</div><div><d=
iv class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); wor=
d-wrap: break-word; background-color: rgb(250, 250, 250);"><code class=3D"p=
rettyprint"><div class=3D"subprettyprint"><div style=3D"font-family: Arial,=
Helvetica, sans-serif; background-color: rgb(255, 255, 255);"><span style=
=3D"color: #008;" class=3D"styled-by-prettify">template</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: #008=
;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> __other_struct</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">typename</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">decltype</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">__other_struct</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">get</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify"><</span><span style=3D"color: #606;" cl=
ass=3D"styled-by-prettify">Ints</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-b=
y-prettify">...</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">})&g=
t;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></sp=
an></div><div style=3D"font-family: Arial, Helvetica, sans-serif; backgroun=
d-color: rgb(255, 255, 255);"><div><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">operator</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> __other_struct</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify"><</span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">Args</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">...>()</span></div><div><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">{</span></div><div><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> =C2=A0 =C2=A0</span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">return</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> __other_struct</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify"><</span><span style=3D"color: #606;" class=3D"=
styled-by-prettify">Args</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">...>{</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">get</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><=
</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Ints</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">...>()...};</=
span></div><div><span style=3D"color: #660;" class=3D"styled-by-prettify">}=
</span></div></div></div></code></div></div><div>=C2=A0 =C2=A0=C2=A0</div><=
div><br></div><div>Regards,<br></div><div>Maciej Cencora</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" 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"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
------=_Part_189_1823778077.1455553143550--
------=_Part_188_324494382.1455553143549--
.
Author: Matthew Woehlke <mwoehlke.floss@gmail.com>
Date: Mon, 15 Feb 2016 12:02:11 -0500
Raw View
On 2016-02-15 11:19, m.cencora@gmail.com wrote:
> BTW, is there already a proposal for default (builtin) conversion operato=
r=20
> for compatible structs?
I don't think so. I've also repeatedly stated opposition to having such
an implicit conversion (see e.g. P0222=C2=B9). Any such conversion should
necessarily be explicit.
If the destination structure supports aggregate initialization, general
unpacking would allow writing an explicit conversion like:
dst =3D {[:]src...};
(=C2=B9 Specifically, the "What about 'pass-through' of return values havin=
g
equivalent types?" question in the discussion section.)
--=20
Matthew
--=20
---=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.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-propos=
als/.
.
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Mon, 15 Feb 2016 19:48:44 +0100
Raw View
This is a multi-part message in MIME format.
--------------040805020509030408090001
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Le 15/02/2016 17:19, m.cencora@gmail.com a =C3=A9crit :
> Hi,
>
> I think the structured binding proposal opens a possibility for major=20
> simplification of std::tuple implementation.
>
> Let's take following "implementation" as an example:
> |
> template<typename...T>
> struct__tuple_struct;
>
> template<typenameT1>
> struct__tuple_struct<T1>
> {
> T1 _1;
>
> template<typename...Args,typename=3Ddecltype(__tuple_struct<Args...>{_1 }=
)>
> operator__tuple_struct<Args...>()
> {
> return__tuple_struct<Args...>{_1 };
> }
>
> voidswap(__tuple_struct&other);
> };
>
> template<typenameT1,typenameT2>
> struct__tuple_struct<T1,T2>
> {
> T1 _1;
> T2 _2;
>
> template<typename...Args,typename=3Ddecltype(__tuple_struct<Args...>{_1,_=
2=20
> })>
> operator__tuple_struct<Args...>()
> {
> return__tuple_struct<Args...>{_1,_2 };
> }
>
> voidswap(__tuple_struct&other);
> };
>
>
> template<typename...Ts>
> usingtuple =3D__tuple_struct<Ts...>;
> |
>
>
Sorry, but I don't how structured bindings plays here.
> The tuple struct is almost implementable with variadic templates in=20
> C++14 - except for the data members.
>
>
I've 3 proposal that are related to having default implementation for=20
tuple-like access, swap and hash that will help to minimize the effort=20
implementing tuple/pair and any aggregate. P0197/P0198/P0199.
> If that's not clear yet, following implementation is almost dead=20
> simple and you get most of current std::tuple functionality for free -=20
> perfect initialization, copy/move assignement, copy/move construction,=20
> get<N>.
>
> There is only one thing that I don't know how to support - the "old"=20
> direct initialization syntax with parentheses instead of curly braces=20
> i.e. tuple<Ts...>( args...).
Yes, you get aggregate initialization, and this is a real compatibility=20
issue.
> I hope that supporting it does not require the full-fledged=20
> implementation as we have now (with constructors complexity/problems).
>
I don't see how.
> I am not an C++ expert, so I am most probably missing something here=20
> that makes it infeasible.
>
> Anyway, what do you think?
>
> BTW, is there already a proposal for default (builtin) conversion=20
> operator for compatible structs?
All depends on what you mean by compatible structs. In P0197 I propose=20
to have a default conversion to pair/tuple as both classes are=20
positional. However I don't see which other compatibility structs are=20
you considering.
> In a similar fashion to default comparison operators, it would be=20
> provided only if there is no user-provided one already.
> Something along the lines:
> |
> template<typename__other_struct,typename=3Ddecltype(__other_struct{get<In=
ts...>(),...})>
> operator__other_struct<Args...>()
> {
> return__other_struct<Args...>{get<Ints...>()...};
> }
> |
>
Consider two structs complex polar and complex Cartesian. Would you want=20
them to be convertible? Evidently no. Structural conversion has no=20
sense, except IMHO when the conversion lost the meaning, as it is the=20
case with conversions to pair/tuple.
Vicente
https://github.com/viboes/std-make/blob/master/doc/proposal/reflection/P019=
7R0.md=20
https://github.com/viboes/std-make/blob/master/doc/proposal/reflection/P019=
8R0.md=20
https://github.com/viboes/std-make/blob/master/doc/proposal/reflection/P019=
9R0.md
--=20
---=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.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-propos=
als/.
--------------040805020509030408090001
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
</head>
<body bgcolor=3D"#FFFFFF" text=3D"#000000">
<div class=3D"moz-cite-prefix">Le 15/02/2016 17:19,
<a class=3D"moz-txt-link-abbreviated" href=3D"mailto:m.cencora@gmail.=
com">m.cencora@gmail.com</a> a =C3=A9crit=C2=A0:<br>
</div>
<blockquote
cite=3D"mid:7ac68e51-c6a5-476a-8bb0-2b2ee5879e1a@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">Hi,
<div><br>
</div>
<div>I think the structured binding proposal opens a possibility
for major simplification of std::tuple implementation.</div>
<div><br>
</div>
<div>Let's take following "implementation" as an example:</div>
<div>
<div class=3D"prettyprint" style=3D"border: 1px solid rgb(187,
187, 187); word-wrap: break-word; background-color: rgb(250,
250, 250);"><code class=3D"prettyprint">
<div class=3D"subprettyprint">
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #008;" class=3D"styled-by-prettify">tem=
plate</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: #008;" class=3D"styled-by-prettify">typ=
ename</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">T</=
span><span
style=3D"color: #660;" class=3D"styled-by-prettify">>=
;</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #008;" class=3D"styled-by-prettify">str=
uct</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
__tuple_struct</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">;</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>
</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #008;" class=3D"styled-by-prettify">tem=
plate</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: #008;" class=3D"styled-by-prettify">typ=
ename</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> T1=
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">>=
;</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #008;" class=3D"styled-by-prettify">str=
uct</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
__tuple_struct</span><span style=3D"color: #660;"
class=3D"styled-by-prettify"><</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">T1<=
/span><span
style=3D"color: #660;" class=3D"styled-by-prettify">>=
;</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #660;" class=3D"styled-by-prettify">{</=
span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
=C2=A0
=C2=A0T1 _1</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">;</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>
</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify">=C2=
=A0 =C2=A0
</span><span style=3D"color: #008;"
class=3D"styled-by-prettify">template</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: #008;" class=3D"styled-by-prettify">typ=
ename</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: #606;" class=3D"styled-by-prettify">Arg=
s</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: #008;" class=3D"styled-by-prettify">typ=
ename</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span
style=3D"color: #660;" class=3D"styled-by-prettify">=3D=
</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span
style=3D"color: #008;" class=3D"styled-by-prettify">dec=
ltype</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">(</=
span><span
style=3D"color: #000;" class=3D"styled-by-prettify">__t=
uple_struct</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><=
;</span><span
style=3D"color: #606;" class=3D"styled-by-prettify">Arg=
s</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">...=
>{</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> _1
</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>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify">=C2=
=A0 =C2=A0
</span><span style=3D"color: #008;"
class=3D"styled-by-prettify">operator</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
__tuple_struct</span><span style=3D"color: #660;"
class=3D"styled-by-prettify"><</span><span
style=3D"color: #606;" class=3D"styled-by-prettify">Arg=
s</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">...=
>()</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
=C2=A0 =C2=A0</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">{</=
span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
=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: #000;" class=3D"styled-by-prettify">
__tuple_struct</span><span style=3D"color: #660;"
class=3D"styled-by-prettify"><</span><span
style=3D"color: #606;" class=3D"styled-by-prettify">Arg=
s</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">...=
>{</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> _1
</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">};</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
=C2=A0 =C2=A0</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">}</=
span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>
</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify">=C2=
=A0 =C2=A0
</span><span style=3D"color: #008;"
class=3D"styled-by-prettify">void</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
swap</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">(</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">__t=
uple_struct</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">&am=
p;</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
other</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">);</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #660;" class=3D"styled-by-prettify">};<=
/span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>
</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #008;" class=3D"styled-by-prettify">tem=
plate</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: #008;" class=3D"styled-by-prettify">typ=
ename</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> T1=
</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: #008;" class=3D"styled-by-prettify">typ=
ename</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> T2=
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">>=
;</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #008;" class=3D"styled-by-prettify">str=
uct</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
__tuple_struct</span><span style=3D"color: #660;"
class=3D"styled-by-prettify"><</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">T1<=
/span><span
style=3D"color: #660;" class=3D"styled-by-prettify">,</=
span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> T2=
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">>=
;</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #660;" class=3D"styled-by-prettify">{</=
span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
=C2=A0
=C2=A0T1 _1</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">;</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
=C2=A0
=C2=A0T2 _2</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">;</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>
</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: rgb(136, 0, 0);"><span style=3D"color:
#000;" class=3D"styled-by-prettify">=C2=A0 =C2=A0</sp=
an><span
style=3D"color: #008;" class=3D"styled-by-prettify">t=
emplate</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">&=
lt;</span><span
style=3D"color: #008;" class=3D"styled-by-prettify">t=
ypename</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: #606;" class=3D"styled-by-prettify">A=
rgs</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: #008;" class=3D"styled-by-prettify">t=
ypename</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span
style=3D"color: #008;" class=3D"styled-by-prettify">d=
ecltype</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">(=
</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">_=
_tuple_struct</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">&=
lt;</span><span
style=3D"color: #606;" class=3D"styled-by-prettify">A=
rgs</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">.=
...>{</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
_1</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">,</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
_2 </span><span style=3D"color: #660;"
class=3D"styled-by-prettify">})></span></span><spa=
n
style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>
</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify">=C2=
=A0 =C2=A0
</span><span style=3D"color: #008;"
class=3D"styled-by-prettify">operator</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
__tuple_struct</span><span style=3D"color: #660;"
class=3D"styled-by-prettify"><</span><span
style=3D"color: #606;" class=3D"styled-by-prettify">Arg=
s</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">...=
>()</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
=C2=A0 =C2=A0</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">{</=
span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
=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: #000;" class=3D"styled-by-prettify">
__tuple_struct</span><span style=3D"color: #660;"
class=3D"styled-by-prettify"><</span><span
style=3D"color: #606;" class=3D"styled-by-prettify">Arg=
s</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">...=
>{</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> _1=
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">,</=
span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> _2
</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">};</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify"> =
=C2=A0 =C2=A0</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">}</=
span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>
</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify">=C2=
=A0 =C2=A0
</span><span style=3D"color: #008;"
class=3D"styled-by-prettify">void</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
swap</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">(</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">__t=
uple_struct</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">&am=
p;</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
other</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">);</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #660;" class=3D"styled-by-prettify">};<=
/span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>
</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>
</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #008;" class=3D"styled-by-prettify">tem=
plate</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: #008;" class=3D"styled-by-prettify">typ=
ename</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: #606;" class=3D"styled-by-prettify">Ts<=
/span><span
style=3D"color: #660;" class=3D"styled-by-prettify">>=
;</span></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #008;" class=3D"styled-by-prettify">usi=
ng</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
tuple </span><span style=3D"color: #660;"
class=3D"styled-by-prettify">=3D</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
__tuple_struct</span><span style=3D"color: #660;"
class=3D"styled-by-prettify"><</span><span
style=3D"color: #606;" class=3D"styled-by-prettify">Ts<=
/span><span
style=3D"color: #660;" class=3D"styled-by-prettify">...=
>;</span></div>
</div>
</code></div>
<br>
<br>
</div>
</div>
</blockquote>
Sorry, but I don't how structured bindings plays here.<br>
<blockquote
cite=3D"mid:7ac68e51-c6a5-476a-8bb0-2b2ee5879e1a@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">
<div>The tuple struct is almost implementable with variadic
templates in C++14 - except for the data members.</div>
<div><br>
</div>
<div><br>
</div>
</div>
</blockquote>
I've 3 proposal that are related to having default implementation
for tuple-like access, swap and hash that will help to minimize the
effort implementing tuple/pair and any aggregate. P0197/P0198/P0199.<br=
>
<blockquote
cite=3D"mid:7ac68e51-c6a5-476a-8bb0-2b2ee5879e1a@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">
<div>If that's not clear yet, following implementation is almost
dead simple and you get most of current std::tuple
functionality for free - perfect initialization, copy/move
assignement, copy/move construction, get<N>.</div>
<div><br>
</div>
<div>There is only one thing that I don't know how to support -
the "old" direct initialization syntax with parentheses
instead of curly braces i.e. tuple<Ts...>( args...).</div>
</div>
</blockquote>
Yes, you get aggregate initialization, and this is a real
compatibility issue.<br>
<blockquote
cite=3D"mid:7ac68e51-c6a5-476a-8bb0-2b2ee5879e1a@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">
<div>I hope that supporting it does not require the full-fledged
implementation as we have now (with constructors
complexity/problems).</div>
<div><br>
</div>
</div>
</blockquote>
I don't see how.<br>
<blockquote
cite=3D"mid:7ac68e51-c6a5-476a-8bb0-2b2ee5879e1a@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">
<div>I am not an C++ expert, so I am most probably missing
something here that makes it infeasible.</div>
<div><br>
</div>
<div>Anyway, what do you think?</div>
<div><br>
</div>
<div>BTW, is there already a proposal for default (builtin)
conversion operator for compatible structs?</div>
</div>
</blockquote>
All depends on what you mean by compatible structs. In P0197 I
propose to have a default conversion to pair/tuple as both classes
are positional. However I don't see which other compatibility
structs are you considering.<br>
<blockquote
cite=3D"mid:7ac68e51-c6a5-476a-8bb0-2b2ee5879e1a@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">
<div> In a similar fashion to default comparison operators, it
would be provided only if there is no user-provided one
already.</div>
<div>Something along the lines:</div>
<div>
<div class=3D"prettyprint" style=3D"border: 1px solid rgb(187,
187, 187); word-wrap: break-word; background-color: rgb(250,
250, 250);"><code class=3D"prettyprint">
<div class=3D"subprettyprint">
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><span
style=3D"color: #008;" class=3D"styled-by-prettify">tem=
plate</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: #008;" class=3D"styled-by-prettify">typ=
ename</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
__other_struct</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: #008;" class=3D"styled-by-prettify">typ=
ename</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span
style=3D"color: #660;" class=3D"styled-by-prettify">=3D=
</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span
style=3D"color: #008;" class=3D"styled-by-prettify">dec=
ltype</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">(</=
span><span
style=3D"color: #000;" class=3D"styled-by-prettify">__o=
ther_struct</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: #008;" class=3D"styled-by-prettify">get=
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><=
;</span><span
style=3D"color: #606;" class=3D"styled-by-prettify">Int=
s</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"> </=
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></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);">
<div><span style=3D"color: #008;"
class=3D"styled-by-prettify">operator</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
__other_struct</span><span style=3D"color: #660;"
class=3D"styled-by-prettify"><</span><span
style=3D"color: #606;" class=3D"styled-by-prettify">A=
rgs</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">.=
...>()</span></div>
<div><span style=3D"color: #660;"
class=3D"styled-by-prettify">{</span></div>
<div><span style=3D"color: #000;"
class=3D"styled-by-prettify"> =C2=A0 =C2=A0</span><sp=
an
style=3D"color: #008;" class=3D"styled-by-prettify">r=
eturn</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
__other_struct</span><span style=3D"color: #660;"
class=3D"styled-by-prettify"><</span><span
style=3D"color: #606;" class=3D"styled-by-prettify">A=
rgs</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: #008;" class=3D"styled-by-prettify">g=
et</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">&=
lt;</span><span
style=3D"color: #606;" class=3D"styled-by-prettify">I=
nts</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">.=
...>()...};</span></div>
<div><span style=3D"color: #660;"
class=3D"styled-by-prettify">}</span></div>
</div>
</div>
</code></div>
</div>
<div>=C2=A0 =C2=A0=C2=A0</div>
<div><br>
</div>
</div>
</blockquote>
Consider two structs complex polar and complex Cartesian. Would you
want them to be convertible? Evidently no. Structural conversion has
no sense, except IMHO when the conversion lost the meaning, as it is
the case with conversions to pair/tuple.<br>
<br>
Vicente<br>
<br>
<a class=3D"moz-txt-link-freetext"
href=3D"https://github.com/viboes/std-make/blob/master/doc/proposal/reflect=
ion/P0198R0.md">https://github.com/viboes/std-make/blob/master/doc/proposal=
/reflection/P0197R0.md</a>
<br>
<br>
<a class=3D"moz-txt-link-freetext"
href=3D"https://github.com/viboes/std-make/blob/master/doc/proposal/reflect=
ion/P0198R0.md">https://github.com/viboes/std-make/blob/master/doc/proposal=
/reflection/P0198R0.md</a>
<br>
<br>
<a class=3D"moz-txt-link-freetext"
href=3D"https://github.com/viboes/std-make/blob/master/doc/proposal/reflect=
ion/P0199R0.md">https://github.com/viboes/std-make/blob/master/doc/proposal=
/reflection/P0199R0.md</a><br>
</body>
</html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
--------------040805020509030408090001--
.
Author: m.cencora@gmail.com
Date: Mon, 15 Feb 2016 13:24:34 -0800 (PST)
Raw View
------=_Part_19_1641855396.1455571474436
Content-Type: multipart/alternative;
boundary="----=_Part_20_477018007.1455571474437"
------=_Part_20_477018007.1455571474437
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Hi,
W dniu poniedzia=C5=82ek, 15 lutego 2016 19:48:48 UTC+1 u=C5=BCytkownik Vic=
ente J.=20
Botet Escriba napisa=C5=82:
>
> Le 15/02/2016 17:19, m.ce...@gmail.com <javascript:> a =C3=A9crit :
>
> Hi,=20
>
> I think the structured binding proposal opens a possibility for major=20
> simplification of std::tuple implementation.
>
> Let's take following "implementation" as an example:
> template <typename ...T>
> struct __tuple_struct;
>
> template <typename T1>
> struct __tuple_struct<T1>
> {
> T1 _1;
>
> template <typename ...Args, typename =3D decltype(__tuple_struct<Args
> ...>{ _1 })>
> operator __tuple_struct<Args...>()
> {
> return __tuple_struct<Args...>{ _1 };
> }
>
> void swap(__tuple_struct& other);
> };
>
> template <typename T1, typename T2>
> struct __tuple_struct<T1, T2>
> {
> T1 _1;
> T2 _2;
>
> template <typename ...Args, typename =3D decltype(__tuple_struct<Args
> ...>{ _1, _2 })>
> operator __tuple_struct<Args...>()
> {
> return __tuple_struct<Args...>{ _1, _2 };
> }
>
> void swap(__tuple_struct& other);
> };
>
>
> template <typename ...Ts>
> using tuple =3D __tuple_struct<Ts...>;
>
>
> Sorry, but I don't how structured bindings plays here.
>
Yeah, I should have clarified that.=20
In C++14 to provide the get<N> functionality the tuple is implemented with=
=20
either multiple inheritance or recursive inheritance.
Structured binding allows to base the tuple implementation on a simple=20
struct - get<N>() will be provided by language.
What is additionally needed is a way to create this base struct, it can be=
=20
either:
1) compiler provided builtin template __magic_struct<Ts...> with only the=
=20
data members of given types
2) new language feature to define new data members based on some template=
=20
parameter pack.
> The tuple struct is almost implementable with variadic templates in C++14=
=20
> - except for the data members.
>
>
> I've 3 proposal that are related to having default implementation for=20
> tuple-like access, swap and hash that will help to minimize the effort=20
> implementing tuple/pair and any aggregate. P0197/P0198/P0199.
>
> If that's not clear yet, following implementation is almost dead simple=
=20
> and you get most of current std::tuple functionality for free - perfect=
=20
> initialization, copy/move assignement, copy/move construction, get<N>.
>
> There is only one thing that I don't know how to support - the "old"=20
> direct initialization syntax with parentheses instead of curly braces i.e=
..=20
> tuple<Ts...>( args...).
>
> Yes, you get aggregate initialization, and this is a real compatibility=
=20
> issue.
>
> I hope that supporting it does not require the full-fledged implementatio=
n=20
> as we have now (with constructors complexity/problems).
>
> I don't see how.
>
I checked how much code would be needed to support this actually, and it=20
turns out not really that much.
template <typename ...Ts>
struct tuple : __magic_struct<Ts...>
{
using base =3D __magic_struct<Ts...>;
=20
template <typename ...Us, typename =3D std::__void_t<decltype(base{std:=
:
forward<Us>(std::declval<Us&&>())...})>>
tuple(Us&& ...us)
: base{std::forward<Us>(us)...}
{}
=20
template <typename ...Us>
operator tuple<Us...>()
{
return { get<0>(*this), get<1>(*this) }; // this should be a=20
properly unrolled parameter pack
}
};
This simple implementation supports:
1) construction in both forms {args..} and (args...)
2) copy/move construction
3) copy/move assignement
4) construction from lvalue/rvalue compatible tuple
5) assignement from lvalue/rvalue compatible tuple
I guess proper support for explicit constructor and constexpr will=20
complicate things a bit.
Do you know if there a tuple test suite that I could use to verify my impl?
=20
> I am not an C++ expert, so I am most probably missing something here that=
=20
> makes it infeasible.
>
> Anyway, what do you think?
>
> BTW, is there already a proposal for default (builtin) conversion operato=
r=20
> for compatible structs?
>
> All depends on what you mean by compatible structs. In P0197 I propose to=
=20
> have a default conversion to pair/tuple as both classes are positional.=
=20
> However I don't see which other compatibility structs are you considering=
..
>
> In a similar fashion to default comparison operators, it would be provide=
d=20
> only if there is no user-provided one already.
> Something along the lines:
> template <typename __other_struct, typename =3D decltype(__other_struct{ =
get
> <Ints...>(), ... })>
> operator __other_struct<Args...>()
> {
> return __other_struct<Args...>{ get<Ints...>()...};
> }
> =20
>
> Consider two structs complex polar and complex Cartesian. Would you want=
=20
> them to be convertible? Evidently no. Structural conversion has no sense,=
=20
> except IMHO when the conversion lost the meaning, as it is the case with=
=20
> conversions to pair/tuple.
>
Understood, certainly not a good idea to make such conversions implicit.
Regards,
Maciej Cencora
=20
>
> Vicente
>
>
> https://github.com/viboes/std-make/blob/master/doc/proposal/reflection/P0=
197R0.md=20
> <https://github.com/viboes/std-make/blob/master/doc/proposal/reflection/P=
0198R0.md>=20
>
>
> https://github.com/viboes/std-make/blob/master/doc/proposal/reflection/P0=
198R0.md=20
>
>
> https://github.com/viboes/std-make/blob/master/doc/proposal/reflection/P0=
199R0.md
>
--=20
---=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.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-propos=
als/.
------=_Part_20_477018007.1455571474437
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hi,<br><br>W dniu poniedzia=C5=82ek, 15 lutego 2016 19:48:=
48 UTC+1 u=C5=BCytkownik Vicente J. Botet Escriba napisa=C5=82:<blockquote =
class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1p=
x #ccc solid;padding-left: 1ex;">
=20
=20
=20
<div bgcolor=3D"#FFFFFF" text=3D"#000000">
<div>Le 15/02/2016 17:19,
<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"9T=
54aRIEIAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:=
9;;return true;" onclick=3D"this.href=3D'javascript:';return true;"=
>m.ce...@gmail.com</a> a =C3=A9crit=C2=A0:<br>
</div>
<blockquote type=3D"cite">
<div dir=3D"ltr">Hi,
<div><br>
</div>
<div>I think the structured binding proposal opens a possibility
for major simplification of std::tuple implementation.</div>
<div><br>
</div>
<div>Let's take following "implementation" as an exam=
ple:</div>
<div>
<div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-w=
ord;background-color:rgb(250,250,250)"><code>
<div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">template</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660"><</span><span =
style=3D"color:#008">typename</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">...</span><span style=3D"color:#000">T</span><span s=
tyle=3D"color:#660">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">struct</span><span =
style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660">;</span=
></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">template</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660"><</span><span =
style=3D"color:#008">typename</span><span style=3D"color:#000"> T1</span><s=
pan style=3D"color:#660">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">struct</span><span =
style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#000">T1</span><span style=3D"color:#660">></sp=
an></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#660">{</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0
=C2=A0T1 _1</span><span style=3D"color:#660">;</span></=
div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000">=C2=A0 =C2=A0
</span><span style=3D"color:#008">template</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#660"><</span><span styl=
e=3D"color:#008">typename</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#660">...</span><span style=3D"color:#606">Args</span><span st=
yle=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">typename</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">decltype</span><span style=3D"color:#660">(</span><span sty=
le=3D"color:#000">__tuple_struct</span><span style=3D"color:#660"><</spa=
n><span style=3D"color:#606">Args</span><span style=3D"color:#660">..<wbr>.=
>{</span><span style=3D"color:#000"> _1
</span><span style=3D"color:#660">})></span><span styl=
e=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000">=C2=A0 =C2=A0
</span><span style=3D"color:#008">operator</span><span st=
yle=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#606">Args</span><span style=3D"color:#660">...>=
;()</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0</spa=
n><span style=3D"color:#660">{</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0
=C2=A0 =C2=A0</span><span style=3D"color:#008">return</=
span><span style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#606">Args</span><span style=3D"color:#660">...>=
;{</span><span style=3D"color:#000"> _1
</span><span style=3D"color:#660">};</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0</spa=
n><span style=3D"color:#660">}</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000">=C2=A0 =C2=A0
</span><span style=3D"color:#008">void</span><span style=
=3D"color:#000">
swap</span><span style=3D"color:#660">(</span><span sty=
le=3D"color:#000">__tuple_struct</span><span style=3D"color:#660">&</sp=
an><span style=3D"color:#000">
other</span><span style=3D"color:#660">);</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#660">};</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">template</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660"><</span><span =
style=3D"color:#008">typename</span><span style=3D"color:#000"> T1</span><s=
pan style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#008">typename</span><span style=3D"color:#000"> T2</span><sp=
an style=3D"color:#660">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">struct</span><span =
style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#000">T1</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> T2</span><span style=3D"color:#660">></span>=
</div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#660">{</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0
=C2=A0T1 _1</span><span style=3D"color:#660">;</span></=
div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0
=C2=A0T2 _2</span><span style=3D"color:#660">;</span></=
div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:rgb(136,0,0)"><span style=
=3D"color:#000">=C2=A0 =C2=A0</span><span style=3D"color:#008">template</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#660"><</span=
><span style=3D"color:#008">typename</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">...</span><span style=3D"color:#606">Args</sp=
an><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#008">typename</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#008">decltype</span><span style=3D"color:#660">(</span><=
span style=3D"color:#000">__tuple_struct</span><span style=3D"color:#660">&=
lt;</span><span style=3D"color:#606">Args</span><span style=3D"color:#660">=
...<wbr>.>{</span><span style=3D"color:#000">
_1</span><span style=3D"color:#660">,</span><span sty=
le=3D"color:#000">
_2 </span><span style=3D"color:#660">})></span></s=
pan><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000">=C2=A0 =C2=A0
</span><span style=3D"color:#008">operator</span><span st=
yle=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#606">Args</span><span style=3D"color:#660">...>=
;()</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0</spa=
n><span style=3D"color:#660">{</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0
=C2=A0 =C2=A0</span><span style=3D"color:#008">return</=
span><span style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#606">Args</span><span style=3D"color:#660">...>=
;{</span><span style=3D"color:#000"> _1</span><span style=3D"color:#660">,<=
/span><span style=3D"color:#000"> _2
</span><span style=3D"color:#660">};</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0</spa=
n><span style=3D"color:#660">}</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000">=C2=A0 =C2=A0
</span><span style=3D"color:#008">void</span><span style=
=3D"color:#000">
swap</span><span style=3D"color:#660">(</span><span sty=
le=3D"color:#000">__tuple_struct</span><span style=3D"color:#660">&</sp=
an><span style=3D"color:#000">
other</span><span style=3D"color:#660">);</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#660">};</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">template</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660"><</span><span =
style=3D"color:#008">typename</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">...</span><span style=3D"color:#606">Ts</span><span =
style=3D"color:#660">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">using</span><span s=
tyle=3D"color:#000">
tuple </span><span style=3D"color:#660">=3D</span><span=
style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#606">Ts</span><span style=3D"color:#660">...>;=
</span></div>
</div>
</code></div>
<br>
<br>
</div>
</div>
</blockquote>
Sorry, but I don't how structured bindings plays here.<br></div></b=
lockquote><div><br>Yeah, I should have clarified that. <br>In C++14 to prov=
ide the get<N> functionality the tuple is implemented with either mul=
tiple inheritance or recursive inheritance.<br>Structured binding allows to=
base the tuple implementation on a simple struct - get<N>() will be =
provided by language.<br><br>What is additionally needed is a way to create=
this base struct, it can be either:<br>1) compiler provided builtin templa=
te __magic_struct<Ts...> with only the data members of given types<br=
>2) new language feature to define new data members based on some template =
parameter pack.<br></div><blockquote class=3D"gmail_quote" style=3D"margin:=
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div =
bgcolor=3D"#FFFFFF" text=3D"#000000">
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div>The tuple struct is almost implementable with variadic
templates in C++14 - except for the data members.</div>
<div><br>
</div>
<div><br>
</div>
</div>
</blockquote>
I've 3 proposal that are related to having default implementation
for tuple-like access, swap and hash that will help to minimize the
effort implementing tuple/pair and any aggregate. P0197/P0198/P0199.<br=
>
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div>If that's not clear yet, following implementation is almos=
t
dead simple and you get most of current std::tuple
functionality for free - perfect initialization, copy/move
assignement, copy/move construction, get<N>.</div>
<div><br>
</div>
<div>There is only one thing that I don't know how to support -
the "old" direct initialization syntax with parentheses
instead of curly braces i.e. tuple<Ts...>( args...).</div>
</div>
</blockquote>
Yes, you get aggregate initialization, and this is a real
compatibility issue.<br>
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div>I hope that supporting it does not require the full-fledged
implementation as we have now (with constructors
complexity/problems).</div>
<div><br>
</div>
</div>
</blockquote>
I don't see how.<br></div></blockquote><div><br>I checked how much =
code would be needed to support this actually, and it turns out not really =
that much.<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"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">template</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">typename</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">...</span><span style=3D"=
color: #606;" class=3D"styled-by-prettify">Ts</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: #008;" class=
=3D"styled-by-prettify">struct</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> tuple </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> __magic_struct</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify"><</span><span style=3D"color: #606;" class=3D"styled-by-pre=
ttify">Ts</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><s=
pan 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">using</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">base</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> __magic_struct</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify"><</span><span style=3D"color: #606;" cl=
ass=3D"styled-by-prettify">Ts</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">...>;</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br>=C2=A0 =C2=A0 <br>=C2=A0 =C2=A0 </span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">template</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660=
;" class=3D"styled-by-prettify"><</span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">...</span><span style=3D"color: #606;" class=3D"styled-by-pr=
ettify">Us</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: #008;" class=3D"styled-by-prettify">typename</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> std</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">__void_t</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify"><</span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">decltype</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">base</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>{</span><span style=3D"color: #000;" class=3D"styled-by-prettify">std</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify">forward</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"=
color: #606;" class=3D"styled-by-prettify">Us</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 style=3D"color: #000;" class=3D"styl=
ed-by-prettify">declval</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify"><</span><span style=3D"color: #606;" class=3D"styled-by-pre=
ttify">Us</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
amp;&>())...})>></span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br>=C2=A0 =C2=A0 tuple</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Us</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&&</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">...</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
us</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=
=C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">:<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">base</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">std</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">forward</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify"><</span><span style=3D"color: #606;" class=3D"st=
yled-by-prettify">Us</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">>(</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">us</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: #660;" class=3D"styled-by-prettify"=
>{}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=
=A0 =C2=A0 <br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">template</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify"><</span><span style=3D"color: #008;" class=3D"styled-by-prettify=
">typename</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: #606;" class=3D"styled-by-prettify">Us</span><span s=
tyle=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><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">operator</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> tuple</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"=
color: #606;" class=3D"styled-by-prettify">Us</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">...>()</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">return</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </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">get</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify"><</span><span style=3D"color: #066;" class=3D"styled-by=
-prettify">0</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">>(*</span><span style=3D"color: #008;" class=3D"styled-by-prettify">th=
is</span><span style=3D"color: #660;" class=3D"styled-by-prettify">),</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">get</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color:=
#066;" class=3D"styled-by-prettify">1</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">>(*</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">this</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </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: #800;" class=3D"styled-by-prettify">// this should be=
a properly unrolled parameter pack</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #66=
0;" 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"st=
yled-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br></span></div></code></div><br>This simple implementation supp=
orts:<br>1) construction in both forms {args..} and (args...)<br>2) copy/mo=
ve construction<br>3) copy/move assignement<br>4) construction from lvalue/=
rvalue compatible tuple<br>5) assignement from lvalue/rvalue compatible tup=
le<br><br>I guess proper support for explicit constructor and constexpr wil=
l complicate things a bit.<br><br>Do you know if there a tuple test suite t=
hat I could use to verify my impl?<br>=C2=A0<br></div><blockquote class=3D"=
gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc so=
lid;padding-left: 1ex;"><div bgcolor=3D"#FFFFFF" text=3D"#000000">
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div>I am not an C++ expert, so I am most probably missing
something here that makes it infeasible.</div>
<div><br>
</div>
<div>Anyway, what do you think?</div>
<div><br>
</div>
<div>BTW, is there already a proposal for default (builtin)
conversion operator for compatible structs?</div>
</div>
</blockquote>
All depends on what you mean by compatible structs. In P0197 I
propose to have a default conversion to pair/tuple as both classes
are positional. However I don't see which other compatibility
structs are you considering.<br>
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div> In a similar fashion to default comparison operators, it
would be provided only if there is no user-provided one
already.</div>
<div>Something along the lines:</div>
<div>
<div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-w=
ord;background-color:rgb(250,250,250)"><code>
<div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">template</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660"><</span><span =
style=3D"color:#008">typename</span><span style=3D"color:#000">
__other_struct</span><span style=3D"color:#660">,</span=
><span style=3D"color:#000"> </span><span style=3D"color:#008">typename</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#660">=3D</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#008">decltype</spa=
n><span style=3D"color:#660">(</span><span style=3D"color:#000">__other_str=
uct</span><span style=3D"color:#660">{</span><span style=3D"color:#000"> </=
span><span style=3D"color:#008">get</span><span style=3D"color:#660"><</=
span><span style=3D"color:#606">Ints</span><span style=3D"color:#660">...&g=
t;(),</span><span style=3D"color:#000"> </span><span style=3D"color:#660">.=
...</span><span style=3D"color:#000"> </span><span style=3D"color:#660">})&g=
t;</span><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)">
<div><span style=3D"color:#008">operator</span><span styl=
e=3D"color:#000">
__other_struct</span><span style=3D"color:#660"><<=
/span><span style=3D"color:#606">Args</span><span style=3D"color:#660">...&=
gt;()</span></div>
<div><span style=3D"color:#660">{</span></div>
<div><span style=3D"color:#000"> =C2=A0 =C2=A0</span><spa=
n style=3D"color:#008">return</span><span style=3D"color:#000">
__other_struct</span><span style=3D"color:#660"><<=
/span><span style=3D"color:#606">Args</span><span style=3D"color:#660">...&=
gt;{</span><span style=3D"color:#000"> </span><span style=3D"color:#008">ge=
t</span><span style=3D"color:#660"><</span><span style=3D"color:#606">In=
ts</span><span style=3D"color:#660">...>()...};</span></div>
<div><span style=3D"color:#660">}</span></div>
</div>
</div>
</code></div>
</div>
<div>=C2=A0 =C2=A0=C2=A0</div>
<div><br>
</div>
</div>
</blockquote>
Consider two structs complex polar and complex Cartesian. Would you
want them to be convertible? Evidently no. Structural conversion has
no sense, except IMHO when the conversion lost the meaning, as it is
the case with conversions to pair/tuple.<br></div></blockquote><div><br=
>Understood, certainly not a good idea to make such conversions implicit.<b=
r><br>Regards,<br>Maciej Cencora<br>=C2=A0</div><blockquote class=3D"gmail_=
quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;pa=
dding-left: 1ex;"><div bgcolor=3D"#FFFFFF" text=3D"#000000">
<br>
Vicente<br>
<br>
<a href=3D"https://github.com/viboes/std-make/blob/master/doc/proposal/=
reflection/P0198R0.md" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"th=
is.href=3D'https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Fvi=
boes%2Fstd-make%2Fblob%2Fmaster%2Fdoc%2Fproposal%2Freflection%2FP0198R0.md\=
46sa\75D\46sntz\0751\46usg\75AFQjCNGD6enCkph7Ag1HsD1fENihtQo1Qw';return=
true;" onclick=3D"this.href=3D'https://www.google.com/url?q\75https%3A=
%2F%2Fgithub.com%2Fviboes%2Fstd-make%2Fblob%2Fmaster%2Fdoc%2Fproposal%2Fref=
lection%2FP0198R0.md\46sa\75D\46sntz\0751\46usg\75AFQjCNGD6enCkph7Ag1HsD1fE=
NihtQo1Qw';return true;">https://github.com/viboes/std-<wbr>make/blob/m=
aster/doc/proposal/<wbr>reflection/P0197R0.md</a>
<br>
<br>
<a href=3D"https://github.com/viboes/std-make/blob/master/doc/proposal/=
reflection/P0198R0.md" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"th=
is.href=3D'https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Fvi=
boes%2Fstd-make%2Fblob%2Fmaster%2Fdoc%2Fproposal%2Freflection%2FP0198R0.md\=
46sa\75D\46sntz\0751\46usg\75AFQjCNGD6enCkph7Ag1HsD1fENihtQo1Qw';return=
true;" onclick=3D"this.href=3D'https://www.google.com/url?q\75https%3A=
%2F%2Fgithub.com%2Fviboes%2Fstd-make%2Fblob%2Fmaster%2Fdoc%2Fproposal%2Fref=
lection%2FP0198R0.md\46sa\75D\46sntz\0751\46usg\75AFQjCNGD6enCkph7Ag1HsD1fE=
NihtQo1Qw';return true;">https://github.com/viboes/std-<wbr>make/blob/m=
aster/doc/proposal/<wbr>reflection/P0198R0.md</a>
<br>
<br>
<a href=3D"https://github.com/viboes/std-make/blob/master/doc/proposal/=
reflection/P0199R0.md" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"th=
is.href=3D'https://www.google.com/url?q\75https%3A%2F%2Fgithub.com%2Fvi=
boes%2Fstd-make%2Fblob%2Fmaster%2Fdoc%2Fproposal%2Freflection%2FP0199R0.md\=
46sa\75D\46sntz\0751\46usg\75AFQjCNEatZj2KITAWF_ObLyurp_L1lMwJQ';return=
true;" onclick=3D"this.href=3D'https://www.google.com/url?q\75https%3A=
%2F%2Fgithub.com%2Fviboes%2Fstd-make%2Fblob%2Fmaster%2Fdoc%2Fproposal%2Fref=
lection%2FP0199R0.md\46sa\75D\46sntz\0751\46usg\75AFQjCNEatZj2KITAWF_ObLyur=
p_L1lMwJQ';return true;">https://github.com/viboes/std-<wbr>make/blob/m=
aster/doc/proposal/<wbr>reflection/P0199R0.md</a><br>
</div>
</blockquote></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
------=_Part_20_477018007.1455571474437--
------=_Part_19_1641855396.1455571474436--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Mon, 15 Feb 2016 14:06:28 -0800 (PST)
Raw View
------=_Part_6045_1789201026.1455573988450
Content-Type: multipart/alternative;
boundary="----=_Part_6046_1650137706.1455573988451"
------=_Part_6046_1650137706.1455573988451
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Monday, February 15, 2016 at 4:24:35 PM UTC-5, m.ce...@gmail.com wrote:
>
> Hi,
>
> W dniu poniedzia=C5=82ek, 15 lutego 2016 19:48:48 UTC+1 u=C5=BCytkownik V=
icente J.=20
> Botet Escriba napisa=C5=82:
>>
>> Le 15/02/2016 17:19, m.ce...@gmail.com a =C3=A9crit :
>>
>> Hi,=20
>>
>> I think the structured binding proposal opens a possibility for major=20
>> simplification of std::tuple implementation.
>>
>> Let's take following "implementation" as an example:
>> template <typename ...T>
>> struct __tuple_struct;
>>
>> template <typename T1>
>> struct __tuple_struct<T1>
>> {
>> T1 _1;
>>
>> template <typename ...Args, typename =3D decltype(__tuple_struct<Arg=
s
>> ...>{ _1 })>
>> operator __tuple_struct<Args...>()
>> {
>> return __tuple_struct<Args...>{ _1 };
>> }
>>
>> void swap(__tuple_struct& other);
>> };
>>
>> template <typename T1, typename T2>
>> struct __tuple_struct<T1, T2>
>> {
>> T1 _1;
>> T2 _2;
>>
>> template <typename ...Args, typename =3D decltype(__tuple_struct<Args
>> ...>{ _1, _2 })>
>> operator __tuple_struct<Args...>()
>> {
>> return __tuple_struct<Args...>{ _1, _2 };
>> }
>>
>> void swap(__tuple_struct& other);
>> };
>>
>>
>> template <typename ...Ts>
>> using tuple =3D __tuple_struct<Ts...>;
>>
>>
>> Sorry, but I don't how structured bindings plays here.
>>
>
> Yeah, I should have clarified that.=20
> In C++14 to provide the get<N> functionality the tuple is implemented wit=
h=20
> either multiple inheritance or recursive inheritance.
> Structured binding allows to base the tuple implementation on a simple=20
> struct - get<N>() will be provided by language.
>
> What is additionally needed is a way to create this base struct, it can b=
e=20
> either:
> 1) compiler provided builtin template __magic_struct<Ts...> with only the=
=20
> data members of given types
> 2) new language feature to define new data members based on some template=
=20
> parameter pack.
>
OK, I fail to see how this concerns the standard at all, save for in one=20
way that I'll get to momentarily. Presumably, the "magic struct" won't=20
allow you to access the members directly; you have to use tuple syntax=20
(like `get<>`). And your implementation below shows that you still need a=
=20
constructor, so you can't use aggregate initialization directly. And=20
therefore... nothing changes for the user.
Which means that standard library implementations of `tuple` could do this=
=20
right now, today, and still be standard compliant. So if a compiler vendor=
=20
wanted to create such a "magic struct" and have their tuple implementation=
=20
use it, that's their business.
The standard specifies behavior, *not* implementation.
As I pointed out earlier, there is one behavioral difference. `tuple` is=20
currently not required to be standard layout, even if the types it is given=
=20
are. If you implemented it your way, it would be *able* to be a standard=20
layout type (so long as the "magic struct" satisfies standard layout=20
rules). `tuple` is also not required to be trivially copyable.
This is the only behavioral difference between what you're proposing and=20
what we have now: that `tuple` could be standard layout & trivially=20
copyable if the component types fulfill these requirements.
--=20
---=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.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-propos=
als/.
------=_Part_6046_1650137706.1455573988451
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Monday, February 15, 2016 at 4:24:35 PM UTC-5, m.ce...@=
gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin=
-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"lt=
r">Hi,<br><br>W dniu poniedzia=C5=82ek, 15 lutego 2016 19:48:48 UTC+1 u=C5=
=BCytkownik Vicente J. Botet Escriba napisa=C5=82:<blockquote class=3D"gmai=
l_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;pad=
ding-left:1ex">
=20
=20
=20
<div bgcolor=3D"#FFFFFF" text=3D"#000000">
<div>Le 15/02/2016 17:19,
<a rel=3D"nofollow">m.ce...@gmail.com</a> a =C3=A9crit=C2=A0:<br>
</div>
<blockquote type=3D"cite">
<div dir=3D"ltr">Hi,
<div><br>
</div>
<div>I think the structured binding proposal opens a possibility
for major simplification of std::tuple implementation.</div>
<div><br>
</div>
<div>Let's take following "implementation" as an exam=
ple:</div>
<div>
<div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-w=
ord;background-color:rgb(250,250,250)"><code>
<div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">template</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660"><</span><span =
style=3D"color:#008">typename</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">...</span><span style=3D"color:#000">T</span><span s=
tyle=3D"color:#660">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">struct</span><span =
style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660">;</span=
></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">template</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660"><</span><span =
style=3D"color:#008">typename</span><span style=3D"color:#000"> T1</span><s=
pan style=3D"color:#660">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">struct</span><span =
style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#000">T1</span><span style=3D"color:#660">></sp=
an></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#660">{</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0
=C2=A0T1 _1</span><span style=3D"color:#660">;</span></=
div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000">=C2=A0 =C2=A0
</span><span style=3D"color:#008">template</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#660"><</span><span styl=
e=3D"color:#008">typename</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#660">...</span><span style=3D"color:#606">Args</span><span st=
yle=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">typename</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">decltype</span><span style=3D"color:#660">(</span><span sty=
le=3D"color:#000">__tuple_struct</span><span style=3D"color:#660"><</spa=
n><span style=3D"color:#606">Args</span><span style=3D"color:#660">..<wbr>.=
>{</span><span style=3D"color:#000"> _1
</span><span style=3D"color:#660">})></span><span styl=
e=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000">=C2=A0 =C2=A0
</span><span style=3D"color:#008">operator</span><span st=
yle=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#606">Args</span><span style=3D"color:#660">...>=
;()</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0</spa=
n><span style=3D"color:#660">{</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0
=C2=A0 =C2=A0</span><span style=3D"color:#008">return</=
span><span style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#606">Args</span><span style=3D"color:#660">...>=
;{</span><span style=3D"color:#000"> _1
</span><span style=3D"color:#660">};</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0</spa=
n><span style=3D"color:#660">}</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000">=C2=A0 =C2=A0
</span><span style=3D"color:#008">void</span><span style=
=3D"color:#000">
swap</span><span style=3D"color:#660">(</span><span sty=
le=3D"color:#000">__tuple_struct</span><span style=3D"color:#660">&</sp=
an><span style=3D"color:#000">
other</span><span style=3D"color:#660">);</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#660">};</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">template</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660"><</span><span =
style=3D"color:#008">typename</span><span style=3D"color:#000"> T1</span><s=
pan style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#008">typename</span><span style=3D"color:#000"> T2</span><sp=
an style=3D"color:#660">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">struct</span><span =
style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#000">T1</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> T2</span><span style=3D"color:#660">></span>=
</div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#660">{</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0
=C2=A0T1 _1</span><span style=3D"color:#660">;</span></=
div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0
=C2=A0T2 _2</span><span style=3D"color:#660">;</span></=
div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:rgb(136,0,0)"><span style=
=3D"color:#000">=C2=A0 =C2=A0</span><span style=3D"color:#008">template</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#660"><</span=
><span style=3D"color:#008">typename</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">...</span><span style=3D"color:#606">Args</sp=
an><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#008">typename</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#008">decltype</span><span style=3D"color:#660">(</span><=
span style=3D"color:#000">__tuple_struct</span><span style=3D"color:#660">&=
lt;</span><span style=3D"color:#606">Args</span><span style=3D"color:#660">=
...<wbr>.>{</span><span style=3D"color:#000">
_1</span><span style=3D"color:#660">,</span><span sty=
le=3D"color:#000">
_2 </span><span style=3D"color:#660">})></span></s=
pan><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000">=C2=A0 =C2=A0
</span><span style=3D"color:#008">operator</span><span st=
yle=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#606">Args</span><span style=3D"color:#660">...>=
;()</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0</spa=
n><span style=3D"color:#660">{</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0
=C2=A0 =C2=A0</span><span style=3D"color:#008">return</=
span><span style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#606">Args</span><span style=3D"color:#660">...>=
;{</span><span style=3D"color:#000"> _1</span><span style=3D"color:#660">,<=
/span><span style=3D"color:#000"> _2
</span><span style=3D"color:#660">};</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0</spa=
n><span style=3D"color:#660">}</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000">=C2=A0 =C2=A0
</span><span style=3D"color:#008">void</span><span style=
=3D"color:#000">
swap</span><span style=3D"color:#660">(</span><span sty=
le=3D"color:#000">__tuple_struct</span><span style=3D"color:#660">&</sp=
an><span style=3D"color:#000">
other</span><span style=3D"color:#660">);</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#660">};</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">template</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660"><</span><span =
style=3D"color:#008">typename</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">...</span><span style=3D"color:#606">Ts</span><span =
style=3D"color:#660">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">using</span><span s=
tyle=3D"color:#000">
tuple </span><span style=3D"color:#660">=3D</span><span=
style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#606">Ts</span><span style=3D"color:#660">...>;=
</span></div>
</div>
</code></div>
<br>
<br>
</div>
</div>
</blockquote>
Sorry, but I don't how structured bindings plays here.<br></div></b=
lockquote><div><br>Yeah, I should have clarified that. <br>In C++14 to prov=
ide the get<N> functionality the tuple is implemented with either mul=
tiple inheritance or recursive inheritance.<br>Structured binding allows to=
base the tuple implementation on a simple struct - get<N>() will be =
provided by language.<br><br>What is additionally needed is a way to create=
this base struct, it can be either:<br>1) compiler provided builtin templa=
te __magic_struct<Ts...> with only the data members of given types<br=
>2) new language feature to define new data members based on some template =
parameter pack.<br></div></div></blockquote><div><br>OK, I fail to see how =
this concerns the standard at all, save for in one way that I'll get to=
momentarily. Presumably, the "magic struct" won't allow you =
to access the members directly; you have to use tuple syntax (like `get<=
>`). And your implementation below shows that you still need a construct=
or, so you can't use aggregate initialization directly. And therefore..=
.. nothing changes for the user.<br><br>Which means that standard library im=
plementations of `tuple` could do this right now, today, and still be stand=
ard compliant. So if a compiler vendor wanted to create such a "magic =
struct" and have their tuple implementation use it, that's their b=
usiness.<br><br>The standard specifies behavior, <i>not</i> implementation.=
<br><br>As I pointed out earlier, there is one behavioral difference. `tupl=
e` is currently not required to be standard layout, even if the types it is=
given are. If you implemented it your way, it would be <i>able</i> to be a=
standard layout type (so long as the "magic struct" satisfies st=
andard layout rules). `tuple` is also not required to be trivially copyable=
..<br><br>This is the only behavioral difference between what you're pro=
posing and what we have now: that `tuple` could be standard layout & tr=
ivially copyable if the component types fulfill these requirements.</div><b=
r></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
------=_Part_6046_1650137706.1455573988451--
------=_Part_6045_1789201026.1455573988450--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Mon, 15 Feb 2016 14:12:54 -0800 (PST)
Raw View
------=_Part_6001_1618890528.1455574374665
Content-Type: multipart/alternative;
boundary="----=_Part_6002_1603304925.1455574374665"
------=_Part_6002_1603304925.1455574374665
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Monday, February 15, 2016 at 4:24:35 PM UTC-5, m.ce...@gmail.com wrote:
>
> Hi,
>
> W dniu poniedzia=C5=82ek, 15 lutego 2016 19:48:48 UTC+1 u=C5=BCytkownik V=
icente J.=20
> Botet Escriba napisa=C5=82:
>>
>> Le 15/02/2016 17:19, m.ce...@gmail.com a =C3=A9crit :
>>
>> Hi,=20
>>
>> I think the structured binding proposal opens a possibility for major=20
>> simplification of std::tuple implementation.
>>
>> Let's take following "implementation" as an example:
>> template <typename ...T>
>> struct __tuple_struct;
>>
>> template <typename T1>
>> struct __tuple_struct<T1>
>> {
>> T1 _1;
>>
>> template <typename ...Args, typename =3D decltype(__tuple_struct<Arg=
s
>> ...>{ _1 })>
>> operator __tuple_struct<Args...>()
>> {
>> return __tuple_struct<Args...>{ _1 };
>> }
>>
>> void swap(__tuple_struct& other);
>> };
>>
>> template <typename T1, typename T2>
>> struct __tuple_struct<T1, T2>
>> {
>> T1 _1;
>> T2 _2;
>>
>> template <typename ...Args, typename =3D decltype(__tuple_struct<Args
>> ...>{ _1, _2 })>
>> operator __tuple_struct<Args...>()
>> {
>> return __tuple_struct<Args...>{ _1, _2 };
>> }
>>
>> void swap(__tuple_struct& other);
>> };
>>
>>
>> template <typename ...Ts>
>> using tuple =3D __tuple_struct<Ts...>;
>>
>>
>> Sorry, but I don't how structured bindings plays here.
>>
>
> Yeah, I should have clarified that.=20
> In C++14 to provide the get<N> functionality the tuple is implemented wit=
h=20
> either multiple inheritance or recursive inheritance.
>
=20
One more thing: I'm pretty sure that there are ways to implement tuple that=
=20
don't use inheritance. If I recall correctly, the idea is to stick a block=
=20
of storage in the tuple. The storage's size and alignment are computed via=
=20
metaprogramming based on the typelist. `get<N>` would simply use an offset=
=20
into the storage, perform a cast on the pointer, and return it.
The computation of the offset may be *compile-time* recursion, but it=20
doesn't involve anything more than that. It should ultimately boil down to=
=20
just a number.
--=20
---=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.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-propos=
als/.
------=_Part_6002_1603304925.1455574374665
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Monday, February 15, 2016 at 4:24:35 PM UTC-5, =
m.ce...@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: =
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div d=
ir=3D"ltr">Hi,<br><br>W dniu poniedzia=C5=82ek, 15 lutego 2016 19:48:48 UTC=
+1 u=C5=BCytkownik Vicente J. Botet Escriba napisa=C5=82:<blockquote class=
=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc s=
olid;padding-left:1ex">
=20
=20
=20
<div bgcolor=3D"#FFFFFF" text=3D"#000000">
<div>Le 15/02/2016 17:19,
<a rel=3D"nofollow">m.ce...@gmail.com</a> a =C3=A9crit=C2=A0:<br>
</div>
<blockquote type=3D"cite">
<div dir=3D"ltr">Hi,
<div><br>
</div>
<div>I think the structured binding proposal opens a possibility
for major simplification of std::tuple implementation.</div>
<div><br>
</div>
<div>Let's take following "implementation" as an exam=
ple:</div>
<div>
<div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-w=
ord;background-color:rgb(250,250,250)"><code>
<div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">template</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660"><</span><span =
style=3D"color:#008">typename</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">...</span><span style=3D"color:#000">T</span><span s=
tyle=3D"color:#660">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">struct</span><span =
style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660">;</span=
></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">template</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660"><</span><span =
style=3D"color:#008">typename</span><span style=3D"color:#000"> T1</span><s=
pan style=3D"color:#660">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">struct</span><span =
style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#000">T1</span><span style=3D"color:#660">></sp=
an></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#660">{</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0
=C2=A0T1 _1</span><span style=3D"color:#660">;</span></=
div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000">=C2=A0 =C2=A0
</span><span style=3D"color:#008">template</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#660"><</span><span styl=
e=3D"color:#008">typename</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#660">...</span><span style=3D"color:#606">Args</span><span st=
yle=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">typename</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">decltype</span><span style=3D"color:#660">(</span><span sty=
le=3D"color:#000">__tuple_struct</span><span style=3D"color:#660"><</spa=
n><span style=3D"color:#606">Args</span><span style=3D"color:#660">..<wbr>.=
>{</span><span style=3D"color:#000"> _1
</span><span style=3D"color:#660">})></span><span styl=
e=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000">=C2=A0 =C2=A0
</span><span style=3D"color:#008">operator</span><span st=
yle=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#606">Args</span><span style=3D"color:#660">...>=
;()</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0</spa=
n><span style=3D"color:#660">{</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0
=C2=A0 =C2=A0</span><span style=3D"color:#008">return</=
span><span style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#606">Args</span><span style=3D"color:#660">...>=
;{</span><span style=3D"color:#000"> _1
</span><span style=3D"color:#660">};</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0</spa=
n><span style=3D"color:#660">}</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000">=C2=A0 =C2=A0
</span><span style=3D"color:#008">void</span><span style=
=3D"color:#000">
swap</span><span style=3D"color:#660">(</span><span sty=
le=3D"color:#000">__tuple_struct</span><span style=3D"color:#660">&</sp=
an><span style=3D"color:#000">
other</span><span style=3D"color:#660">);</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#660">};</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">template</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660"><</span><span =
style=3D"color:#008">typename</span><span style=3D"color:#000"> T1</span><s=
pan style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#008">typename</span><span style=3D"color:#000"> T2</span><sp=
an style=3D"color:#660">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">struct</span><span =
style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#000">T1</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> T2</span><span style=3D"color:#660">></span>=
</div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#660">{</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0
=C2=A0T1 _1</span><span style=3D"color:#660">;</span></=
div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0
=C2=A0T2 _2</span><span style=3D"color:#660">;</span></=
div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:rgb(136,0,0)"><span style=
=3D"color:#000">=C2=A0 =C2=A0</span><span style=3D"color:#008">template</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#660"><</span=
><span style=3D"color:#008">typename</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">...</span><span style=3D"color:#606">Args</sp=
an><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#008">typename</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#008">decltype</span><span style=3D"color:#660">(</span><=
span style=3D"color:#000">__tuple_struct</span><span style=3D"color:#660">&=
lt;</span><span style=3D"color:#606">Args</span><span style=3D"color:#660">=
...<wbr>.>{</span><span style=3D"color:#000">
_1</span><span style=3D"color:#660">,</span><span sty=
le=3D"color:#000">
_2 </span><span style=3D"color:#660">})></span></s=
pan><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000">=C2=A0 =C2=A0
</span><span style=3D"color:#008">operator</span><span st=
yle=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#606">Args</span><span style=3D"color:#660">...>=
;()</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0</spa=
n><span style=3D"color:#660">{</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0
=C2=A0 =C2=A0</span><span style=3D"color:#008">return</=
span><span style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#606">Args</span><span style=3D"color:#660">...>=
;{</span><span style=3D"color:#000"> _1</span><span style=3D"color:#660">,<=
/span><span style=3D"color:#000"> _2
</span><span style=3D"color:#660">};</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0</spa=
n><span style=3D"color:#660">}</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000">=C2=A0 =C2=A0
</span><span style=3D"color:#008">void</span><span style=
=3D"color:#000">
swap</span><span style=3D"color:#660">(</span><span sty=
le=3D"color:#000">__tuple_struct</span><span style=3D"color:#660">&</sp=
an><span style=3D"color:#000">
other</span><span style=3D"color:#660">);</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#660">};</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">template</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660"><</span><span =
style=3D"color:#008">typename</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">...</span><span style=3D"color:#606">Ts</span><span =
style=3D"color:#660">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">using</span><span s=
tyle=3D"color:#000">
tuple </span><span style=3D"color:#660">=3D</span><span=
style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#606">Ts</span><span style=3D"color:#660">...>;=
</span></div>
</div>
</code></div>
<br>
<br>
</div>
</div>
</blockquote>
Sorry, but I don't how structured bindings plays here.<br></div></b=
lockquote><div><br>Yeah, I should have clarified that. <br>In C++14 to prov=
ide the get<N> functionality the tuple is implemented with either mul=
tiple inheritance or recursive inheritance.<br></div></div></blockquote><di=
v>=C2=A0</div><div>One more thing: I'm pretty sure that there are ways =
to implement tuple that don't use inheritance. If I recall correctly, t=
he idea is to stick a block of storage in the tuple. The storage's size=
and alignment are computed via metaprogramming based on the typelist. `get=
<N>` would simply use an offset into the storage, perform a cast on t=
he pointer, and return it.<br><br>The computation of the offset may be <i>c=
ompile-time</i> recursion, but it doesn't involve anything more than th=
at. It should ultimately boil down to just a number.<br></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" 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"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
------=_Part_6002_1603304925.1455574374665--
------=_Part_6001_1618890528.1455574374665--
.
Author: Larry Evans <cppljevans@suddenlink.net>
Date: Mon, 15 Feb 2016 18:06:09 -0600
Raw View
On 02/15/2016 04:12 PM, Nicol Bolas wrote:
>=20
>=20
> On Monday, February 15, 2016 at 4:24:35 PM UTC-5, m.ce...@gmail.com wrote=
:
>=20
> Hi,
>=20
> W dniu poniedzia=C5=82ek, 15 lutego 2016 19:48:48 UTC+1 u=C5=BCytkown=
ik
> Vicente J. Botet Escriba napisa=C5=82:
>=20
> Le 15/02/2016 17:19, m.ce...@gmail.com a =C3=A9crit :
>> Hi,
>>
>> I think the structured binding proposal opens a possibility
>> for major simplification of std::tuple implementation.
>>
>> Let's take following "implementation" as an example:
>> |
>> template<typename...T>
>> struct__tuple_struct;
>>
>> template<typenameT1>
>> struct__tuple_struct<T1>
>> {
>> T1 _1;
>>
>> =20
>> template<typename...Args,typename=3Ddecltype(__tuple_struct<Args=
....>{_1
>> })>
>> operator__tuple_struct<Args...>()
>> {
>> return__tuple_struct<Args...>{_1 };
>> }
>>
>> voidswap(__tuple_struct&other);
>> };
>>
>> template<typenameT1,typenameT2>
>> struct__tuple_struct<T1,T2>
>> {
>> T1 _1;
>> T2 _2;
>>
>> =20
>> template<typename...Args,typename=3Ddecltype(__tuple_struct<Arg=
s...>{_1,_2
>> })>
>> operator__tuple_struct<Args...>()
>> {
>> return__tuple_struct<Args...>{_1,_2 };
>> }
>>
>> voidswap(__tuple_struct&other);
>> };
>>
>>
>> template<typename...Ts>
>> usingtuple =3D__tuple_struct<Ts...>;
>> |
>>
>>
> Sorry, but I don't how structured bindings plays here.
>=20
>=20
> Yeah, I should have clarified that.
> In C++14 to provide the get<N> functionality the tuple is
> implemented with either multiple inheritance or recursive inheritance=
..
>=20
> =20
> One more thing: I'm pretty sure that there are ways to implement tuple
> that don't use inheritance. If I recall correctly, the idea is to stick
> a block of storage in the tuple. The storage's size and alignment are
> computed via metaprogramming based on the typelist. `get<N>` would
> simply use an offset into the storage, perform a cast on the pointer,
> and return it.
>=20
> The computation of the offset may be /compile-time/ recursion, but it
> doesn't involve anything more than that. It should ultimately boil down
> to just a number.
>=20
There's an implementation of this offset computation here:
https://github.com/cppljevans/variadic_templates/blob/master/boost/composit=
e_storage/pack/container_all_of_aligned.hpp
There is an alternate implementation that avoids the recursive
templates by using constexpr function.
--=20
---=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.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-propos=
als/.
.
Author: Edward Catmur <ed@catmur.co.uk>
Date: Mon, 15 Feb 2016 16:52:30 -0800 (PST)
Raw View
------=_Part_5996_386036006.1455583951097
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Monday, 15 February 2016 22:12:55 UTC, Nicol Bolas wrote:
> On Monday, February 15, 2016 at 4:24:35 PM UTC-5, m.ce...@gmail.com wrote=
:
> Hi,
>=20
> W dniu poniedzia=C5=82ek, 15 lutego 2016 19:48:48 UTC+1 u=C5=BCytkownik V=
icente J. Botet Escriba napisa=C5=82:
> =20
> =20
> =20
> =20
>=20
> =20
> Le 15/02/2016 17:19,
> m.ce...@gmail.com a =C3=A9crit=C2=A0:
>=20
> =20
> =20
> =20
> Hi,
> =20
>=20
>=20
> =20
> =20
> I think the structured binding proposal opens a possibility
> for major simplification of std::tuple implementation.
> =20
>=20
>=20
> =20
> =20
> Let's take following "implementation" as an example:
> =20
>=20
> =20
>=20
> =20
>=20
> =20
> template <typename ...T>
> =20
> struct
> __tuple_struct;
> =20
>=20
>=20
> =20
> =20
> template <typename T1>
> =20
> struct
> __tuple_struct<T1>
> =20
> {
> =20
> =C2=A0
> =C2=A0T1 _1;
> =20
>=20
>=20
> =20
> =20
> =C2=A0 =C2=A0
> template <typename ...Args, typename =3D decltype(__tup=
le_struct<Args...>{ _1
> })>
>=20
> =20
> =20
> =C2=A0 =C2=A0
> operator
> __tuple_struct<Args...>()
> =20
> =C2=A0 =C2=A0{
> =20
> =C2=A0 =C2=A0
> =C2=A0 =C2=A0return
> __tuple_struct<Args...>{ _1
> };
> =20
> =C2=A0 =C2=A0}
> =20
>=20
>=20
> =20
> =20
> =C2=A0 =C2=A0
> void
> swap(__tuple_struct&
> other);
> =20
> };
> =20
>=20
>=20
> =20
> =20
> template <typename T1, typename T2>
> =20
> struct
> __tuple_struct<T1, T2>
> =20
> {
> =20
> =C2=A0
> =C2=A0T1 _1;
> =20
> =C2=A0
> =C2=A0T2 _2;
> =20
>=20
>=20
> =20
> =20
> =C2=A0 =C2=A0template <typename ...Args, typename =3D decltype(__tuple_st=
ruct<Args...>{
> _1,
> _2 })>
>=20
> =20
> =20
> =C2=A0 =C2=A0
> operator
> __tuple_struct<Args...>()
> =20
> =C2=A0 =C2=A0{
> =20
> =C2=A0 =C2=A0
> =C2=A0 =C2=A0return
> __tuple_struct<Args...>{ _1, _2
> };
> =20
> =C2=A0 =C2=A0}
> =20
>=20
>=20
> =20
> =20
> =C2=A0 =C2=A0
> void
> swap(__tuple_struct&
> other);
> =20
> };
> =20
>=20
>=20
> =20
> =20
>=20
>=20
> =20
> =20
> template <typename ...Ts>
> =20
> using
> tuple =3D
> __tuple_struct<Ts...>;
> =20
> =20
> =20
>=20
> =20
>=20
> =20
> =20
> =20
> Sorry, but I don't how structured bindings plays here.
>=20
>=20
> Yeah, I should have clarified that.=20
> In C++14 to provide the get<N> functionality the tuple is implemented wit=
h either multiple inheritance or recursive inheritance.
>=20
> =C2=A0
> One more thing: I'm pretty sure that there are ways to implement tuple th=
at don't use inheritance. If I recall correctly, the idea is to stick a blo=
ck of storage in the tuple. The storage's size and alignment are computed v=
ia metaprogramming based on the typelist. `get<N>` would simply use an offs=
et into the storage, perform a cast on the pointer, and return it.
Wouldn't that prevent the constructor being constexpr?=20
--=20
---=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.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-propos=
als/.
------=_Part_5996_386036006.1455583951097--
.
Author: Larry Evans <cppljevans@suddenlink.net>
Date: Mon, 15 Feb 2016 19:10:22 -0600
Raw View
On 02/15/2016 06:52 PM, Edward Catmur wrote:
> On Monday, 15 February 2016 22:12:55 UTC, Nicol Bolas wrote:
[snip]
>>
>> Yeah, I should have clarified that.=20
>> In C++14 to provide the get<N> functionality the tuple is implemented wi=
th either multiple inheritance or recursive inheritance.
>>
>> =20
>> One more thing: I'm pretty sure that there are ways to implement tuple t=
hat don't use inheritance. If I recall correctly, the idea is to stick a bl=
ock of storage in the tuple. The storage's size and alignment are computed =
via metaprogramming based on the typelist. `get<N>` would simply use an off=
set into the storage, perform a cast on the pointer, and return it.
>=20
> Wouldn't that prevent the constructor being constexpr?=20
>=20
Yes, AFAICT, and according to:
https://groups.google.com/a/isocpp.org/d/msg/std-discussion/_s7vi9pOhfY/2N4=
HAq9LkEAJ
a post with subject:
[std-discussion]why placement new not allowed in constexpr?
Too bad :(
--=20
---=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.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-propos=
als/.
.
Author: m.cencora@gmail.com
Date: Tue, 16 Feb 2016 10:29:21 -0800 (PST)
Raw View
------=_Part_7238_1659834629.1455647361991
Content-Type: multipart/alternative;
boundary="----=_Part_7239_1947635726.1455647361992"
------=_Part_7239_1947635726.1455647361992
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Hi,
Well, the standard itself could be simplified if tuple was defined as a=20
standard layout type.
Just look at the current list of possible constructors and their=20
"visibility" preconditions and recall recent changes due to not-so-perfect=
=20
forwarding.=20
Also from the beginner C++ programmer perspective it would be much clearer=
=20
to grasp it, i.e.:
tuple<T1, T2, T3, ...> is a struct { T1 <implementation-defined-name>; T2=
=20
<implementation-defined-name>; T3 <implementation-defined-name>; ... };=20
with members accessible through structured binding or get<N> and with=20
additional functionalities:
- construction with ( ) parenthesis (just to preserve backward=20
compatibility)
- convertible to compatible tuple
- swap
Regards,
Maciej
W dniu poniedzia=C5=82ek, 15 lutego 2016 23:06:28 UTC+1 u=C5=BCytkownik Nic=
ol Bolas=20
napisa=C5=82:
>
> On Monday, February 15, 2016 at 4:24:35 PM UTC-5, m.ce...@gmail.com wrote=
:
>>
>> Hi,
>>
>> W dniu poniedzia=C5=82ek, 15 lutego 2016 19:48:48 UTC+1 u=C5=BCytkownik =
Vicente J.=20
>> Botet Escriba napisa=C5=82:
>>>
>>> Le 15/02/2016 17:19, m.ce...@gmail.com a =C3=A9crit :
>>>
>>> Hi,=20
>>>
>>> I think the structured binding proposal opens a possibility for major=
=20
>>> simplification of std::tuple implementation.
>>>
>>> Let's take following "implementation" as an example:
>>> template <typename ...T>
>>> struct __tuple_struct;
>>>
>>> template <typename T1>
>>> struct __tuple_struct<T1>
>>> {
>>> T1 _1;
>>>
>>> template <typename ...Args, typename =3D decltype(__tuple_struct<Ar=
gs
>>> ...>{ _1 })>
>>> operator __tuple_struct<Args...>()
>>> {
>>> return __tuple_struct<Args...>{ _1 };
>>> }
>>>
>>> void swap(__tuple_struct& other);
>>> };
>>>
>>> template <typename T1, typename T2>
>>> struct __tuple_struct<T1, T2>
>>> {
>>> T1 _1;
>>> T2 _2;
>>>
>>> template <typename ...Args, typename =3D decltype(__tuple_struct<Arg=
s
>>> ...>{ _1, _2 })>
>>> operator __tuple_struct<Args...>()
>>> {
>>> return __tuple_struct<Args...>{ _1, _2 };
>>> }
>>>
>>> void swap(__tuple_struct& other);
>>> };
>>>
>>>
>>> template <typename ...Ts>
>>> using tuple =3D __tuple_struct<Ts...>;
>>>
>>>
>>> Sorry, but I don't how structured bindings plays here.
>>>
>>
>> Yeah, I should have clarified that.=20
>> In C++14 to provide the get<N> functionality the tuple is implemented=20
>> with either multiple inheritance or recursive inheritance.
>> Structured binding allows to base the tuple implementation on a simple=
=20
>> struct - get<N>() will be provided by language.
>>
>> What is additionally needed is a way to create this base struct, it can=
=20
>> be either:
>> 1) compiler provided builtin template __magic_struct<Ts...> with only th=
e=20
>> data members of given types
>> 2) new language feature to define new data members based on some templat=
e=20
>> parameter pack.
>>
>
> OK, I fail to see how this concerns the standard at all, save for in one=
=20
> way that I'll get to momentarily. Presumably, the "magic struct" won't=20
> allow you to access the members directly; you have to use tuple syntax=20
> (like `get<>`). And your implementation below shows that you still need a=
=20
> constructor, so you can't use aggregate initialization directly. And=20
> therefore... nothing changes for the user.
>
> Which means that standard library implementations of `tuple` could do thi=
s=20
> right now, today, and still be standard compliant. So if a compiler vendo=
r=20
> wanted to create such a "magic struct" and have their tuple implementatio=
n=20
> use it, that's their business.
>
> The standard specifies behavior, *not* implementation.
>
> As I pointed out earlier, there is one behavioral difference. `tuple` is=
=20
> currently not required to be standard layout, even if the types it is giv=
en=20
> are. If you implemented it your way, it would be *able* to be a standard=
=20
> layout type (so long as the "magic struct" satisfies standard layout=20
> rules). `tuple` is also not required to be trivially copyable.
>
> This is the only behavioral difference between what you're proposing and=
=20
> what we have now: that `tuple` could be standard layout & trivially=20
> copyable if the component types fulfill these requirements.
>
>
--=20
---=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.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-propos=
als/.
------=_Part_7239_1947635726.1455647361992
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hi,<br><br>Well, the standard itself could be simplified i=
f tuple was defined as a standard layout type.<br>Just look at the current =
list of possible constructors and their "visibility" precondition=
s and recall recent changes due to not-so-perfect forwarding. <br><br>Also =
from the beginner C++ programmer perspective it would be much clearer to gr=
asp it, i.e.:<br>tuple<T1, T2, T3, ...> is a struct { T1 <implemen=
tation-defined-name>; T2 <implementation-defined-name>; T3 <i=
mplementation-defined-name>; ... }; <br>with members accessible through =
structured binding or get<N> and with additional functionalities:<br>=
=C2=A0- construction with ( ) parenthesis (just to preserve backward compat=
ibility)<br>=C2=A0- convertible to compatible tuple<br>=C2=A0- swap<br><br>=
Regards,<br>Maciej<br><br>W dniu poniedzia=C5=82ek, 15 lutego 2016 23:06:28=
UTC+1 u=C5=BCytkownik Nicol Bolas napisa=C5=82:<blockquote class=3D"gmail_=
quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;pa=
dding-left: 1ex;"><div dir=3D"ltr">On Monday, February 15, 2016 at 4:24:35 =
PM UTC-5, <a>m.ce...@gmail.com</a> wrote:<blockquote class=3D"gmail_quote" =
style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left=
:1ex"><div dir=3D"ltr">Hi,<br><br>W dniu poniedzia=C5=82ek, 15 lutego 2016 =
19:48:48 UTC+1 u=C5=BCytkownik Vicente J. Botet Escriba napisa=C5=82:<block=
quote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left=
:1px #ccc solid;padding-left:1ex">
=20
=20
=20
<div bgcolor=3D"#FFFFFF" text=3D"#000000">
<div>Le 15/02/2016 17:19,
<a rel=3D"nofollow">m.ce...@gmail.com</a> a =C3=A9crit=C2=A0:<br>
</div>
<blockquote type=3D"cite">
<div dir=3D"ltr">Hi,
<div><br>
</div>
<div>I think the structured binding proposal opens a possibility
for major simplification of std::tuple implementation.</div>
<div><br>
</div>
<div>Let's take following "implementation" as an exam=
ple:</div>
<div>
<div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-w=
ord;background-color:rgb(250,250,250)"><code>
<div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">template</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660"><</span><span =
style=3D"color:#008">typename</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">...</span><span style=3D"color:#000">T</span><span s=
tyle=3D"color:#660">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">struct</span><span =
style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660">;</span=
></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">template</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660"><</span><span =
style=3D"color:#008">typename</span><span style=3D"color:#000"> T1</span><s=
pan style=3D"color:#660">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">struct</span><span =
style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#000">T1</span><span style=3D"color:#660">></sp=
an></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#660">{</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0
=C2=A0T1 _1</span><span style=3D"color:#660">;</span></=
div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000">=C2=A0 =C2=A0
</span><span style=3D"color:#008">template</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#660"><</span><span styl=
e=3D"color:#008">typename</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#660">...</span><span style=3D"color:#606">Args</span><span st=
yle=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">typename</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">decltype</span><span style=3D"color:#660">(</span><span sty=
le=3D"color:#000">__tuple_struct</span><span style=3D"color:#660"><</spa=
n><span style=3D"color:#606">Args</span><span style=3D"color:#660">..<wbr>.=
>{</span><span style=3D"color:#000"> _1
</span><span style=3D"color:#660">})></span><span styl=
e=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000">=C2=A0 =C2=A0
</span><span style=3D"color:#008">operator</span><span st=
yle=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#606">Args</span><span style=3D"color:#660">...>=
;()</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0</spa=
n><span style=3D"color:#660">{</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0
=C2=A0 =C2=A0</span><span style=3D"color:#008">return</=
span><span style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#606">Args</span><span style=3D"color:#660">...>=
;{</span><span style=3D"color:#000"> _1
</span><span style=3D"color:#660">};</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0</spa=
n><span style=3D"color:#660">}</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000">=C2=A0 =C2=A0
</span><span style=3D"color:#008">void</span><span style=
=3D"color:#000">
swap</span><span style=3D"color:#660">(</span><span sty=
le=3D"color:#000">__tuple_struct</span><span style=3D"color:#660">&</sp=
an><span style=3D"color:#000">
other</span><span style=3D"color:#660">);</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#660">};</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">template</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660"><</span><span =
style=3D"color:#008">typename</span><span style=3D"color:#000"> T1</span><s=
pan style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#008">typename</span><span style=3D"color:#000"> T2</span><sp=
an style=3D"color:#660">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">struct</span><span =
style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#000">T1</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> T2</span><span style=3D"color:#660">></span>=
</div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#660">{</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0
=C2=A0T1 _1</span><span style=3D"color:#660">;</span></=
div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0
=C2=A0T2 _2</span><span style=3D"color:#660">;</span></=
div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:rgb(136,0,0)"><span style=
=3D"color:#000">=C2=A0 =C2=A0</span><span style=3D"color:#008">template</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#660"><</span=
><span style=3D"color:#008">typename</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">...</span><span style=3D"color:#606">Args</sp=
an><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#008">typename</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#008">decltype</span><span style=3D"color:#660">(</span><=
span style=3D"color:#000">__tuple_struct</span><span style=3D"color:#660">&=
lt;</span><span style=3D"color:#606">Args</span><span style=3D"color:#660">=
...<wbr>.>{</span><span style=3D"color:#000">
_1</span><span style=3D"color:#660">,</span><span sty=
le=3D"color:#000">
_2 </span><span style=3D"color:#660">})></span></s=
pan><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000">=C2=A0 =C2=A0
</span><span style=3D"color:#008">operator</span><span st=
yle=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#606">Args</span><span style=3D"color:#660">...>=
;()</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0</spa=
n><span style=3D"color:#660">{</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0
=C2=A0 =C2=A0</span><span style=3D"color:#008">return</=
span><span style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#606">Args</span><span style=3D"color:#660">...>=
;{</span><span style=3D"color:#000"> _1</span><span style=3D"color:#660">,<=
/span><span style=3D"color:#000"> _2
</span><span style=3D"color:#660">};</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"> =C2=A0 =C2=A0</spa=
n><span style=3D"color:#660">}</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000">=C2=A0 =C2=A0
</span><span style=3D"color:#008">void</span><span style=
=3D"color:#000">
swap</span><span style=3D"color:#660">(</span><span sty=
le=3D"color:#000">__tuple_struct</span><span style=3D"color:#660">&</sp=
an><span style=3D"color:#000">
other</span><span style=3D"color:#660">);</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#660">};</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#000"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">template</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660"><</span><span =
style=3D"color:#008">typename</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">...</span><span style=3D"color:#606">Ts</span><span =
style=3D"color:#660">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:#008">using</span><span s=
tyle=3D"color:#000">
tuple </span><span style=3D"color:#660">=3D</span><span=
style=3D"color:#000">
__tuple_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#606">Ts</span><span style=3D"color:#660">...>;=
</span></div>
</div>
</code></div>
<br>
<br>
</div>
</div>
</blockquote>
Sorry, but I don't how structured bindings plays here.<br></div></b=
lockquote><div><br>Yeah, I should have clarified that. <br>In C++14 to prov=
ide the get<N> functionality the tuple is implemented with either mul=
tiple inheritance or recursive inheritance.<br>Structured binding allows to=
base the tuple implementation on a simple struct - get<N>() will be =
provided by language.<br><br>What is additionally needed is a way to create=
this base struct, it can be either:<br>1) compiler provided builtin templa=
te __magic_struct<Ts...> with only the data members of given types<br=
>2) new language feature to define new data members based on some template =
parameter pack.<br></div></div></blockquote><div><br>OK, I fail to see how =
this concerns the standard at all, save for in one way that I'll get to=
momentarily. Presumably, the "magic struct" won't allow you =
to access the members directly; you have to use tuple syntax (like `get<=
>`). And your implementation below shows that you still need a construct=
or, so you can't use aggregate initialization directly. And therefore..=
.. nothing changes for the user.<br><br>Which means that standard library im=
plementations of `tuple` could do this right now, today, and still be stand=
ard compliant. So if a compiler vendor wanted to create such a "magic =
struct" and have their tuple implementation use it, that's their b=
usiness.<br><br>The standard specifies behavior, <i>not</i> implementation.=
<br><br>As I pointed out earlier, there is one behavioral difference. `tupl=
e` is currently not required to be standard layout, even if the types it is=
given are. If you implemented it your way, it would be <i>able</i> to be a=
standard layout type (so long as the "magic struct" satisfies st=
andard layout rules). `tuple` is also not required to be trivially copyable=
..<br><br>This is the only behavioral difference between what you're pro=
posing and what we have now: that `tuple` could be standard layout & tr=
ivially copyable if the component types fulfill these requirements.</div><b=
r></div></blockquote></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
------=_Part_7239_1947635726.1455647361992--
------=_Part_7238_1659834629.1455647361991--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Tue, 16 Feb 2016 15:48:27 -0800 (PST)
Raw View
------=_Part_7489_1881638563.1455666507465
Content-Type: multipart/alternative;
boundary="----=_Part_7490_1477198166.1455666507465"
------=_Part_7490_1477198166.1455666507465
Content-Type: text/plain; charset=UTF-8
On Tuesday, February 16, 2016 at 1:29:22 PM UTC-5, m.ce...@gmail.com wrote:
>
> Hi,
>
> Well, the standard itself could be simplified if tuple was defined as a
> standard layout type.
> Just look at the current list of possible constructors and their
> "visibility" preconditions and recall recent changes due to not-so-perfect
> forwarding.
>
Whether it's standard layout or not has nothing to do with forwarding of
its constructors. Standard layout, as the name suggests, is about the
*layout* of its members.
Furthermore, forcing standard layout on tuples will in no way ensure that
tuples are implemented via some compiler-intrinsic.
Also from the beginner C++ programmer perspective it would be much clearer
> to grasp it, i.e.:
> tuple<T1, T2, T3, ...> is a struct { T1 <implementation-defined-name>; T2
> <implementation-defined-name>; T3 <implementation-defined-name>; ... };
> with members accessible through structured binding or get<N> and with
> additional functionalities:
> - construction with ( ) parenthesis (just to preserve backward
> compatibility)
> - convertible to compatible tuple
> - swap
>
>
Beginning C++ programmers do not know about standard layout types and
absolutely are not in a position to *care* whether their types are standard
layout. So beginning C++ programmers can be taught that a tuple works as
you describe right now: as a struct that contains those values, but you
have to use `get<N>` to access them.
As for "convertible to compatible tuple"... how do you expect that to work?
And convertibility has nothing to do with how tuples are implemented.
--
---
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 https://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_7490_1477198166.1455666507465
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, February 16, 2016 at 1:29:22 PM UTC-5, m.ce...=
@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr">Hi,<br><br>Well, the standard itself could be simplified if tuple was d=
efined as a standard layout type.<br>Just look at the current list of possi=
ble constructors and their "visibility" preconditions and recall =
recent changes due to not-so-perfect forwarding. <br></div></blockquote><di=
v><br>Whether it's standard layout or not has nothing to do with forwar=
ding of its constructors. Standard layout, as the name suggests, is about t=
he <i>layout</i> of its members.<br><br>Furthermore, forcing standard layou=
t on tuples will in no way ensure that tuples are implemented via some comp=
iler-intrinsic.<br><br></div><blockquote class=3D"gmail_quote" style=3D"mar=
gin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><=
div dir=3D"ltr">Also from the beginner C++ programmer perspective it would =
be much clearer to grasp it, i.e.:<br>tuple<T1, T2, T3, ...> is a str=
uct { T1 <implementation-defined-name>; T2 <implementation-define=
d-name>; T3 <implementation-defined-name>; ... }; <br>with member=
s accessible through structured binding or get<N> and with additional=
functionalities:<br>=C2=A0- construction with ( ) parenthesis (just to pre=
serve backward compatibility)<br>=C2=A0- convertible to compatible tuple<br=
>=C2=A0- swap<br><br></div></blockquote><div><br>Beginning C++ programmers =
do not know about standard layout types and absolutely are not in a positio=
n to <i>care</i> whether their types are standard layout. So beginning C++ =
programmers can be taught that a tuple works as you describe right now: as =
a struct that contains those values, but you have to use `get<N>` to =
access them.<br><br>As for "convertible to compatible tuple"... h=
ow do you expect that to work? And convertibility has nothing to do with ho=
w tuples are implemented.</div><br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
------=_Part_7490_1477198166.1455666507465--
------=_Part_7489_1881638563.1455666507465--
.
Author: m.cencora@gmail.com
Date: Fri, 19 Feb 2016 02:50:32 -0800 (PST)
Raw View
------=_Part_2603_1547902565.1455879032925
Content-Type: multipart/alternative;
boundary="----=_Part_2604_1120358681.1455879032934"
------=_Part_2604_1120358681.1455879032934
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
W dniu =C5=9Broda, 17 lutego 2016 00:48:27 UTC+1 u=C5=BCytkownik Nicol Bola=
s napisa=C5=82:
>
> On Tuesday, February 16, 2016 at 1:29:22 PM UTC-5, m.ce...@gmail.com=20
> wrote:
>>
>> Hi,
>>
>> Well, the standard itself could be simplified if tuple was defined as a=
=20
>> standard layout type.
>> Just look at the current list of possible constructors and their=20
>> "visibility" preconditions and recall recent changes due to not-so-perfe=
ct=20
>> forwarding.=20
>>
>
> Whether it's standard layout or not has nothing to do with forwarding of=
=20
> its constructors. Standard layout, as the name suggests, is about the=20
> *layout* of its members.
>
Sorry I meant a simple aggregate type (all public fields, no virtual=20
members, no virtual bases).
> Furthermore, forcing standard layout on tuples will in no way ensure that=
=20
> tuples are implemented via some compiler-intrinsic.
>
> Also from the beginner C++ programmer perspective it would be much cleare=
r=20
>> to grasp it, i.e.:
>> tuple<T1, T2, T3, ...> is a struct { T1 <implementation-defined-name>; T=
2=20
>> <implementation-defined-name>; T3 <implementation-defined-name>; ... };=
=20
>> with members accessible through structured binding or get<N> and with=20
>> additional functionalities:
>> - construction with ( ) parenthesis (just to preserve backward=20
>> compatibility)
>> - convertible to compatible tuple
>> - swap
>>
>>
> Beginning C++ programmers do not know about standard layout types and=20
> absolutely are not in a position to *care* whether their types are=20
> standard layout. So beginning C++ programmers can be taught that a tuple=
=20
> works as you describe right now: as a struct that contains those values,=
=20
> but you have to use `get<N>` to access them.
>
> As for "convertible to compatible tuple"... how do you expect that to=20
> work? And convertibility has nothing to do with how tuples are implemente=
d.
>
>
Novice C++ programmers understand what a struct is, and that's what I=20
propose for the tuple to be. Currently tuple tries to emulate struct=20
behavior, but there are subtle differences.
The convertibility is nothing new, it is already there since C++11,=20
provided as convertible copy/move constructors.
With P0222R0 by Matthew Woehlke std::tuple could be an alias to such an=20
anonymous struct.
--=20
---=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.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-propos=
als/.
------=_Part_2604_1120358681.1455879032934
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br>W dniu =C5=9Broda, 17 lutego 2016 00:48:27 UTC+1 u=C5=
=BCytkownik Nicol Bolas napisa=C5=82:<blockquote class=3D"gmail_quote" styl=
e=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left:=
1ex;"><div dir=3D"ltr">On Tuesday, February 16, 2016 at 1:29:22 PM UTC-5, =
<a>m.ce...@gmail.com</a> wrote:<blockquote class=3D"gmail_quote" style=3D"m=
argin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div=
dir=3D"ltr">Hi,<br><br>Well, the standard itself could be simplified if tu=
ple was defined as a standard layout type.<br>Just look at the current list=
of possible constructors and their "visibility" preconditions an=
d recall recent changes due to not-so-perfect forwarding. <br></div></block=
quote><div><br>Whether it's standard layout or not has nothing to do wi=
th forwarding of its constructors. Standard layout, as the name suggests, i=
s about the <i>layout</i> of its members.<br></div></div></blockquote><div>=
<br></div><div>Sorry I meant a simple aggregate type (all public fields, no=
virtual members, no virtual bases).</div><div><br></div><blockquote class=
=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #cc=
c solid;padding-left: 1ex;"><div dir=3D"ltr"><div><br>Furthermore, forcing =
standard layout on tuples will in no way ensure that tuples are implemented=
via some compiler-intrinsic.<br><br></div><blockquote class=3D"gmail_quote=
" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-le=
ft:1ex"><div dir=3D"ltr">Also from the beginner C++ programmer perspective =
it would be much clearer to grasp it, i.e.:<br>tuple<T1, T2, T3, ...>=
is a struct { T1 <implementation-defined-name>; T2 <implementati=
on-defined-name>; T3 <implementation-defined-name>; ... }; <br>wi=
th members accessible through structured binding or get<N> and with a=
dditional functionalities:<br>=C2=A0- construction with ( ) parenthesis (ju=
st to preserve backward compatibility)<br>=C2=A0- convertible to compatible=
tuple<br>=C2=A0- swap<br><br></div></blockquote><div><br>Beginning C++ pro=
grammers do not know about standard layout types and absolutely are not in =
a position to <i>care</i> whether their types are standard layout. So begin=
ning C++ programmers can be taught that a tuple works as you describe right=
now: as a struct that contains those values, but you have to use `get<N=
>` to access them.<br><br>As for "convertible to compatible tuple&q=
uot;... how do you expect that to work? And convertibility has nothing to d=
o with how tuples are implemented.</div><br></div></blockquote><div><br></d=
iv><div>Novice C++ programmers understand what a struct is, and that's =
what I propose for the tuple to be. Currently tuple tries to emulate struct=
behavior, but there are subtle differences.</div><div><br></div><div>The c=
onvertibility is nothing new, it is already there since C++11, provided as =
convertible copy/move constructors.</div><div><br></div><div>With P0222R0 b=
y=C2=A0Matthew Woehlke std::tuple could be an alias to such an anonymous st=
ruct.</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" 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"https://groups.google.com/a/isocpp.org/group=
/std-proposals/">https://groups.google.com/a/isocpp.org/group/std-proposals=
/</a>.<br />
------=_Part_2604_1120358681.1455879032934--
------=_Part_2603_1547902565.1455879032925--
.
Author: Matthew Woehlke <mwoehlke.floss@gmail.com>
Date: Fri, 19 Feb 2016 10:45:09 -0500
Raw View
On 2016-02-19 05:50, m.cencora@gmail.com wrote:
> Novice C++ programmers understand what a struct is, and that's what I
> propose for the tuple to be. Currently tuple tries to emulate struct
> behavior, but there are subtle differences.
>
> The convertibility is nothing new, it is already there since C++11,
> provided as convertible copy/move constructors.
>
> With P0222R0 by Matthew Woehlke std::tuple could be an alias to such an
> anonymous struct.
If it's aliased, it's no longer anonymous, now is it? :-) (Also, I don't
think P0222 would affect this. You can already alias an anonymous
struct. The only change made by P0222 is to allow defining an anonymous
- or not anonymous, for that matter - struct as a return value.)
--
Matthew
--
---
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 https://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: m.cencora@gmail.com
Date: Tue, 15 Mar 2016 03:09:39 -0700 (PDT)
Raw View
------=_Part_5323_860618060.1458036579156
Content-Type: multipart/alternative;
boundary="----=_Part_5324_1486096034.1458036579156"
------=_Part_5324_1486096034.1458036579156
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
So in general, what do you guys think? Is it worth pursuing this idea any=
=20
further?
To sum up advantages of introducing this into the standard:
- simpler implementation,
- simpler specification (including for upcoming structured binding and=20
default tuple like access features - i.e. tuple won't be a special case=20
anymore),
- improved compilation time (at least compared to current recursive=20
inheritance implementations),
- trivially copyable (if all elements are) to ease serialization,
- if we get new language features for user defined types (similar to=20
default comparison) tuple will get it too for free.
- (minor) defined order of member initialization.
IMHO with this proposal tuple will more feel like a natural extension to=20
aggregate, instead of class with special behavior for get<I>, structured=20
binding and other features.
Regards,
Maciej
W dniu pi=C4=85tek, 19 lutego 2016 16:45:25 UTC+1 u=C5=BCytkownik Matthew W=
oehlke=20
napisa=C5=82:
>
> On 2016-02-19 05:50, m.ce...@gmail.com <javascript:> wrote:=20
> > Novice C++ programmers understand what a struct is, and that's what I=
=20
> > propose for the tuple to be. Currently tuple tries to emulate struct=20
> > behavior, but there are subtle differences.=20
> >=20
> > The convertibility is nothing new, it is already there since C++11,=20
> > provided as convertible copy/move constructors.=20
> >=20
> > With P0222R0 by Matthew Woehlke std::tuple could be an alias to such an=
=20
> > anonymous struct.=20
>
> If it's aliased, it's no longer anonymous, now is it? :-) (Also, I don't=
=20
> think P0222 would affect this. You can already alias an anonymous=20
> struct. The only change made by P0222 is to allow defining an anonymous=
=20
> - or not anonymous, for that matter - struct as a return value.)=20
>
> --=20
> Matthew=20
>
>
--=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/2c4c76a0-ac53-4908-9fba-b5ce405d2676%40isocpp.or=
g.
------=_Part_5324_1486096034.1458036579156
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>So in general, what do you guys think? Is it worth pu=
rsuing this idea any further?</div><div><br></div>To sum up advantages of i=
ntroducing this into the standard:<div><div>- simpler implementation,</div>=
<div>- simpler specification (including for upcoming structured binding and=
default tuple like access features - i.e. tuple won't be a special cas=
e anymore),<br></div><div>- improved compilation time (at least compared to=
current recursive inheritance implementations),</div><div>- trivially copy=
able (if all elements are) to ease serialization,</div><div>- if we get new=
language features for user defined types (similar to default comparison) t=
uple will get it too for free.</div><div>- (minor) defined order of member =
initialization.</div><div><br></div><div>IMHO with this proposal tuple will=
more feel like a natural extension to aggregate, instead of class with spe=
cial behavior for get<I>, structured binding and other features.</div=
><div><br></div><div>Regards,</div><div>Maciej<br><div><br><br>W dniu pi=C4=
=85tek, 19 lutego 2016 16:45:25 UTC+1 u=C5=BCytkownik Matthew Woehlke napis=
a=C5=82:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0=
..8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 2016-02-19 05:50, <=
a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"Mqa9nYfHA=
AAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:';retu=
rn true;" onclick=3D"this.href=3D'javascript:';return true;">m.ce..=
..@gmail.com</a> wrote:
<br>> Novice C++ programmers understand what a struct is, and that's=
what I=20
<br>> propose for the tuple to be. Currently tuple tries to emulate stru=
ct=20
<br>> behavior, but there are subtle differences.
<br>>=20
<br>> The convertibility is nothing new, it is already there since C++11=
,=20
<br>> provided as convertible copy/move constructors.
<br>>=20
<br>> With P0222R0 by Matthew Woehlke std::tuple could be an alias to su=
ch an=20
<br>> anonymous struct.
<br>
<br>If it's aliased, it's no longer anonymous, now is it? :-) (Also=
, I don't
<br>think P0222 would affect this. You can already alias an anonymous
<br>struct. The only change made by P0222 is to allow defining an anonymous
<br>- or not anonymous, for that matter - struct as a return value.)
<br>
<br>--=20
<br>Matthew
<br>
<br></blockquote></div></div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/2c4c76a0-ac53-4908-9fba-b5ce405d2676%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/2c4c76a0-ac53-4908-9fba-b5ce405d2676=
%40isocpp.org</a>.<br />
------=_Part_5324_1486096034.1458036579156--
------=_Part_5323_860618060.1458036579156--
.
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Wed, 16 Mar 2016 09:07:13 +0100
Raw View
Le 15/03/2016 11:09, m.cencora@gmail.com a =C3=A9crit :
> So in general, what do you guys think? Is it worth pursuing this idea=20
> any further?
>
> To sum up advantages of introducing this into the standard:
> - simpler implementation,
> - simpler specification (including for upcoming structured binding and=20
> default tuple like access features - i.e. tuple won't be a special=20
> case anymore),
> - improved compilation time (at least compared to current recursive=20
> inheritance implementations),
> - trivially copyable (if all elements are) to ease serialization,
> - if we get new language features for user defined types (similar to=20
> default comparison) tuple will get it too for free.
> - (minor) defined order of member initialization.
>
> IMHO with this proposal tuple will more feel like a natural extension=20
> to aggregate, instead of class with special behavior for get<I>,=20
> structured binding and other features.
>
>
Hi,
I'm not sure you have take in account the comments people did in this=20
thread.
I agree there is something to do to simplify the definition of simple=20
regular classes.
I don't think the approach you are proposing is good enough. I have the=20
impression that you want to define some magic classes that could=20
simplify and could improve the performances of some implementation.=20
Don't forget that you will need to specify these magic classes.
Vicente
--=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/56E91431.5000500%40wanadoo.fr.
.
Author: m.cencora@gmail.com
Date: Wed, 16 Mar 2016 05:07:16 -0700 (PDT)
Raw View
------=_Part_134_983348439.1458130037068
Content-Type: multipart/alternative;
boundary="----=_Part_135_2040466293.1458130037069"
------=_Part_135_2040466293.1458130037069
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
I may have not been clear enough one more time.=20
I've changed the initial proposal due to need to support construction with=
=20
parenthesis (to stay backward compatible), so now the "magic" class is much=
=20
simpler - just a compiler provided template aggregate something along the=
=20
lines:
template <typename ...T>
struct __magic_struct
{
static_assert(sizeof...(T) =3D=3D 0, "");
}; // empty pack
template <typename T0>
struct __magic_struct<T0>
{
T0 _0;
};
template <typename T0, typename T1>
struct __magic_struct<T0, T1>
{
T0 _0;
T1 _1;
};
template <typename T0, typename T1, typename T2>
struct __magic_struct<T0, T1, T2>
{
T0 _0;
T1 _1;
T2 _2;
};
....
so its specification should be rather simple.
We could even get a standard type alias for this in the library:
template <typename ...Ts>
using tuple_struct =3D <implementation_defined>; // __magic_struct<Ts...> i=
n=20
this case
The rest would be implemented in the tuple<typename ...T> itself.
I've improved my implementation - https://ideone.com/Tfk3Ce . Hopefully the=
=20
code speaks for itself and explains better my idea.
This already supports everything C++17 tuple has except for:
- integration with pair,
- swap,
- allocator constructors,
- comparison operators (would be automatically provided by P0221)
Missing features are easy to implement with this aproach.
Implementation will be even simpler with P0197 (default tuple-like access).
Regards,
Maciej
W dniu =C5=9Broda, 16 marca 2016 09:07:16 UTC+1 u=C5=BCytkownik Vicente J. =
Botet=20
Escriba napisa=C5=82:
>
> Le 15/03/2016 11:09, m.ce...@gmail.com <javascript:> a =C3=A9crit :=20
> > So in general, what do you guys think? Is it worth pursuing this idea=
=20
> > any further?=20
> >=20
> > To sum up advantages of introducing this into the standard:=20
> > - simpler implementation,=20
> > - simpler specification (including for upcoming structured binding and=
=20
> > default tuple like access features - i.e. tuple won't be a special=20
> > case anymore),=20
> > - improved compilation time (at least compared to current recursive=20
> > inheritance implementations),=20
> > - trivially copyable (if all elements are) to ease serialization,=20
> > - if we get new language features for user defined types (similar to=20
> > default comparison) tuple will get it too for free.=20
> > - (minor) defined order of member initialization.=20
> >=20
> > IMHO with this proposal tuple will more feel like a natural extension=
=20
> > to aggregate, instead of class with special behavior for get<I>,=20
> > structured binding and other features.=20
> >=20
> >=20
> Hi,=20
>
> I'm not sure you have take in account the comments people did in this=20
> thread.=20
>
> I agree there is something to do to simplify the definition of simple=20
> regular classes.=20
>
> I don't think the approach you are proposing is good enough. I have the=
=20
> impression that you want to define some magic classes that could=20
> simplify and could improve the performances of some implementation.=20
> Don't forget that you will need to specify these magic classes.=20
>
>
>
> Vicente=20
>
--=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/3aa91a5d-47e7-4c2c-9d2f-339f5a242af8%40isocpp.or=
g.
------=_Part_135_2040466293.1458130037069
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I may have not been clear enough one more time.=C2=A0<div>=
I've changed the initial proposal due to need to support construction w=
ith parenthesis (to stay backward compatible), so now the "magic"=
class is much simpler - just a compiler provided template aggregate someth=
ing along the lines:<div><div class=3D"prettyprint" style=3D"border: 1px so=
lid rgb(187, 187, 187); word-wrap: break-word; background-color: rgb(250, 2=
50, 250);"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span =
style=3D"color: #008;" class=3D"styled-by-prettify">template</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">typename</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"sty=
led-by-prettify">T</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">></span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">stru=
ct</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> __magic=
_struct<br></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">=
static_assert</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">sizeof=
</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 st=
yle=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">=3D=3D</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"s=
tyled-by-prettify">0</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: #080;" class=3D"styled-by-prettify">"&q=
uot;</span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><sp=
an 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=
: #800;" class=3D"styled-by-prettify">// empty pack</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">template</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify"><</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> T0</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">></span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">struct</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> __magic_struct</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify"><</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
T0</span><span style=3D"color: #660;" class=3D"styled-by-prettify">></sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><sp=
an 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 T0 _0</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color:=
#008;" class=3D"styled-by-prettify">template</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify"><</span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">typename</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> T0</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: #008;" class=3D"styled-by-prettify">typenam=
e</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T1</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: #008;" class=3D"styled-by-prettify">struct</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> __magic_struct</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">T0</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> T1</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">></span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br></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 T0 _0</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 T1 _1</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br></span><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 style=3D"color: #008;" class=3D"styled-by-prettify">template</s=
pan><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: #008;" class=3D"styled-by-prettify">typename</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> T0</span><span style=3D"col=
or: #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"styled-by-prettify"> T1</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">t=
ypename</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T2=
</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: #008;" class=3D"styled-by-prettify">struct</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> __magic_struct</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">T0</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> T1</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> T2</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">></span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =
=C2=A0 T0 _0</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 T1 _1</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 T2 _2</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">};</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">...</span></div></c=
ode></div><div style=3D"font-family: Arial, Helvetica, sans-serif; backgrou=
nd-color: rgb(255, 255, 255);"><br></div>so its specification should be rat=
her simple.</div><div>We could even get a standard type alias for this in t=
he library:</div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(=
187, 187, 187); word-wrap: break-word; background-color: rgb(250, 250, 250)=
;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D=
"color: #008;" class=3D"styled-by-prettify">template</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify"><</span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">...</span><span style=3D"color: #606;" class=3D"styled-by-p=
rettify">Ts</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: #008;" class=3D"styled-by-prettify">using</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> tuple_struct </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #080;" class=3D"styled-by-prettify"><implementation_defined&g=
t;</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #800;" class=3D"styled-by-prettify">// __magic_struct<Ts...=
> in this case</span></div></code></div><div><br></div><div>The rest wou=
ld be implemented in the tuple<typename ...T> itself.<br></div><div><=
br></div><div>I've improved my implementation - https://ideone.com/Tfk3=
Ce . Hopefully the code speaks for itself and explains better my idea.<br>T=
his already supports everything C++17 tuple has except for:</div><div>=C2=
=A0- integration with pair,<br></div><div>=C2=A0- swap,</div><div>=C2=A0- a=
llocator constructors,</div><div>=C2=A0- comparison operators (would be aut=
omatically provided by P0221)</div><div>Missing features are easy to implem=
ent with this aproach.</div><div><br></div><div>Implementation will be even=
simpler with P0197 (default tuple-like access).</div><div><br></div><div>R=
egards,</div><div>Maciej<br><div><div><br></div><br>W dniu =C5=9Broda, 16 m=
arca 2016 09:07:16 UTC+1 u=C5=BCytkownik Vicente J. Botet Escriba napisa=C5=
=82:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex=
;border-left: 1px #ccc solid;padding-left: 1ex;">Le 15/03/2016 11:09, <a hr=
ef=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"ioAOEZ6pCAAJ"=
rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:';return t=
rue;" onclick=3D"this.href=3D'javascript:';return true;">m.ce...@gm=
ail.com</a> a =C3=A9crit :
<br>> So in general, what do you guys think? Is it worth pursuing this i=
dea=20
<br>> any further?
<br>>
<br>> To sum up advantages of introducing this into the standard:
<br>> - simpler implementation,
<br>> - simpler specification (including for upcoming structured binding=
and=20
<br>> default tuple like access features - i.e. tuple won't be a spe=
cial=20
<br>> case anymore),
<br>> - improved compilation time (at least compared to current recursiv=
e=20
<br>> inheritance implementations),
<br>> - trivially copyable (if all elements are) to ease serialization,
<br>> - if we get new language features for user defined types (similar =
to=20
<br>> default comparison) tuple will get it too for free.
<br>> - (minor) defined order of member initialization.
<br>>
<br>> IMHO with this proposal tuple will more feel like a natural extens=
ion=20
<br>> to aggregate, instead of class with special behavior for get<I&=
gt;,=20
<br>> structured binding and other features.
<br>>
<br>>
<br>Hi,
<br>
<br>I'm not sure you have take in account the comments people did in th=
is=20
<br>thread.
<br>
<br>I agree there is something to do to simplify the definition of simple=
=20
<br>regular classes.
<br>
<br>I don't think the approach you are proposing is good enough. I have=
the=20
<br>impression that you want to define some magic classes that could=20
<br>simplify and could improve the performances of some implementation.=20
<br>Don't forget that you will need to specify these magic classes.
<br>
<br>
<br>
<br>Vicente
<br></blockquote></div></div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/3aa91a5d-47e7-4c2c-9d2f-339f5a242af8%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/3aa91a5d-47e7-4c2c-9d2f-339f5a242af8=
%40isocpp.org</a>.<br />
------=_Part_135_2040466293.1458130037069--
------=_Part_134_983348439.1458130037068--
.
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Fri, 18 Mar 2016 08:50:56 +0100
Raw View
This is a multi-part message in MIME format.
--------------040108000106000304000808
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Le 16/03/2016 13:07, m.cencora@gmail.com a =C3=A9crit :
> I may have not been clear enough one more time.
> I've changed the initial proposal due to need to support construction=20
> with parenthesis (to stay backward compatible), so now the "magic"=20
> class is much simpler - just a compiler provided template aggregate=20
> something along the lines:
> |
> template<typename...T>
> struct__magic_struct
> {
> static_assert(sizeof...(T)=3D=3D0,"");
> };// empty pack
>
> template<typenameT0>
> struct__magic_struct<T0>
> {
> T0 _0;
> };
>
> template<typenameT0,typenameT1>
> struct__magic_struct<T0,T1>
> {
> T0 _0;
> T1 _1;
> };
>
> template<typenameT0,typenameT1,typenameT2>
> struct__magic_struct<T0,T1,T2>
> {
> T0 _0;
> T1 _1;
> T2 _2;
> };
> ...
> |
>
> so its specification should be rather simple.
Who could use this magic struct?
> We could even get a standard type alias for this in the library:
> |
> template<typename...Ts>
> usingtuple_struct =3D<implementation_defined>;// __magic_struct<Ts...>=20
> in this case
> |
>
> The rest would be implemented in the tuple<typename ...T> itself.
>
Instead of implementing operator conversion to another tuple, I believe=20
that what we need is conversion from any Tuple-like type.
P0197 proposes that the compiler can generate them, but after some=20
thought this can be relaxed and it will be simple to implement them in=20
tuple and pair. After all it will be implemented only once.
> I've improved my implementation - https://ideone.com/Tfk3Ce .=20
> Hopefully the code speaks for itself and explains better my idea.
> This already supports everything C++17 tuple has except for:
> - integration with pair,
See above.
> - swap,
P0198
> - allocator constructors,
> - comparison operators (would be automatically provided by P0221)
> Missing features are easy to implement with this aproach.
>
Hash on tuples doesn't exist yet, PO198 proposes as well the generation=20
under some conditions.
> Implementation will be even simpler with P0197 (default tuple-like=20
> access).
>
If I resume, your proposal would make the implementation of tuple=20
simpler, but if there are no more classes that use this __magic_struct=20
the gain is minor.
However the __magic_struct could be more important as a QOI IF the=20
compile performances are improved.
It would be worth doing a benchmark comparing a recursive implementation=20
that preserves the order and the hard-coded you proposes.
Vicente
--=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/56EBB360.9050400%40wanadoo.fr.
--------------040108000106000304000808
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
</head>
<body text=3D"#000000" bgcolor=3D"#FFFFFF">
<div class=3D"moz-cite-prefix">Le 16/03/2016 13:07,
<a class=3D"moz-txt-link-abbreviated" href=3D"mailto:m.cencora@gmail.=
com">m.cencora@gmail.com</a> a =C3=A9crit=C2=A0:<br>
</div>
<blockquote
cite=3D"mid:3aa91a5d-47e7-4c2c-9d2f-339f5a242af8@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">I may have not been clear enough one more time.=C2=
=A0
<div>I've changed the initial proposal due to need to support
construction with parenthesis (to stay backward compatible),
so now the "magic" class is much simpler - just a compiler
provided template aggregate something along the lines:
<div>
<div class=3D"prettyprint" style=3D"border: 1px solid rgb(187,
187, 187); word-wrap: break-word; background-color:
rgb(250, 250, 250);"><code class=3D"prettyprint">
<div class=3D"subprettyprint"><span style=3D"color: #008;"
class=3D"styled-by-prettify">template</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: #008;" class=3D"styled-by-prettify">typ=
ename</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">T</=
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: #008;"
class=3D"styled-by-prettify">struct</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
__magic_struct<br>
</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">static_assert</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">(</=
span><span
style=3D"color: #008;" class=3D"styled-by-prettify">siz=
eof</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;" 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">=3D=
=3D</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span
style=3D"color: #066;" class=3D"styled-by-prettify">0</=
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: #080;" 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"> </=
span><span
style=3D"color: #800;" class=3D"styled-by-prettify">//
empty pack</span><span style=3D"color: #000;"
class=3D"styled-by-prettify"><br>
<br>
</span><span style=3D"color: #008;"
class=3D"styled-by-prettify">template</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: #008;" class=3D"styled-by-prettify">typ=
ename</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> T0=
</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: #008;"
class=3D"styled-by-prettify">struct</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
__magic_struct</span><span style=3D"color: #660;"
class=3D"styled-by-prettify"><</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">T0<=
/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=
>
=C2=A0 =C2=A0 T0 _0</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=
>
<br>
</span><span style=3D"color: #008;"
class=3D"styled-by-prettify">template</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: #008;" class=3D"styled-by-prettify">typ=
ename</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> T0=
</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: #008;" class=3D"styled-by-prettify">typ=
ename</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> T1=
</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: #008;"
class=3D"styled-by-prettify">struct</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
__magic_struct</span><span style=3D"color: #660;"
class=3D"styled-by-prettify"><</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">T0<=
/span><span
style=3D"color: #660;" class=3D"styled-by-prettify">,</=
span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> T1=
</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=
>
=C2=A0 =C2=A0 T0 _0</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 T1 _1</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=
>
<br>
</span><span style=3D"color: #008;"
class=3D"styled-by-prettify">template</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: #008;" class=3D"styled-by-prettify">typ=
ename</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> T0=
</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: #008;" class=3D"styled-by-prettify">typ=
ename</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> T1=
</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: #008;" class=3D"styled-by-prettify">typ=
ename</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> T2=
</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: #008;"
class=3D"styled-by-prettify">struct</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
__magic_struct</span><span style=3D"color: #660;"
class=3D"styled-by-prettify"><</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">T0<=
/span><span
style=3D"color: #660;" class=3D"styled-by-prettify">,</=
span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> T1=
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">,</=
span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> T2=
</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=
>
=C2=A0 =C2=A0 T0 _0</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 T1 _1</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 T2 _2</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><span style=3D"color: #660;"
class=3D"styled-by-prettify">...</span></div>
</code></div>
<div style=3D"font-family: Arial, Helvetica, sans-serif;
background-color: rgb(255, 255, 255);"><br>
</div>
so its specification should be rather simple.</div>
</div>
</div>
</blockquote>
Who could use this magic struct?<br>
<br>
<br>
<blockquote
cite=3D"mid:3aa91a5d-47e7-4c2c-9d2f-339f5a242af8@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">
<div>
<div>We could even get a standard type alias for this in the
library:</div>
<div class=3D"prettyprint" style=3D"border: 1px solid rgb(187,
187, 187); word-wrap: break-word; background-color: rgb(250,
250, 250);"><code class=3D"prettyprint">
<div class=3D"subprettyprint"><span style=3D"color: #008;"
class=3D"styled-by-prettify">template</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
style=3D"color: #660;" class=3D"styled-by-prettify"><<=
/span><span
style=3D"color: #008;" class=3D"styled-by-prettify">typen=
ame</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
style=3D"color: #660;" class=3D"styled-by-prettify">...</=
span><span
style=3D"color: #606;" class=3D"styled-by-prettify">Ts</s=
pan><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: #008;"
class=3D"styled-by-prettify">using</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
tuple_struct </span><span style=3D"color: #660;"
class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or:
#000;" class=3D"styled-by-prettify"> </span><span
style=3D"color: #080;" class=3D"styled-by-prettify"><i=
mplementation_defined></span><span
style=3D"color: #660;" class=3D"styled-by-prettify">;</sp=
an><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span
style=3D"color: #800;" class=3D"styled-by-prettify">//
__magic_struct<Ts...> in this case</span></div>
</code></div>
<div><br>
</div>
<div>The rest would be implemented in the tuple<typename
...T> itself.<br>
</div>
<div><br>
</div>
</div>
</div>
</blockquote>
Instead of implementing operator conversion to another tuple, I
believe that what we need is conversion from any Tuple-like type. <br>
P0197 proposes that the compiler can generate them, but after some
thought this can be relaxed and it will be simple to implement them
in tuple and pair. After all it will be implemented only once.<br>
<blockquote
cite=3D"mid:3aa91a5d-47e7-4c2c-9d2f-339f5a242af8@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">
<div>
<div>I've improved my implementation -
<a class=3D"moz-txt-link-freetext" href=3D"https://ideone.com/T=
fk3Ce">https://ideone.com/Tfk3Ce</a> . Hopefully the code speaks for
itself and explains better my idea.<br>
This already supports everything C++17 tuple has except for:</d=
iv>
<div>=C2=A0- integration with pair, <br>
</div>
</div>
</div>
</blockquote>
See above.<br>
<blockquote
cite=3D"mid:3aa91a5d-47e7-4c2c-9d2f-339f5a242af8@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">
<div>
<div>=C2=A0- swap,</div>
</div>
</div>
</blockquote>
P0198<br>
<blockquote
cite=3D"mid:3aa91a5d-47e7-4c2c-9d2f-339f5a242af8@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">
<div>
<div>=C2=A0- allocator constructors,</div>
<div>=C2=A0- comparison operators (would be automatically provide=
d
by P0221)</div>
<div>Missing features are easy to implement with this aproach.</d=
iv>
<div><br>
</div>
</div>
</div>
</blockquote>
Hash on tuples doesn't exist yet, PO198 proposes as well the
generation under some conditions. <br>
<blockquote
cite=3D"mid:3aa91a5d-47e7-4c2c-9d2f-339f5a242af8@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">
<div>
<div>Implementation will be even simpler with P0197 (default
tuple-like access).</div>
<div><br>
</div>
</div>
</div>
</blockquote>
If I resume, your proposal would make the implementation of tuple
simpler, but if there are no more classes that use this
__magic_struct the gain is minor.<br>
However the __magic_struct could be more important as a QOI IF the
compile performances are improved.<br>
<br>
It would be worth doing a benchmark comparing a recursive
implementation that preserves the order and the hard-coded you
proposes.<br>
<br>
Vicente<br>
</body>
</html>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/56EBB360.9050400%40wanadoo.fr?utm_med=
ium=3Demail&utm_source=3Dfooter">https://groups.google.com/a/isocpp.org/d/m=
sgid/std-proposals/56EBB360.9050400%40wanadoo.fr</a>.<br />
--------------040108000106000304000808--
.
Author: m.cencora@gmail.com
Date: Fri, 1 Apr 2016 08:42:35 -0700 (PDT)
Raw View
------=_Part_608_231674555.1459525355185
Content-Type: multipart/alternative;
boundary="----=_Part_609_1725393213.1459525355186"
------=_Part_609_1725393213.1459525355186
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
For now the only use case for__magic_struct that I can think of is the=20
tuple, but if this proposal goes to standard than anyway this will have to=
=20
be specified (as part of tuple).
So additional cost of standardizing the __magic_struct comes down to giving=
=20
it a name.
....
For starters I compared compilation time for the simple code in main() from=
=20
previous post (https://ideone.com/Tfk3Ce)
I compared gcc-6 own std::tuple and my version (with __magic_struct=20
template pregenerated for up to 50 parameters).
I've performed around 10 runs for each version, and results are pretty=20
consistent.
There is always ~150-200ms improvement in total compilation time in favor=
=20
of __magic_struct version,
and most of this improvement can be attributed to reduction of template=20
instantation time:
excerpt of -ftime-report gcc-6:
template instantiation : 0.09 (50%) usr 0.69 (33%) sys 0.80 (35%)=20
wall 50660 kB (58%) ggc
TOTAL : 0.18 2.08 2.26 =
=20
87351 kB
excerpt of -ftime-report __magic_struct:
template instantiation : 0.05 (33%) usr 0.40 (21%) sys 0.48 (23%)=20
wall 30762 kB (42%) ggc
TOTAL : 0.15 1.92 2.08 =
=20
73944 kB
I'd love to perform tests on real code that makes heavy use of tuples, but=
=20
I don't have access to such code anymore.
Any suggestions for such a freely available code? (e.g. an open source=20
project with UTs relaying on google mock).
I'll try to perform the tests for clang-3.8
Regards,
Maciej
W dniu pi=C4=85tek, 18 marca 2016 08:50:59 UTC+1 u=C5=BCytkownik Vicente J.=
Botet=20
Escriba napisa=C5=82:
>
> Le 16/03/2016 13:07, m.ce...@gmail.com <javascript:> a =C3=A9crit :
>
> I may have not been clear enough one more time. =20
> I've changed the initial proposal due to need to support construction wit=
h=20
> parenthesis (to stay backward compatible), so now the "magic" class is mu=
ch=20
> simpler - just a compiler provided template aggregate something along the=
=20
> lines:=20
> template <typename ...T>
> struct __magic_struct
> {
> static_assert(sizeof...(T) =3D=3D 0, "");
> }; // empty pack
>
> template <typename T0>
> struct __magic_struct<T0>
> {
> T0 _0;
> };
>
> template <typename T0, typename T1>
> struct __magic_struct<T0, T1>
> {
> T0 _0;
> T1 _1;
> };
>
> template <typename T0, typename T1, typename T2>
> struct __magic_struct<T0, T1, T2>
> {
> T0 _0;
> T1 _1;
> T2 _2;
> };
> ...
>
> so its specification should be rather simple.
>
> Who could use this magic struct?
>
>
> We could even get a standard type alias for this in the library:
> template <typename ...Ts>
> using tuple_struct =3D <implementation_defined>; // __magic_struct<Ts...>=
=20
> in this case
>
> The rest would be implemented in the tuple<typename ...T> itself.
>
> Instead of implementing operator conversion to another tuple, I believe=
=20
> that what we need is conversion from any Tuple-like type.=20
> P0197 proposes that the compiler can generate them, but after some though=
t=20
> this can be relaxed and it will be simple to implement them in tuple and=
=20
> pair. After all it will be implemented only once.
>
> I've improved my implementation - https://ideone.com/Tfk3Ce . Hopefully=
=20
> the code speaks for itself and explains better my idea.
> This already supports everything C++17 tuple has except for:
> - integration with pair,=20
>
> See above.
>
> - swap,
>
> P0198
>
> - allocator constructors,
> - comparison operators (would be automatically provided by P0221)
> Missing features are easy to implement with this aproach.
>
> Hash on tuples doesn't exist yet, PO198 proposes as well the generation=
=20
> under some conditions.=20
>
> Implementation will be even simpler with P0197 (default tuple-like access=
).
>
> If I resume, your proposal would make the implementation of tuple simpler=
,=20
> but if there are no more classes that use this __magic_struct the gain is=
=20
> minor.
> However the __magic_struct could be more important as a QOI IF the compil=
e=20
> performances are improved.
>
> It would be worth doing a benchmark comparing a recursive implementation=
=20
> that preserves the order and the hard-coded you proposes.
>
> Vicente
>
--=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/865dbbc5-1f70-45bf-b265-b3c2f6bb8d1b%40isocpp.or=
g.
------=_Part_609_1725393213.1459525355186
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>For now the only use case for__magic_struct that I ca=
n think of is the tuple, but if this proposal goes to standard than anyway =
this will have to be specified (as part of tuple).</div><div>So=C2=A0additi=
onal cost of standardizing the __magic_struct comes down to giving it a nam=
e.</div><div><br></div><div>...</div><div><br></div>For starters I compared=
compilation time for the simple code in main() from previous post (https:/=
/ideone.com/Tfk3Ce)<div>I compared gcc-6 own std::tuple and my version (wit=
h __magic_struct template pregenerated for up to 50 parameters).</div><div>=
<br></div><div>I've performed around 10 runs for each version, and resu=
lts are pretty consistent.<br></div><div>There is always ~150-200ms improve=
ment in total compilation time in favor of __magic_struct version,</div><di=
v>and most of this improvement can be attributed to reduction of template i=
nstantation time:</div><div><br></div><div>excerpt of -ftime-report gcc-6:<=
/div><div>template instantiation =C2=A0: =C2=A0 0.09 (50%) usr =C2=A0 0.69 =
(33%) sys =C2=A0 0.80 (35%) wall =C2=A0 50660 kB (58%) ggc<br></div><div>TO=
TAL =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 : =C2=A0 0.18 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 2.08 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 2.26 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A087351 kB=
<br></div><div><br></div><div>excerpt of -ftime-report __magic_struct:</div=
><div>template instantiation =C2=A0: =C2=A0 0.05 (33%) usr =C2=A0 0.40 (21%=
) sys =C2=A0 0.48 (23%) wall =C2=A0 30762 kB (42%) ggc<br></div><div>TOTAL =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 : =C2=A0 0.15 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 1.92 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 2.08 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A073944 kB</d=
iv><div><br></div><div>I'd love to perform tests on real code that make=
s heavy use of tuples, but I don't have access to such code anymore.</d=
iv><div>Any suggestions for such a freely available code? (e.g. an open sou=
rce project with UTs relaying on google mock).<br></div><div><br></div><div=
>I'll try to perform the tests for clang-3.8<br></div><div><br></div><d=
iv>Regards,</div><div>Maciej</div><div><br>W dniu pi=C4=85tek, 18 marca 201=
6 08:50:59 UTC+1 u=C5=BCytkownik Vicente J. Botet Escriba napisa=C5=82:<blo=
ckquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-=
left: 1px #ccc solid;padding-left: 1ex;">
=20
=20
=20
<div text=3D"#000000" bgcolor=3D"#FFFFFF">
<div>Le 16/03/2016 13:07,
<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"r7=
Kj2eNFCQAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:=
9;;return true;" onclick=3D"this.href=3D'javascript:';return true;"=
>m.ce...@gmail.com</a> a =C3=A9crit=C2=A0:<br>
</div>
<blockquote type=3D"cite">
<div dir=3D"ltr">I may have not been clear enough one more time.=C2=
=A0
<div>I've changed the initial proposal due to need to support
construction with parenthesis (to stay backward compatible),
so now the "magic" class is much simpler - just a compi=
ler
provided template aggregate something along the lines:
<div>
<div style=3D"border:1px solid rgb(187,187,187);word-wrap:break=
-word;background-color:rgb(250,250,250)"><code>
<div><span style=3D"color:#008">template</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660"><</span><span style=
=3D"color:#008">typename</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">...</span><span style=3D"color:#000">T</span><span style=
=3D"color:#660">></span><span style=3D"color:#000"><br>
</span><span style=3D"color:#008">struct</span><span styl=
e=3D"color:#000">
__magic_struct<br>
</span><span style=3D"color:#660">{</span><span style=3D"=
color:#000"><br>
=C2=A0 =C2=A0</span><span style=3D"color:#008">static_a=
ssert</span><span style=3D"color:#660">(</span><span style=3D"color:#008">s=
izeof</span><span style=3D"color:#660">...(</span><span style=3D"color:#000=
">T</span><span style=3D"color:#660">)</span><span style=3D"color:#000"> </=
span><span style=3D"color:#660">=3D=3D</span><span style=3D"color:#000"> </=
span><span style=3D"color:#066">0</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#080">""<=
/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"> </span><span style=3D"color:#800">//
empty pack</span><span style=3D"color:#000"><br>
<br>
</span><span style=3D"color:#008">template</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#660"><</span><span styl=
e=3D"color:#008">typename</span><span style=3D"color:#000"> T0</span><span =
style=3D"color:#660">></span><span style=3D"color:#000"><br>
</span><span style=3D"color:#008">struct</span><span styl=
e=3D"color:#000">
__magic_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#000">T0</span><span style=3D"color:#660">></sp=
an><span style=3D"color:#000"><br>
</span><span style=3D"color:#660">{</span><span style=3D"=
color:#000"><br>
=C2=A0 =C2=A0 T0 _0</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>
</span><span style=3D"color:#008">template</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#660"><</span><span styl=
e=3D"color:#008">typename</span><span style=3D"color:#000"> T0</span><span =
style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">typename</span><span style=3D"color:#000"> T1</span><span s=
tyle=3D"color:#660">></span><span style=3D"color:#000"><br>
</span><span style=3D"color:#008">struct</span><span styl=
e=3D"color:#000">
__magic_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#000">T0</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> T1</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>
=C2=A0 =C2=A0 T0 _0</span><span style=3D"color:#660">;<=
/span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 T1 _1</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>
</span><span style=3D"color:#008">template</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#660"><</span><span styl=
e=3D"color:#008">typename</span><span style=3D"color:#000"> T0</span><span =
style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">typename</span><span style=3D"color:#000"> T1</span><span s=
tyle=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">typename</span><span style=3D"color:#000"> T2</span><span s=
tyle=3D"color:#660">></span><span style=3D"color:#000"><br>
</span><span style=3D"color:#008">struct</span><span styl=
e=3D"color:#000">
__magic_struct</span><span style=3D"color:#660"><</s=
pan><span style=3D"color:#000">T0</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> T1</span><span style=3D"color:#660">,</span><sp=
an style=3D"color:#000"> T2</span><span style=3D"color:#660">></span><sp=
an style=3D"color:#000"><br>
</span><span style=3D"color:#660">{</span><span style=3D"=
color:#000"><br>
=C2=A0 =C2=A0 T0 _0</span><span style=3D"color:#660">;<=
/span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 T1 _1</span><span style=3D"color:#660">;<=
/span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 T2 _2</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>
</span><span style=3D"color:#660">...</span></div>
</code></div>
<div style=3D"font-family:Arial,Helvetica,sans-serif;background=
-color:rgb(255,255,255)"><br>
</div>
so its specification should be rather simple.</div>
</div>
</div>
</blockquote>
Who could use this magic struct?<br>
<br>
<br>
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div>
<div>We could even get a standard type alias for this in the
library:</div>
<div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-w=
ord;background-color:rgb(250,250,250)"><code>
<div><span style=3D"color:#008">template</span><span style=3D=
"color:#000"> </span><span style=3D"color:#660"><</span><span style=3D"c=
olor:#008">typename</span><span style=3D"color:#000"> </span><span style=3D=
"color:#660">...</span><span style=3D"color:#606">Ts</span><span style=3D"c=
olor:#660">></span><span style=3D"color:#000"><br>
</span><span style=3D"color:#008">using</span><span style=
=3D"color:#000">
tuple_struct </span><span style=3D"color:#660">=3D</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#080"><implement=
ation_defined></span><span style=3D"color:#660">;</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#800">//
__magic_struct<Ts...> in this case</span></div>
</code></div>
<div><br>
</div>
<div>The rest would be implemented in the tuple<typename
...T> itself.<br>
</div>
<div><br>
</div>
</div>
</div>
</blockquote>
Instead of implementing operator conversion to another tuple, I
believe that what we need is conversion from any Tuple-like type. <br>
P0197 proposes that the compiler can generate them, but after some
thought this can be relaxed and it will be simple to implement them
in tuple and pair. After all it will be implemented only once.<br>
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div>
<div>I've improved my implementation -
<a href=3D"https://ideone.com/Tfk3Ce" target=3D"_blank" rel=3D"=
nofollow" onmousedown=3D"this.href=3D'https://www.google.com/url?q\75ht=
tps%3A%2F%2Fideone.com%2FTfk3Ce\46sa\75D\46sntz\0751\46usg\75AFQjCNGThkW7w5=
AuhV9xw6lb9Li_t7e4sA';return true;" onclick=3D"this.href=3D'https:/=
/www.google.com/url?q\75https%3A%2F%2Fideone.com%2FTfk3Ce\46sa\75D\46sntz\0=
751\46usg\75AFQjCNGThkW7w5AuhV9xw6lb9Li_t7e4sA';return true;">https://i=
deone.com/Tfk3Ce</a> . Hopefully the code speaks for
itself and explains better my idea.<br>
This already supports everything C++17 tuple has except for:</d=
iv>
<div>=C2=A0- integration with pair, <br>
</div>
</div>
</div>
</blockquote>
See above.<br>
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div>
<div>=C2=A0- swap,</div>
</div>
</div>
</blockquote>
P0198<br>
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div>
<div>=C2=A0- allocator constructors,</div>
<div>=C2=A0- comparison operators (would be automatically provide=
d
by P0221)</div>
<div>Missing features are easy to implement with this aproach.</d=
iv>
<div><br>
</div>
</div>
</div>
</blockquote>
Hash on tuples doesn't exist yet, PO198 proposes as well the
generation under some conditions. <br>
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div>
<div>Implementation will be even simpler with P0197 (default
tuple-like access).</div>
<div><br>
</div>
</div>
</div>
</blockquote>
If I resume, your proposal would make the implementation of tuple
simpler, but if there are no more classes that use this
__magic_struct the gain is minor.<br>
However the __magic_struct could be more important as a QOI IF the
compile performances are improved.<br>
<br>
It would be worth doing a benchmark comparing a recursive
implementation that preserves the order and the hard-coded you
proposes.<br>
<br>
Vicente<br>
</div>
</blockquote></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/865dbbc5-1f70-45bf-b265-b3c2f6bb8d1b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/865dbbc5-1f70-45bf-b265-b3c2f6bb8d1b=
%40isocpp.org</a>.<br />
------=_Part_609_1725393213.1459525355186--
------=_Part_608_231674555.1459525355185--
.
Author: Mathias Gaunard <mathias@gaunard.com>
Date: Fri, 1 Apr 2016 17:18:56 +0100
Raw View
--001a11c3c34a5baac1052f6ebc96
Content-Type: text/plain; charset=UTF-8
On 15 February 2016 at 16:19, <m.cencora@gmail.com> wrote:
> Hi,
>
> I think the structured binding proposal opens a possibility for major
> simplification of std::tuple implementation.
>
> Let's take following "implementation" as an example:
> template <typename ...T>
> struct __tuple_struct;
>
> template <typename T1>
> struct __tuple_struct<T1>
> {
> T1 _1;
>
> template <typename ...Args, typename = decltype(__tuple_struct<Args
> ...>{ _1 })>
> operator __tuple_struct<Args...>()
> {
> return __tuple_struct<Args...>{ _1 };
> }
>
> void swap(__tuple_struct& other);
> };
>
> template <typename T1, typename T2>
> struct __tuple_struct<T1, T2>
> {
> T1 _1;
> T2 _2;
>
> template <typename ...Args, typename = decltype(__tuple_struct<Args
> ...>{ _1, _2 })>
> operator __tuple_struct<Args...>()
> {
> return __tuple_struct<Args...>{ _1, _2 };
> }
>
> void swap(__tuple_struct& other);
> };
>
>
> template <typename ...Ts>
> using tuple = __tuple_struct<Ts...>;
>
>
> The tuple struct is almost implementable with variadic templates in C++14
> - except for the data members.
>
>
> If that's not clear yet, following implementation is almost dead simple
> and you get most of current std::tuple functionality for free - perfect
> initialization, copy/move assignement, copy/move construction, get<N>.
>
There are interesting ways to implement tuples in C++14 already, like with
something like this
template<class... T>
struct tuple
{
tuple(T&&... t) : data(init(std::forward<T>(t)...)) {}
static auto init(T&&... xs)
{
return [=](auto&& f)
{
return f(std::forward<T>(xs)...);
};
}
decltype(init(std::declval<T>()...)) data;
};
Note the members are stored in the capture list of the lambda 'data', and
you extract them by applying 'data' to any function object as needed.
--
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/CALnjya8Z8vOVJPF5gbrrzmfW9eH_QVKo%3Du65MqGdHexnUKu1zQ%40mail.gmail.com.
--001a11c3c34a5baac1052f6ebc96
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On 1=
5 February 2016 at 16:19, <span dir=3D"ltr"><<a href=3D"mailto:m.cencor=
a@gmail.com" target=3D"_blank">m.cencora@gmail.com</a>></span> wrote:<br=
><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border=
-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;=
padding-left:1ex"><div dir=3D"ltr">Hi,<div><br></div><div>I think the struc=
tured binding proposal opens a possibility for major simplification of std:=
:tuple implementation.</div><div><br></div><div>Let's take following &q=
uot;implementation" as an example:</div><div><div style=3D"border:1px =
solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,250,25=
0)"><code><div><div style=3D"font-family:Arial,Helvetica,sans-serif;backgro=
und-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,136)">template</sp=
an><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,10=
2,0)"><</span><span style=3D"color:rgb(0,0,136)">typename</span><span st=
yle=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">...</=
span><span style=3D"color:rgb(0,0,0)">T</span><span style=3D"color:rgb(102,=
102,0)">></span></div><div style=3D"font-family:Arial,Helvetica,sans-ser=
if;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,136)">st=
ruct</span><span style=3D"color:rgb(0,0,0)"> __tuple_struct</span><span sty=
le=3D"color:rgb(102,102,0)">;</span></div><div style=3D"font-family:Arial,H=
elvetica,sans-serif;background-color:rgb(255,255,255)"><span style=3D"color=
:rgb(0,0,0)"><br></span></div><div style=3D"font-family:Arial,Helvetica,san=
s-serif;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,136=
)">template</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"c=
olor:rgb(102,102,0)"><</span><span style=3D"color:rgb(0,0,136)">typename=
</span><span style=3D"color:rgb(0,0,0)"> T1</span><span style=3D"color:rgb(=
102,102,0)">></span></div><div style=3D"font-family:Arial,Helvetica,sans=
-serif;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,136)=
">struct</span><span style=3D"color:rgb(0,0,0)"> __tuple_struct</span><span=
style=3D"color:rgb(102,102,0)"><</span><span style=3D"color:rgb(0,0,0)"=
>T1</span><span style=3D"color:rgb(102,102,0)">></span></div><div style=
=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,255,255=
)"><span style=3D"color:rgb(102,102,0)">{</span></div><div style=3D"font-fa=
mily:Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)"><span st=
yle=3D"color:rgb(0,0,0)"> =C2=A0 =C2=A0T1 _1</span><span style=3D"color:rgb=
(102,102,0)">;</span></div><div style=3D"font-family:Arial,Helvetica,sans-s=
erif;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"><b=
r></span></div><div style=3D"font-family:Arial,Helvetica,sans-serif;backgro=
und-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)">=C2=A0 =C2=A0 =
</span><span style=3D"color:rgb(0,0,136)">template</span><span style=3D"col=
or:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)"><</span><spa=
n style=3D"color:rgb(0,0,136)">typename</span><span style=3D"color:rgb(0,0,=
0)"> </span><span style=3D"color:rgb(102,102,0)">...</span><span style=3D"c=
olor:rgb(102,0,102)">Args</span><span style=3D"color:rgb(102,102,0)">,</spa=
n><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136=
)">typename</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"c=
olor:rgb(102,102,0)">=3D</span><span style=3D"color:rgb(0,0,0)"> </span><sp=
an style=3D"color:rgb(0,0,136)">decltype</span><span style=3D"color:rgb(102=
,102,0)">(</span><span style=3D"color:rgb(0,0,0)">__tuple_struct</span><spa=
n style=3D"color:rgb(102,102,0)"><</span><span style=3D"color:rgb(102,0,=
102)">Args</span><span style=3D"color:rgb(102,102,0)">...>{</span><span =
style=3D"color:rgb(0,0,0)"> _1 </span><span style=3D"color:rgb(102,102,0)">=
})></span><span style=3D"color:rgb(0,0,0)"><br></span></div><div style=
=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,255,255=
)"><span style=3D"color:rgb(0,0,0)">=C2=A0 =C2=A0 </span><span style=3D"col=
or:rgb(0,0,136)">operator</span><span style=3D"color:rgb(0,0,0)"> __tuple_s=
truct</span><span style=3D"color:rgb(102,102,0)"><</span><span style=3D"=
color:rgb(102,0,102)">Args</span><span style=3D"color:rgb(102,102,0)">...&g=
t;()</span></div><div style=3D"font-family:Arial,Helvetica,sans-serif;backg=
round-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"> =C2=A0 =C2=
=A0</span><span style=3D"color:rgb(102,102,0)">{</span></div><div style=3D"=
font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)"><=
span style=3D"color:rgb(0,0,0)"> =C2=A0 =C2=A0 =C2=A0 =C2=A0</span><span st=
yle=3D"color:rgb(0,0,136)">return</span><span style=3D"color:rgb(0,0,0)"> _=
_tuple_struct</span><span style=3D"color:rgb(102,102,0)"><</span><span s=
tyle=3D"color:rgb(102,0,102)">Args</span><span style=3D"color:rgb(102,102,0=
)">...>{</span><span style=3D"color:rgb(0,0,0)"> _1 </span><span style=
=3D"color:rgb(102,102,0)">};</span></div><div style=3D"font-family:Arial,He=
lvetica,sans-serif;background-color:rgb(255,255,255)"><span style=3D"color:=
rgb(0,0,0)"> =C2=A0 =C2=A0</span><span style=3D"color:rgb(102,102,0)">}</sp=
an></div><div style=3D"font-family:Arial,Helvetica,sans-serif;background-co=
lor:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"><br></span></div><di=
v style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,=
255,255)"><span style=3D"color:rgb(0,0,0)">=C2=A0 =C2=A0 </span><span style=
=3D"color:rgb(0,0,136)">void</span><span style=3D"color:rgb(0,0,0)"> swap</=
span><span style=3D"color:rgb(102,102,0)">(</span><span style=3D"color:rgb(=
0,0,0)">__tuple_struct</span><span style=3D"color:rgb(102,102,0)">&</sp=
an><span style=3D"color:rgb(0,0,0)"> other</span><span style=3D"color:rgb(1=
02,102,0)">);</span></div><div style=3D"font-family:Arial,Helvetica,sans-se=
rif;background-color:rgb(255,255,255)"><span style=3D"color:rgb(102,102,0)"=
>};</span></div><div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"><br></span></=
div><div style=3D"font-family:Arial,Helvetica,sans-serif;background-color:r=
gb(255,255,255)"><span style=3D"color:rgb(0,0,136)">template</span><span st=
yle=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)"><<=
/span><span style=3D"color:rgb(0,0,136)">typename</span><span style=3D"colo=
r:rgb(0,0,0)"> T1</span><span style=3D"color:rgb(102,102,0)">,</span><span =
style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">typen=
ame</span><span style=3D"color:rgb(0,0,0)"> T2</span><span style=3D"color:r=
gb(102,102,0)">></span></div><div style=3D"font-family:Arial,Helvetica,s=
ans-serif;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,1=
36)">struct</span><span style=3D"color:rgb(0,0,0)"> __tuple_struct</span><s=
pan style=3D"color:rgb(102,102,0)"><</span><span style=3D"color:rgb(0,0,=
0)">T1</span><span style=3D"color:rgb(102,102,0)">,</span><span style=3D"co=
lor:rgb(0,0,0)"> T2</span><span style=3D"color:rgb(102,102,0)">></span><=
/div><div style=3D"font-family:Arial,Helvetica,sans-serif;background-color:=
rgb(255,255,255)"><span style=3D"color:rgb(102,102,0)">{</span></div><div s=
tyle=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,255=
,255)"><span style=3D"color:rgb(0,0,0)"> =C2=A0 =C2=A0T1 _1</span><span sty=
le=3D"color:rgb(102,102,0)">;</span></div><div style=3D"font-family:Arial,H=
elvetica,sans-serif;background-color:rgb(255,255,255)"><span style=3D"color=
:rgb(0,0,0)"> =C2=A0 =C2=A0T2 _2</span><span style=3D"color:rgb(102,102,0)"=
>;</span></div><div style=3D"font-family:Arial,Helvetica,sans-serif;backgro=
und-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"><br></span></d=
iv><div style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rg=
b(255,255,255)"><span style=3D"color:rgb(136,0,0)"><span style=3D"color:rgb=
(0,0,0)">=C2=A0 =C2=A0</span><span style=3D"color:rgb(0,0,136)">template</s=
pan><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,1=
02,0)"><</span><span style=3D"color:rgb(0,0,136)">typename</span><span s=
tyle=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">...<=
/span><span style=3D"color:rgb(102,0,102)">Args</span><span style=3D"color:=
rgb(102,102,0)">,</span><span style=3D"color:rgb(0,0,0)"> </span><span styl=
e=3D"color:rgb(0,0,136)">typename</span><span style=3D"color:rgb(0,0,0)"> <=
/span><span style=3D"color:rgb(102,102,0)">=3D</span><span style=3D"color:r=
gb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">decltype</span><span =
style=3D"color:rgb(102,102,0)">(</span><span style=3D"color:rgb(0,0,0)">__t=
uple_struct</span><span style=3D"color:rgb(102,102,0)"><</span><span sty=
le=3D"color:rgb(102,0,102)">Args</span><span style=3D"color:rgb(102,102,0)"=
>...>{</span><span style=3D"color:rgb(0,0,0)"> _1</span><span style=3D"c=
olor:rgb(102,102,0)">,</span><span style=3D"color:rgb(0,0,0)"> _2 </span><s=
pan style=3D"color:rgb(102,102,0)">})></span></span><span style=3D"color=
:rgb(0,0,0)"><br></span></div><div style=3D"font-family:Arial,Helvetica,san=
s-serif;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"=
>=C2=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)">operator</span><sp=
an style=3D"color:rgb(0,0,0)"> __tuple_struct</span><span style=3D"color:rg=
b(102,102,0)"><</span><span style=3D"color:rgb(102,0,102)">Args</span><s=
pan style=3D"color:rgb(102,102,0)">...>()</span></div><div style=3D"font=
-family:Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)"><span=
style=3D"color:rgb(0,0,0)"> =C2=A0 =C2=A0</span><span style=3D"color:rgb(1=
02,102,0)">{</span></div><div style=3D"font-family:Arial,Helvetica,sans-ser=
if;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"> =C2=
=A0 =C2=A0 =C2=A0 =C2=A0</span><span style=3D"color:rgb(0,0,136)">return</s=
pan><span style=3D"color:rgb(0,0,0)"> __tuple_struct</span><span style=3D"c=
olor:rgb(102,102,0)"><</span><span style=3D"color:rgb(102,0,102)">Args</=
span><span style=3D"color:rgb(102,102,0)">...>{</span><span style=3D"col=
or:rgb(0,0,0)"> _1</span><span style=3D"color:rgb(102,102,0)">,</span><span=
style=3D"color:rgb(0,0,0)"> _2 </span><span style=3D"color:rgb(102,102,0)"=
>};</span></div><div style=3D"font-family:Arial,Helvetica,sans-serif;backgr=
ound-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"> =C2=A0 =C2=
=A0</span><span style=3D"color:rgb(102,102,0)">}</span></div><div style=3D"=
font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)"><=
span style=3D"color:rgb(0,0,0)"><br></span></div><div style=3D"font-family:=
Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)"><span style=
=3D"color:rgb(0,0,0)">=C2=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136=
)">void</span><span style=3D"color:rgb(0,0,0)"> swap</span><span style=3D"c=
olor:rgb(102,102,0)">(</span><span style=3D"color:rgb(0,0,0)">__tuple_struc=
t</span><span style=3D"color:rgb(102,102,0)">&</span><span style=3D"col=
or:rgb(0,0,0)"> other</span><span style=3D"color:rgb(102,102,0)">);</span><=
/div><div style=3D"font-family:Arial,Helvetica,sans-serif;background-color:=
rgb(255,255,255)"><span style=3D"color:rgb(102,102,0)">};</span></div><div =
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span style=3D"color:rgb(0,0,0)"><br></span></div><div style=3D"fon=
t-family:Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)"><spa=
n style=3D"color:rgb(0,0,0)"><br></span></div><div style=3D"font-family:Ari=
al,Helvetica,sans-serif;background-color:rgb(255,255,255)"><span style=3D"c=
olor:rgb(0,0,136)">template</span><span style=3D"color:rgb(0,0,0)"> </span>=
<span style=3D"color:rgb(102,102,0)"><</span><span style=3D"color:rgb(0,=
0,136)">typename</span><span style=3D"color:rgb(0,0,0)"> </span><span style=
=3D"color:rgb(102,102,0)">...</span><span style=3D"color:rgb(102,0,102)">Ts=
</span><span style=3D"color:rgb(102,102,0)">></span></div><div style=3D"=
font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)"><=
span style=3D"color:rgb(0,0,136)">using</span><span style=3D"color:rgb(0,0,=
0)"> tuple </span><span style=3D"color:rgb(102,102,0)">=3D</span><span styl=
e=3D"color:rgb(0,0,0)"> __tuple_struct</span><span style=3D"color:rgb(102,1=
02,0)"><</span><span style=3D"color:rgb(102,0,102)">Ts</span><span style=
=3D"color:rgb(102,102,0)">...>;</span></div></div></code></div><br><br><=
/div><div>The tuple struct is almost implementable with variadic templates =
in C++14 - except for the data members.</div><div><br></div><div><br></div>=
<div>If that's not clear yet, following implementation is almost dead s=
imple and you get most of current std::tuple functionality for free - perfe=
ct initialization, copy/move assignement, copy/move construction, get<N&=
gt;.</div></div></blockquote><div><br></div><div>There are interesting ways=
to implement tuples in C++14 already, like with something like this</div><=
div><br>template<class... T><br>struct tuple<br>{<br>=C2=A0 =C2=A0 tu=
ple(T&&... t) : data(init(std::forward<T>(t)...)) {}<br><br>=
=C2=A0 =C2=A0 static auto init(T&&... xs)<br>=C2=A0 =C2=A0 {=C2=A0<=
br></div><div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return [=3D](auto&& =
f)<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 return f(std::forward<T>(xs)...);</div><div>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 };=C2=A0</div><div>=C2=A0 =C2=A0 }</div><div><br>=C2=A0 =
=C2=A0 decltype(init(std::declval<T>()...)) data;</div><div>};</div><=
/div><div><br></div><div>Note the members are stored in the capture list of=
the lambda 'data', and you extract them by applying 'data'=
to any function object as needed.</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" 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/CALnjya8Z8vOVJPF5gbrrzmfW9eH_QVKo%3Du=
65MqGdHexnUKu1zQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CALnjya8Z8vOVJP=
F5gbrrzmfW9eH_QVKo%3Du65MqGdHexnUKu1zQ%40mail.gmail.com</a>.<br />
--001a11c3c34a5baac1052f6ebc96--
.
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Fri, 1 Apr 2016 20:20:30 +0200
Raw View
This is a multi-part message in MIME format.
--------------080109030301000001030103
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Le 01/04/2016 18:18, Mathias Gaunard a =C3=A9crit :
> On 15 February 2016 at 16:19, <m.cencora@gmail.com=20
> <mailto:m.cencora@gmail.com>> wrote:
>
> Hi,
>
> I think the structured binding proposal opens a possibility for
> major simplification of std::tuple implementation.
>
> Let's take following "implementation" as an example:
> |
> template<typename...T>
> struct__tuple_struct;
>
> template<typenameT1>
> struct__tuple_struct<T1>
> {
> T1 _1;
>
> template<typename...Args,typename=3Ddecltype(__tuple_struct<Args...>{=
_1
> })>
> operator__tuple_struct<Args...>()
> {
> return__tuple_struct<Args...>{_1 };
> }
>
> voidswap(__tuple_struct&other);
> };
>
> template<typenameT1,typenameT2>
> struct__tuple_struct<T1,T2>
> {
> T1 _1;
> T2 _2;
>
> template<typename...Args,typename=3Ddecltype(__tuple_struct<Args...>{=
_1,_2
> })>
> operator__tuple_struct<Args...>()
> {
> return__tuple_struct<Args...>{_1,_2 };
> }
>
> voidswap(__tuple_struct&other);
> };
>
>
> template<typename...Ts>
> usingtuple =3D__tuple_struct<Ts...>;
> |
>
>
> The tuple struct is almost implementable with variadic templates
> in C++14 - except for the data members.
>
>
> If that's not clear yet, following implementation is almost dead
> simple and you get most of current std::tuple functionality for
> free - perfect initialization, copy/move assignement, copy/move
> construction, get<N>.
>
>
> There are interesting ways to implement tuples in C++14 already, like=20
> with something like this
>
> template<class... T>
> struct tuple
> {
> tuple(T&&... t) : data(init(std::forward<T>(t)...)) {}
>
> static auto init(T&&... xs)
> {
> return [=3D](auto&& f)
> {
> return f(std::forward<T>(xs)...);
> };
> }
>
> decltype(init(std::declval<T>()...)) data;
> };
>
> Note the members are stored in the capture list of the lambda 'data',=20
> and you extract them by applying 'data' to any function object as needed.
>
>
This is similar/inline with the operator extract defined by David Sankel=20
in his Blog [1]
I'm wondering how the compiler optimizes the code when I want to access=20
just a member of a tuple.
Vicente
[1]=20
http://davidsankel.com/uncategorized/c-language-support-for-pattern-matchin=
g-and-variants/
--=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/56FEBBEE.7020106%40wanadoo.fr.
--------------080109030301000001030103
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
</head>
<body bgcolor=3D"#FFFFFF" text=3D"#000000">
<div class=3D"moz-cite-prefix">Le 01/04/2016 18:18, Mathias Gaunard a
=C3=A9crit=C2=A0:<br>
</div>
<blockquote
cite=3D"mid:CALnjya8Z8vOVJPF5gbrrzmfW9eH_QVKo=3Du65MqGdHexnUKu1zQ@mail.gmai=
l.com"
type=3D"cite">
<div dir=3D"ltr">
<div class=3D"gmail_extra">
<div class=3D"gmail_quote">On 15 February 2016 at 16:19, <span
dir=3D"ltr"><<a moz-do-not-send=3D"true"
href=3D"mailto:m.cencora@gmail.com" target=3D"_blank">m.cen=
cora@gmail.com</a>></span>
wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-=
style:solid;padding-left:1ex">
<div dir=3D"ltr">Hi,
<div><br>
</div>
<div>I think the structured binding proposal opens a
possibility for major simplification of std::tuple
implementation.</div>
<div><br>
</div>
<div>Let's take following "implementation" as an
example:</div>
<div>
<div style=3D"border:1px solid
rgb(187,187,187);word-wrap:break-word;background-color:=
rgb(250,250,250)"><code>
<div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,136)">template</span><sp=
an
style=3D"color:rgb(0,0,0)"> </span><span
style=3D"color:rgb(102,102,0)"><</span><span
style=3D"color:rgb(0,0,136)">typename</span><sp=
an
style=3D"color:rgb(0,0,0)"> </span><span
style=3D"color:rgb(102,102,0)">...</span><span
style=3D"color:rgb(0,0,0)">T</span><span
style=3D"color:rgb(102,102,0)">></span></div=
>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,136)">struct</span><span
style=3D"color:rgb(0,0,0)"> __tuple_struct</spa=
n><span
style=3D"color:rgb(102,102,0)">;</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,136)">template</span><sp=
an
style=3D"color:rgb(0,0,0)"> </span><span
style=3D"color:rgb(102,102,0)"><</span><span
style=3D"color:rgb(0,0,136)">typename</span><sp=
an
style=3D"color:rgb(0,0,0)"> T1</span><span
style=3D"color:rgb(102,102,0)">></span></div=
>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,136)">struct</span><span
style=3D"color:rgb(0,0,0)"> __tuple_struct</spa=
n><span
style=3D"color:rgb(102,102,0)"><</span><span
style=3D"color:rgb(0,0,0)">T1</span><span
style=3D"color:rgb(102,102,0)">></span></div=
>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(102,102,0)">{</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)"> =C2=A0 =C2=A0T1 _1<=
/span><span
style=3D"color:rgb(102,102,0)">;</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)">=C2=A0 =C2=A0 </span=
><span
style=3D"color:rgb(0,0,136)">template</span><sp=
an
style=3D"color:rgb(0,0,0)"> </span><span
style=3D"color:rgb(102,102,0)"><</span><span
style=3D"color:rgb(0,0,136)">typename</span><sp=
an
style=3D"color:rgb(0,0,0)"> </span><span
style=3D"color:rgb(102,102,0)">...</span><span
style=3D"color:rgb(102,0,102)">Args</span><span
style=3D"color:rgb(102,102,0)">,</span><span
style=3D"color:rgb(0,0,0)"> </span><span
style=3D"color:rgb(0,0,136)">typename</span><sp=
an
style=3D"color:rgb(0,0,0)"> </span><span
style=3D"color:rgb(102,102,0)">=3D</span><span
style=3D"color:rgb(0,0,0)"> </span><span
style=3D"color:rgb(0,0,136)">decltype</span><sp=
an
style=3D"color:rgb(102,102,0)">(</span><span
style=3D"color:rgb(0,0,0)">__tuple_struct</span=
><span
style=3D"color:rgb(102,102,0)"><</span><span
style=3D"color:rgb(102,0,102)">Args</span><span
style=3D"color:rgb(102,102,0)">...>{</span><=
span
style=3D"color:rgb(0,0,0)"> _1 </span><span
style=3D"color:rgb(102,102,0)">})></span><sp=
an
style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)">=C2=A0 =C2=A0 </span=
><span
style=3D"color:rgb(0,0,136)">operator</span><sp=
an
style=3D"color:rgb(0,0,0)"> __tuple_struct</spa=
n><span
style=3D"color:rgb(102,102,0)"><</span><span
style=3D"color:rgb(102,0,102)">Args</span><span
style=3D"color:rgb(102,102,0)">...>()</span>=
</div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)"> =C2=A0 =C2=A0</span=
><span
style=3D"color:rgb(102,102,0)">{</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)"> =C2=A0 =C2=A0 =C2=
=A0 =C2=A0</span><span
style=3D"color:rgb(0,0,136)">return</span><span
style=3D"color:rgb(0,0,0)"> __tuple_struct</spa=
n><span
style=3D"color:rgb(102,102,0)"><</span><span
style=3D"color:rgb(102,0,102)">Args</span><span
style=3D"color:rgb(102,102,0)">...>{</span><=
span
style=3D"color:rgb(0,0,0)"> _1 </span><span
style=3D"color:rgb(102,102,0)">};</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)"> =C2=A0 =C2=A0</span=
><span
style=3D"color:rgb(102,102,0)">}</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)">=C2=A0 =C2=A0 </span=
><span
style=3D"color:rgb(0,0,136)">void</span><span
style=3D"color:rgb(0,0,0)"> swap</span><span
style=3D"color:rgb(102,102,0)">(</span><span
style=3D"color:rgb(0,0,0)">__tuple_struct</span=
><span
style=3D"color:rgb(102,102,0)">&</span><spa=
n
style=3D"color:rgb(0,0,0)"> other</span><span
style=3D"color:rgb(102,102,0)">);</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(102,102,0)">};</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,136)">template</span><sp=
an
style=3D"color:rgb(0,0,0)"> </span><span
style=3D"color:rgb(102,102,0)"><</span><span
style=3D"color:rgb(0,0,136)">typename</span><sp=
an
style=3D"color:rgb(0,0,0)"> T1</span><span
style=3D"color:rgb(102,102,0)">,</span><span
style=3D"color:rgb(0,0,0)"> </span><span
style=3D"color:rgb(0,0,136)">typename</span><sp=
an
style=3D"color:rgb(0,0,0)"> T2</span><span
style=3D"color:rgb(102,102,0)">></span></div=
>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,136)">struct</span><span
style=3D"color:rgb(0,0,0)"> __tuple_struct</spa=
n><span
style=3D"color:rgb(102,102,0)"><</span><span
style=3D"color:rgb(0,0,0)">T1</span><span
style=3D"color:rgb(102,102,0)">,</span><span
style=3D"color:rgb(0,0,0)"> T2</span><span
style=3D"color:rgb(102,102,0)">></span></div=
>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(102,102,0)">{</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)"> =C2=A0 =C2=A0T1 _1<=
/span><span
style=3D"color:rgb(102,102,0)">;</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)"> =C2=A0 =C2=A0T2 _2<=
/span><span
style=3D"color:rgb(102,102,0)">;</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(136,0,0)"><span
style=3D"color:rgb(0,0,0)">=C2=A0 =C2=A0</spa=
n><span
style=3D"color:rgb(0,0,136)">template</span><=
span
style=3D"color:rgb(0,0,0)"> </span><span
style=3D"color:rgb(102,102,0)"><</span><sp=
an
style=3D"color:rgb(0,0,136)">typename</span><=
span
style=3D"color:rgb(0,0,0)"> </span><span
style=3D"color:rgb(102,102,0)">...</span><spa=
n
style=3D"color:rgb(102,0,102)">Args</span><sp=
an
style=3D"color:rgb(102,102,0)">,</span><span
style=3D"color:rgb(0,0,0)"> </span><span
style=3D"color:rgb(0,0,136)">typename</span><=
span
style=3D"color:rgb(0,0,0)"> </span><span
style=3D"color:rgb(102,102,0)">=3D</span><spa=
n
style=3D"color:rgb(0,0,0)"> </span><span
style=3D"color:rgb(0,0,136)">decltype</span><=
span
style=3D"color:rgb(102,102,0)">(</span><span
style=3D"color:rgb(0,0,0)">__tuple_struct</sp=
an><span
style=3D"color:rgb(102,102,0)"><</span><sp=
an
style=3D"color:rgb(102,0,102)">Args</span><sp=
an
style=3D"color:rgb(102,102,0)">...>{</span=
><span
style=3D"color:rgb(0,0,0)"> _1</span><span
style=3D"color:rgb(102,102,0)">,</span><span
style=3D"color:rgb(0,0,0)"> _2 </span><span
style=3D"color:rgb(102,102,0)">})></span><=
/span><span
style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)">=C2=A0 =C2=A0 </span=
><span
style=3D"color:rgb(0,0,136)">operator</span><sp=
an
style=3D"color:rgb(0,0,0)"> __tuple_struct</spa=
n><span
style=3D"color:rgb(102,102,0)"><</span><span
style=3D"color:rgb(102,0,102)">Args</span><span
style=3D"color:rgb(102,102,0)">...>()</span>=
</div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)"> =C2=A0 =C2=A0</span=
><span
style=3D"color:rgb(102,102,0)">{</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)"> =C2=A0 =C2=A0 =C2=
=A0 =C2=A0</span><span
style=3D"color:rgb(0,0,136)">return</span><span
style=3D"color:rgb(0,0,0)"> __tuple_struct</spa=
n><span
style=3D"color:rgb(102,102,0)"><</span><span
style=3D"color:rgb(102,0,102)">Args</span><span
style=3D"color:rgb(102,102,0)">...>{</span><=
span
style=3D"color:rgb(0,0,0)"> _1</span><span
style=3D"color:rgb(102,102,0)">,</span><span
style=3D"color:rgb(0,0,0)"> _2 </span><span
style=3D"color:rgb(102,102,0)">};</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)"> =C2=A0 =C2=A0</span=
><span
style=3D"color:rgb(102,102,0)">}</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)">=C2=A0 =C2=A0 </span=
><span
style=3D"color:rgb(0,0,136)">void</span><span
style=3D"color:rgb(0,0,0)"> swap</span><span
style=3D"color:rgb(102,102,0)">(</span><span
style=3D"color:rgb(0,0,0)">__tuple_struct</span=
><span
style=3D"color:rgb(102,102,0)">&</span><spa=
n
style=3D"color:rgb(0,0,0)"> other</span><span
style=3D"color:rgb(102,102,0)">);</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(102,102,0)">};</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,136)">template</span><sp=
an
style=3D"color:rgb(0,0,0)"> </span><span
style=3D"color:rgb(102,102,0)"><</span><span
style=3D"color:rgb(0,0,136)">typename</span><sp=
an
style=3D"color:rgb(0,0,0)"> </span><span
style=3D"color:rgb(102,102,0)">...</span><span
style=3D"color:rgb(102,0,102)">Ts</span><span
style=3D"color:rgb(102,102,0)">></span></div=
>
<div
style=3D"font-family:Arial,Helvetica,sans-serif;background-color:rgb(255,25=
5,255)"><span
style=3D"color:rgb(0,0,136)">using</span><span
style=3D"color:rgb(0,0,0)"> tuple </span><span
style=3D"color:rgb(102,102,0)">=3D</span><span
style=3D"color:rgb(0,0,0)"> __tuple_struct</spa=
n><span
style=3D"color:rgb(102,102,0)"><</span><span
style=3D"color:rgb(102,0,102)">Ts</span><span
style=3D"color:rgb(102,102,0)">...>;</span><=
/div>
</div>
</code></div>
<br>
<br>
</div>
<div>The tuple struct is almost implementable with
variadic templates in C++14 - except for the data
members.</div>
<div><br>
</div>
<div><br>
</div>
<div>If that's not clear yet, following implementation
is almost dead simple and you get most of current
std::tuple functionality for free - perfect
initialization, copy/move assignement, copy/move
construction, get<N>.</div>
</div>
</blockquote>
<div><br>
</div>
<div>There are interesting ways to implement tuples in C++14
already, like with something like this</div>
<div><br>
template<class... T><br>
struct tuple<br>
{<br>
=C2=A0 =C2=A0 tuple(T&&... t) :
data(init(std::forward<T>(t)...)) {}<br>
<br>
=C2=A0 =C2=A0 static auto init(T&&... xs)<br>
=C2=A0 =C2=A0 {=C2=A0<br>
</div>
<div>
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return [=3D](auto&& =
f)<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 {</div>
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return f(std::=
forward<T>(xs)...);</div>
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 };=C2=A0</div>
<div>=C2=A0 =C2=A0 }</div>
<div><br>
=C2=A0 =C2=A0 decltype(init(std::declval<T>()...)) da=
ta;</div>
<div>};</div>
</div>
<div><br>
</div>
<div>Note the members are stored in the capture list of the
lambda 'data', and you extract them by applying 'data' to
any function object as needed.</div>
</div>
<br>
</div>
</div>
<br>
</blockquote>
This is similar/inline with the operator extract defined by David
Sankel in his Blog [1]<br>
I'm wondering how the compiler optimizes the code when I want to
access just a member of a tuple.<br>
<br>
Vicente<br>
<br>
[1]
<a class=3D"moz-txt-link-freetext" href=3D"http://davidsankel.com/uncategor=
ized/c-language-support-for-pattern-matching-and-variants/">http://davidsan=
kel.com/uncategorized/c-language-support-for-pattern-matching-and-variants/=
</a><br>
</body>
</html>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/56FEBBEE.7020106%40wanadoo.fr?utm_med=
ium=3Demail&utm_source=3Dfooter">https://groups.google.com/a/isocpp.org/d/m=
sgid/std-proposals/56FEBBEE.7020106%40wanadoo.fr</a>.<br />
--------------080109030301000001030103--
.
Author: m.cencora@gmail.com
Date: Mon, 4 Apr 2016 07:21:49 -0700 (PDT)
Raw View
------=_Part_143_2110319844.1459779710116
Content-Type: multipart/alternative;
boundary="----=_Part_144_1694897782.1459779710117"
------=_Part_144_1694897782.1459779710117
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
This won't work e.g. for non-copyable types, since there is no way to=20
move-initialize lambda capture from pack expansion like here:
static auto init(Ts&&... us)
{
return [xs... =3D us...] (auto&& f)
{
return f(std::forward<Ts>(xs)...);
};
}
Regards,
Maciej
W dniu pi=C4=85tek, 1 kwietnia 2016 20:20:33 UTC+2 u=C5=BCytkownik Vicente =
J. Botet=20
Escriba napisa=C5=82:
>
> Le 01/04/2016 18:18, Mathias Gaunard a =C3=A9crit :
>
> On 15 February 2016 at 16:19, <m.ce...@gmail.com <javascript:>> wrote:
>
>> Hi,=20
>>
>> I think the structured binding proposal opens a possibility for major=20
>> simplification of std::tuple implementation.
>>
>> Let's take following "implementation" as an example:
>> template <typename ...T>
>> struct __tuple_struct;
>>
>> template <typename T1>
>> struct __tuple_struct<T1>
>> {
>> T1 _1;
>>
>> template <typename ...Args, typename =3D decltype(__tuple_struct<Arg=
s
>> ...>{ _1 })>
>> operator __tuple_struct<Args...>()
>> {
>> return __tuple_struct<Args...>{ _1 };
>> }
>>
>> void swap(__tuple_struct& other);
>> };
>>
>> template <typename T1, typename T2>
>> struct __tuple_struct<T1, T2>
>> {
>> T1 _1;
>> T2 _2;
>>
>> template <typename ...Args, typename =3D decltype(__tuple_struct<Args
>> ...>{ _1, _2 })>
>> operator __tuple_struct<Args...>()
>> {
>> return __tuple_struct<Args...>{ _1, _2 };
>> }
>>
>> void swap(__tuple_struct& other);
>> };
>>
>>
>> template <typename ...Ts>
>> using tuple =3D __tuple_struct<Ts...>;
>>
>>
>> The tuple struct is almost implementable with variadic templates in C++1=
4=20
>> - except for the data members.
>>
>>
>> If that's not clear yet, following implementation is almost dead simple=
=20
>> and you get most of current std::tuple functionality for free - perfect=
=20
>> initialization, copy/move assignement, copy/move construction, get<N>.
>>
>
> There are interesting ways to implement tuples in C++14 already, like wit=
h=20
> something like this
>
> template<class... T>
> struct tuple
> {
> tuple(T&&... t) : data(init(std::forward<T>(t)...)) {}
>
> static auto init(T&&... xs)
> {=20
> return [=3D](auto&& f)
> {
> return f(std::forward<T>(xs)...);
> };=20
> }
>
> decltype(init(std::declval<T>()...)) data;
> };
>
> Note the members are stored in the capture list of the lambda 'data', and=
=20
> you extract them by applying 'data' to any function object as needed.
>
>
> This is similar/inline with the operator extract defined by David Sankel=
=20
> in his Blog [1]
> I'm wondering how the compiler optimizes the code when I want to access=
=20
> just a member of a tuple.
>
> Vicente
>
> [1]=20
> http://davidsankel.com/uncategorized/c-language-support-for-pattern-match=
ing-and-variants/
>
--=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/d445948c-f623-4af7-be27-40288705bef6%40isocpp.or=
g.
------=_Part_144_1694897782.1459779710117
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>This won't work e.g. for non-copyable types, sinc=
e there is no way to move-initialize lambda capture from pack expansion lik=
e here:</div><div><div><br></div><div><div class=3D"prettyprint" style=3D"b=
order: 1px solid rgb(187, 187, 187); word-wrap: break-word; background-colo=
r: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"subpretty=
print"><div class=3D"subprettyprint"><span style=3D"font-family: Arial, Hel=
vetica, sans-serif;">static auto init(Ts&&... us)</span><br></div><=
div class=3D"subprettyprint">{</div><div class=3D"subprettyprint">=C2=A0 =
=C2=A0 return [xs... =3D us...] (auto&& f)</div><div class=3D"subpr=
ettyprint">=C2=A0 =C2=A0 {</div><div class=3D"subprettyprint">=C2=A0 =C2=A0=
=C2=A0 =C2=A0 return f(std::forward<Ts>(xs)...);</div><div class=3D"=
subprettyprint">=C2=A0 =C2=A0 };</div><div class=3D"subprettyprint">}</div>=
</div></code></div><br></div></div><div>Regards,</div><div>Maciej</div><br>=
W dniu pi=C4=85tek, 1 kwietnia 2016 20:20:33 UTC+2 u=C5=BCytkownik Vicente =
J. Botet Escriba napisa=C5=82:<blockquote class=3D"gmail_quote" style=3D"ma=
rgin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
=20
=20
=20
<div bgcolor=3D"#FFFFFF" text=3D"#000000">
<div>Le 01/04/2016 18:18, Mathias Gaunard a
=C3=A9crit=C2=A0:<br>
</div>
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div>
<div class=3D"gmail_quote">On 15 February 2016 at 16:19, <span di=
r=3D"ltr"><<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mail=
to=3D"aGMc_hB9AAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javasc=
ript:';return true;" onclick=3D"this.href=3D'javascript:';retur=
n true;">m.ce...@gmail.com</a>></span>
wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0=
..8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-s=
tyle:solid;padding-left:1ex">
<div dir=3D"ltr">Hi,
<div><br>
</div>
<div>I think the structured binding proposal opens a
possibility for major simplification of std::tuple
implementation.</div>
<div><br>
</div>
<div>Let's take following "implementation" as=
an
example:</div>
<div>
<div style=3D"border:1px solid rgb(187,187,187);word-wrap=
:break-word;background-color:rgb(250,250,250)"><code>
<div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,136)">tem=
plate</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:r=
gb(102,102,0)"><</span><span style=3D"color:rgb(0,0,136)">typename</span=
><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,=
0)">...</span><span style=3D"color:rgb(0,0,0)">T</span><span style=3D"color=
:rgb(102,102,0)">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,136)">str=
uct</span><span style=3D"color:rgb(0,0,0)"> __tuple_struct</span><span styl=
e=3D"color:rgb(102,102,0)">;</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,136)">tem=
plate</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:r=
gb(102,102,0)"><</span><span style=3D"color:rgb(0,0,136)">typename</span=
><span style=3D"color:rgb(0,0,0)"> T1</span><span style=3D"color:rgb(102,10=
2,0)">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,136)">str=
uct</span><span style=3D"color:rgb(0,0,0)"> __tuple_struct</span><span styl=
e=3D"color:rgb(102,102,0)"><</span><span style=3D"color:rgb(0,0,0)">T1</=
span><span style=3D"color:rgb(102,102,0)">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(102,102,0)">{=
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"> =C2=
=A0 =C2=A0T1 _1</span><span style=3D"color:rgb(102,102,0)">;</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)">=C2=
=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)">template</span><span s=
tyle=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)"><=
</span><span style=3D"color:rgb(0,0,136)">typename</span><span style=3D"col=
or:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">...</span><span=
style=3D"color:rgb(102,0,102)">Args</span><span style=3D"color:rgb(102,102=
,0)">,</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:=
rgb(0,0,136)">typename</span><span style=3D"color:rgb(0,0,0)"> </span><span=
style=3D"color:rgb(102,102,0)">=3D</span><span style=3D"color:rgb(0,0,0)">=
</span><span style=3D"color:rgb(0,0,136)">decltype</span><span style=3D"co=
lor:rgb(102,102,0)">(</span><span style=3D"color:rgb(0,0,0)">__tuple_struct=
</span><span style=3D"color:rgb(102,102,0)"><</span><span style=3D"color=
:rgb(102,0,102)">Args</span><span style=3D"color:rgb(102,102,0)">..<wbr>.&g=
t;{</span><span style=3D"color:rgb(0,0,0)"> _1 </span><span style=3D"color:=
rgb(102,102,0)">})></span><span style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)">=C2=
=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)">operator</span><span s=
tyle=3D"color:rgb(0,0,0)"> __tuple_struct</span><span style=3D"color:rgb(10=
2,102,0)"><</span><span style=3D"color:rgb(102,0,102)">Args</span><span =
style=3D"color:rgb(102,102,0)">...>()</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"> =C2=
=A0 =C2=A0</span><span style=3D"color:rgb(102,102,0)">{</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"> =C2=
=A0 =C2=A0 =C2=A0 =C2=A0</span><span style=3D"color:rgb(0,0,136)">return</s=
pan><span style=3D"color:rgb(0,0,0)"> __tuple_struct</span><span style=3D"c=
olor:rgb(102,102,0)"><</span><span style=3D"color:rgb(102,0,102)">Args</=
span><span style=3D"color:rgb(102,102,0)">...>{</span><span style=3D"col=
or:rgb(0,0,0)"> _1 </span><span style=3D"color:rgb(102,102,0)">};</span></d=
iv>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"> =C2=
=A0 =C2=A0</span><span style=3D"color:rgb(102,102,0)">}</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)">=C2=
=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)">void</span><span style=
=3D"color:rgb(0,0,0)"> swap</span><span style=3D"color:rgb(102,102,0)">(</s=
pan><span style=3D"color:rgb(0,0,0)">__tuple_struct</span><span style=3D"co=
lor:rgb(102,102,0)">&</span><span style=3D"color:rgb(0,0,0)"> other</sp=
an><span style=3D"color:rgb(102,102,0)">);</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(102,102,0)">}=
;</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,136)">tem=
plate</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:r=
gb(102,102,0)"><</span><span style=3D"color:rgb(0,0,136)">typename</span=
><span style=3D"color:rgb(0,0,0)"> T1</span><span style=3D"color:rgb(102,10=
2,0)">,</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color=
:rgb(0,0,136)">typename</span><span style=3D"color:rgb(0,0,0)"> T2</span><s=
pan style=3D"color:rgb(102,102,0)">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,136)">str=
uct</span><span style=3D"color:rgb(0,0,0)"> __tuple_struct</span><span styl=
e=3D"color:rgb(102,102,0)"><</span><span style=3D"color:rgb(0,0,0)">T1</=
span><span style=3D"color:rgb(102,102,0)">,</span><span style=3D"color:rgb(=
0,0,0)"> T2</span><span style=3D"color:rgb(102,102,0)">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(102,102,0)">{=
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"> =C2=
=A0 =C2=A0T1 _1</span><span style=3D"color:rgb(102,102,0)">;</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"> =C2=
=A0 =C2=A0T2 _2</span><span style=3D"color:rgb(102,102,0)">;</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(136,0,0)"><sp=
an style=3D"color:rgb(0,0,0)">=C2=A0 =C2=A0</span><span style=3D"color:rgb(=
0,0,136)">template</span><span style=3D"color:rgb(0,0,0)"> </span><span sty=
le=3D"color:rgb(102,102,0)"><</span><span style=3D"color:rgb(0,0,136)">t=
ypename</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color=
:rgb(102,102,0)">...</span><span style=3D"color:rgb(102,0,102)">Args</span>=
<span style=3D"color:rgb(102,102,0)">,</span><span style=3D"color:rgb(0,0,0=
)"> </span><span style=3D"color:rgb(0,0,136)">typename</span><span style=3D=
"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">=3D</span><=
span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">=
decltype</span><span style=3D"color:rgb(102,102,0)">(</span><span style=3D"=
color:rgb(0,0,0)">__tuple_struct</span><span style=3D"color:rgb(102,102,0)"=
><</span><span style=3D"color:rgb(102,0,102)">Args</span><span style=3D"=
color:rgb(102,102,0)">..<wbr>.>{</span><span style=3D"color:rgb(0,0,0)">=
_1</span><span style=3D"color:rgb(102,102,0)">,</span><span style=3D"color=
:rgb(0,0,0)"> _2 </span><span style=3D"color:rgb(102,102,0)">})></span><=
/span><span style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)">=C2=
=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)">operator</span><span s=
tyle=3D"color:rgb(0,0,0)"> __tuple_struct</span><span style=3D"color:rgb(10=
2,102,0)"><</span><span style=3D"color:rgb(102,0,102)">Args</span><span =
style=3D"color:rgb(102,102,0)">...>()</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"> =C2=
=A0 =C2=A0</span><span style=3D"color:rgb(102,102,0)">{</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"> =C2=
=A0 =C2=A0 =C2=A0 =C2=A0</span><span style=3D"color:rgb(0,0,136)">return</s=
pan><span style=3D"color:rgb(0,0,0)"> __tuple_struct</span><span style=3D"c=
olor:rgb(102,102,0)"><</span><span style=3D"color:rgb(102,0,102)">Args</=
span><span style=3D"color:rgb(102,102,0)">...>{</span><span style=3D"col=
or:rgb(0,0,0)"> _1</span><span style=3D"color:rgb(102,102,0)">,</span><span=
style=3D"color:rgb(0,0,0)"> _2 </span><span style=3D"color:rgb(102,102,0)"=
>};</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"> =C2=
=A0 =C2=A0</span><span style=3D"color:rgb(102,102,0)">}</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)">=C2=
=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)">void</span><span style=
=3D"color:rgb(0,0,0)"> swap</span><span style=3D"color:rgb(102,102,0)">(</s=
pan><span style=3D"color:rgb(0,0,0)">__tuple_struct</span><span style=3D"co=
lor:rgb(102,102,0)">&</span><span style=3D"color:rgb(0,0,0)"> other</sp=
an><span style=3D"color:rgb(102,102,0)">);</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(102,102,0)">}=
;</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,136)">tem=
plate</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:r=
gb(102,102,0)"><</span><span style=3D"color:rgb(0,0,136)">typename</span=
><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,=
0)">...</span><span style=3D"color:rgb(102,0,102)">Ts</span><span style=3D"=
color:rgb(102,102,0)">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,136)">usi=
ng</span><span style=3D"color:rgb(0,0,0)"> tuple </span><span style=3D"colo=
r:rgb(102,102,0)">=3D</span><span style=3D"color:rgb(0,0,0)"> __tuple_struc=
t</span><span style=3D"color:rgb(102,102,0)"><</span><span style=3D"colo=
r:rgb(102,0,102)">Ts</span><span style=3D"color:rgb(102,102,0)">...>;</s=
pan></div>
</div>
</code></div>
<br>
<br>
</div>
<div>The tuple struct is almost implementable with
variadic templates in C++14 - except for the data
members.</div>
<div><br>
</div>
<div><br>
</div>
<div>If that's not clear yet, following implementation
is almost dead simple and you get most of current
std::tuple functionality for free - perfect
initialization, copy/move assignement, copy/move
construction, get<N>.</div>
</div>
</blockquote>
<div><br>
</div>
<div>There are interesting ways to implement tuples in C++14
already, like with something like this</div>
<div><br>
template<class... T><br>
struct tuple<br>
{<br>
=C2=A0 =C2=A0 tuple(T&&... t) :
data(init(std::forward<T>(t)..<wbr>.)) {}<br>
<br>
=C2=A0 =C2=A0 static auto init(T&&... xs)<br>
=C2=A0 =C2=A0 {=C2=A0<br>
</div>
<div>
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return [=3D](auto&& =
f)<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 {</div>
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return f(std::=
forward<T>(xs)...);</div>
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 };=C2=A0</div>
<div>=C2=A0 =C2=A0 }</div>
<div><br>
=C2=A0 =C2=A0 decltype(init(std::declval<T>(<wbr>)...=
)) data;</div>
<div>};</div>
</div>
<div><br>
</div>
<div>Note the members are stored in the capture list of the
lambda 'data', and you extract them by applying '=
data' to
any function object as needed.</div>
</div>
<br>
</div>
</div>
<br>
</blockquote>
This is similar/inline with the operator extract defined by David
Sankel in his Blog [1]<br>
I'm wondering how the compiler optimizes the code when I want to
access just a member of a tuple.<br>
<br>
Vicente<br>
<br>
[1]
<a href=3D"http://davidsankel.com/uncategorized/c-language-support-for-patt=
ern-matching-and-variants/" target=3D"_blank" rel=3D"nofollow" onmousedown=
=3D"this.href=3D'http://www.google.com/url?q\75http%3A%2F%2Fdavidsankel=
..com%2Funcategorized%2Fc-language-support-for-pattern-matching-and-variants=
%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNHVmo-ZTUeo0s_uitRiB7aDpxZ3Qw';re=
turn true;" onclick=3D"this.href=3D'http://www.google.com/url?q\75http%=
3A%2F%2Fdavidsankel.com%2Funcategorized%2Fc-language-support-for-pattern-ma=
tching-and-variants%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNHVmo-ZTUeo0s_uitR=
iB7aDpxZ3Qw';return true;">http://davidsankel.com/<wbr>uncategorized/c-=
language-<wbr>support-for-pattern-matching-<wbr>and-variants/</a><br>
</div>
</blockquote></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/d445948c-f623-4af7-be27-40288705bef6%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/d445948c-f623-4af7-be27-40288705bef6=
%40isocpp.org</a>.<br />
------=_Part_144_1694897782.1459779710117--
------=_Part_143_2110319844.1459779710116--
.
Author: Richard Smith <richard@metafoo.co.uk>
Date: Mon, 4 Apr 2016 11:34:26 -0700
Raw View
--047d7bdc07ac7e4e59052facfa6c
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Mon, Apr 4, 2016 at 7:21 AM, <m.cencora@gmail.com> wrote:
> This won't work e.g. for non-copyable types, since there is no way to
> move-initialize lambda capture from pack expansion like here:
>
> static auto init(Ts&&... us)
> {
> return [xs... =3D us...] (auto&& f)
>
[xs... =3D std::forward<Ts>(us)...]
> {
> return f(std::forward<Ts>(xs)...);
> };
> }
>
> Regards,
> Maciej
>
> W dniu pi=C4=85tek, 1 kwietnia 2016 20:20:33 UTC+2 u=C5=BCytkownik Vicent=
e J. Botet
> Escriba napisa=C5=82:
>>
>> Le 01/04/2016 18:18, Mathias Gaunard a =C3=A9crit :
>>
>> On 15 February 2016 at 16:19, <m.ce...@gmail.com> wrote:
>>
>>> Hi,
>>>
>>> I think the structured binding proposal opens a possibility for major
>>> simplification of std::tuple implementation.
>>>
>>> Let's take following "implementation" as an example:
>>> template <typename ...T>
>>> struct __tuple_struct;
>>>
>>> template <typename T1>
>>> struct __tuple_struct<T1>
>>> {
>>> T1 _1;
>>>
>>> template <typename ...Args, typename =3D decltype(__tuple_struct<Ar=
gs
>>> ...>{ _1 })>
>>> operator __tuple_struct<Args...>()
>>> {
>>> return __tuple_struct<Args...>{ _1 };
>>> }
>>>
>>> void swap(__tuple_struct& other);
>>> };
>>>
>>> template <typename T1, typename T2>
>>> struct __tuple_struct<T1, T2>
>>> {
>>> T1 _1;
>>> T2 _2;
>>>
>>> template <typename ...Args, typename =3D decltype(__tuple_struct<Arg=
s
>>> ...>{ _1, _2 })>
>>> operator __tuple_struct<Args...>()
>>> {
>>> return __tuple_struct<Args...>{ _1, _2 };
>>> }
>>>
>>> void swap(__tuple_struct& other);
>>> };
>>>
>>>
>>> template <typename ...Ts>
>>> using tuple =3D __tuple_struct<Ts...>;
>>>
>>>
>>> The tuple struct is almost implementable with variadic templates in
>>> C++14 - except for the data members.
>>>
>>>
>>> If that's not clear yet, following implementation is almost dead simple
>>> and you get most of current std::tuple functionality for free - perfect
>>> initialization, copy/move assignement, copy/move construction, get<N>.
>>>
>>
>> There are interesting ways to implement tuples in C++14 already, like
>> with something like this
>>
>> template<class... T>
>> struct tuple
>> {
>> tuple(T&&... t) : data(init(std::forward<T>(t)...)) {}
>>
>> static auto init(T&&... xs)
>> {
>> return [=3D](auto&& f)
>> {
>> return f(std::forward<T>(xs)...);
>> };
>> }
>>
>> decltype(init(std::declval<T>()...)) data;
>> };
>>
>> Note the members are stored in the capture list of the lambda 'data', an=
d
>> you extract them by applying 'data' to any function object as needed.
>>
>>
>> This is similar/inline with the operator extract defined by David Sankel
>> in his Blog [1]
>> I'm wondering how the compiler optimizes the code when I want to access
>> just a member of a tuple.
>>
>> Vicente
>>
>> [1]
>> http://davidsankel.com/uncategorized/c-language-support-for-pattern-matc=
hing-and-variants/
>>
> --
> 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/d445948c-f62=
3-4af7-be27-40288705bef6%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/d445948c-f6=
23-4af7-be27-40288705bef6%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoot=
er>
> .
>
--=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/CAOfiQqmCtbYFrXjKqABc%2B%2BbYkPBP3Z_6K2FF9z%3Du3=
W%2B%3Dj-H_HQ%40mail.gmail.com.
--047d7bdc07ac7e4e59052facfa6c
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On M=
on, Apr 4, 2016 at 7:21 AM, <span dir=3D"ltr"><<a href=3D"mailto:m.cenc=
ora@gmail.com" target=3D"_blank">m.cencora@gmail.com</a>></span> wrote:<=
br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left=
:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>This won't work=
e.g. for non-copyable types, since there is no way to move-initialize lamb=
da capture from pack expansion like here:</div><div><div><br></div><div><di=
v style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;backgroun=
d-color:rgb(250,250,250)"><code><div><div><span style=3D"font-family:Arial,=
Helvetica,sans-serif">static auto init(Ts&&... us)</span><br></div>=
<div>{</div><div>=C2=A0 =C2=A0 return [xs... =3D us...] (auto&& f)<=
/div></div></code></div></div></div></div></blockquote><div><br></div><div>=
[xs... =3D std::forward<Ts>(us)...]</div><div>=C2=A0</div><blockquote=
class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc soli=
d;padding-left:1ex"><div dir=3D"ltr"><div><div><div style=3D"border:1px sol=
id rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,250,250)"=
><code><div><div>=C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 retu=
rn f(std::forward<Ts>(xs)...);</div><div>=C2=A0 =C2=A0 };</div><div>}=
</div></div></code></div><br></div></div><div>Regards,</div><div>Maciej</di=
v><span class=3D""><br>W dniu pi=C4=85tek, 1 kwietnia 2016 20:20:33 UTC+2 u=
=C5=BCytkownik Vicente J. Botet Escriba napisa=C5=82:</span><blockquote cla=
ss=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc=
solid;padding-left:1ex">
=20
=20
=20
<div bgcolor=3D"#FFFFFF" text=3D"#000000"><span class=3D"">
<div>Le 01/04/2016 18:18, Mathias Gaunard a
=C3=A9crit=C2=A0:<br>
</div>
</span><div><div class=3D"h5"><blockquote type=3D"cite">
<div dir=3D"ltr">
<div>
<div class=3D"gmail_quote">On 15 February 2016 at 16:19, <span di=
r=3D"ltr"><<a rel=3D"nofollow">m.ce...@gmail.com</a>></span>
wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0=
..8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-s=
tyle:solid;padding-left:1ex">
<div dir=3D"ltr">Hi,
<div><br>
</div>
<div>I think the structured binding proposal opens a
possibility for major simplification of std::tuple
implementation.</div>
<div><br>
</div>
<div>Let's take following "implementation" as=
an
example:</div>
<div>
<div style=3D"border:1px solid rgb(187,187,187);word-wrap=
:break-word;background-color:rgb(250,250,250)"><code>
<div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,136)">tem=
plate</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:r=
gb(102,102,0)"><</span><span style=3D"color:rgb(0,0,136)">typename</span=
><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,=
0)">...</span><span style=3D"color:rgb(0,0,0)">T</span><span style=3D"color=
:rgb(102,102,0)">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,136)">str=
uct</span><span style=3D"color:rgb(0,0,0)"> __tuple_struct</span><span styl=
e=3D"color:rgb(102,102,0)">;</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,136)">tem=
plate</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:r=
gb(102,102,0)"><</span><span style=3D"color:rgb(0,0,136)">typename</span=
><span style=3D"color:rgb(0,0,0)"> T1</span><span style=3D"color:rgb(102,10=
2,0)">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,136)">str=
uct</span><span style=3D"color:rgb(0,0,0)"> __tuple_struct</span><span styl=
e=3D"color:rgb(102,102,0)"><</span><span style=3D"color:rgb(0,0,0)">T1</=
span><span style=3D"color:rgb(102,102,0)">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(102,102,0)">{=
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"> =C2=
=A0 =C2=A0T1 _1</span><span style=3D"color:rgb(102,102,0)">;</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)">=C2=
=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)">template</span><span s=
tyle=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)"><=
</span><span style=3D"color:rgb(0,0,136)">typename</span><span style=3D"col=
or:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">...</span><span=
style=3D"color:rgb(102,0,102)">Args</span><span style=3D"color:rgb(102,102=
,0)">,</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:=
rgb(0,0,136)">typename</span><span style=3D"color:rgb(0,0,0)"> </span><span=
style=3D"color:rgb(102,102,0)">=3D</span><span style=3D"color:rgb(0,0,0)">=
</span><span style=3D"color:rgb(0,0,136)">decltype</span><span style=3D"co=
lor:rgb(102,102,0)">(</span><span style=3D"color:rgb(0,0,0)">__tuple_struct=
</span><span style=3D"color:rgb(102,102,0)"><</span><span style=3D"color=
:rgb(102,0,102)">Args</span><span style=3D"color:rgb(102,102,0)">...>{</=
span><span style=3D"color:rgb(0,0,0)"> _1 </span><span style=3D"color:rgb(1=
02,102,0)">})></span><span style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)">=C2=
=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)">operator</span><span s=
tyle=3D"color:rgb(0,0,0)"> __tuple_struct</span><span style=3D"color:rgb(10=
2,102,0)"><</span><span style=3D"color:rgb(102,0,102)">Args</span><span =
style=3D"color:rgb(102,102,0)">...>()</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"> =C2=
=A0 =C2=A0</span><span style=3D"color:rgb(102,102,0)">{</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"> =C2=
=A0 =C2=A0 =C2=A0 =C2=A0</span><span style=3D"color:rgb(0,0,136)">return</s=
pan><span style=3D"color:rgb(0,0,0)"> __tuple_struct</span><span style=3D"c=
olor:rgb(102,102,0)"><</span><span style=3D"color:rgb(102,0,102)">Args</=
span><span style=3D"color:rgb(102,102,0)">...>{</span><span style=3D"col=
or:rgb(0,0,0)"> _1 </span><span style=3D"color:rgb(102,102,0)">};</span></d=
iv>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"> =C2=
=A0 =C2=A0</span><span style=3D"color:rgb(102,102,0)">}</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)">=C2=
=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)">void</span><span style=
=3D"color:rgb(0,0,0)"> swap</span><span style=3D"color:rgb(102,102,0)">(</s=
pan><span style=3D"color:rgb(0,0,0)">__tuple_struct</span><span style=3D"co=
lor:rgb(102,102,0)">&</span><span style=3D"color:rgb(0,0,0)"> other</sp=
an><span style=3D"color:rgb(102,102,0)">);</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(102,102,0)">}=
;</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,136)">tem=
plate</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:r=
gb(102,102,0)"><</span><span style=3D"color:rgb(0,0,136)">typename</span=
><span style=3D"color:rgb(0,0,0)"> T1</span><span style=3D"color:rgb(102,10=
2,0)">,</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color=
:rgb(0,0,136)">typename</span><span style=3D"color:rgb(0,0,0)"> T2</span><s=
pan style=3D"color:rgb(102,102,0)">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,136)">str=
uct</span><span style=3D"color:rgb(0,0,0)"> __tuple_struct</span><span styl=
e=3D"color:rgb(102,102,0)"><</span><span style=3D"color:rgb(0,0,0)">T1</=
span><span style=3D"color:rgb(102,102,0)">,</span><span style=3D"color:rgb(=
0,0,0)"> T2</span><span style=3D"color:rgb(102,102,0)">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(102,102,0)">{=
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"> =C2=
=A0 =C2=A0T1 _1</span><span style=3D"color:rgb(102,102,0)">;</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"> =C2=
=A0 =C2=A0T2 _2</span><span style=3D"color:rgb(102,102,0)">;</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(136,0,0)"><sp=
an style=3D"color:rgb(0,0,0)">=C2=A0 =C2=A0</span><span style=3D"color:rgb(=
0,0,136)">template</span><span style=3D"color:rgb(0,0,0)"> </span><span sty=
le=3D"color:rgb(102,102,0)"><</span><span style=3D"color:rgb(0,0,136)">t=
ypename</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color=
:rgb(102,102,0)">...</span><span style=3D"color:rgb(102,0,102)">Args</span>=
<span style=3D"color:rgb(102,102,0)">,</span><span style=3D"color:rgb(0,0,0=
)"> </span><span style=3D"color:rgb(0,0,136)">typename</span><span style=3D=
"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">=3D</span><=
span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(0,0,136)">=
decltype</span><span style=3D"color:rgb(102,102,0)">(</span><span style=3D"=
color:rgb(0,0,0)">__tuple_struct</span><span style=3D"color:rgb(102,102,0)"=
><</span><span style=3D"color:rgb(102,0,102)">Args</span><span style=3D"=
color:rgb(102,102,0)">...>{</span><span style=3D"color:rgb(0,0,0)"> _1</=
span><span style=3D"color:rgb(102,102,0)">,</span><span style=3D"color:rgb(=
0,0,0)"> _2 </span><span style=3D"color:rgb(102,102,0)">})></span></span=
><span style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)">=C2=
=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)">operator</span><span s=
tyle=3D"color:rgb(0,0,0)"> __tuple_struct</span><span style=3D"color:rgb(10=
2,102,0)"><</span><span style=3D"color:rgb(102,0,102)">Args</span><span =
style=3D"color:rgb(102,102,0)">...>()</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"> =C2=
=A0 =C2=A0</span><span style=3D"color:rgb(102,102,0)">{</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"> =C2=
=A0 =C2=A0 =C2=A0 =C2=A0</span><span style=3D"color:rgb(0,0,136)">return</s=
pan><span style=3D"color:rgb(0,0,0)"> __tuple_struct</span><span style=3D"c=
olor:rgb(102,102,0)"><</span><span style=3D"color:rgb(102,0,102)">Args</=
span><span style=3D"color:rgb(102,102,0)">...>{</span><span style=3D"col=
or:rgb(0,0,0)"> _1</span><span style=3D"color:rgb(102,102,0)">,</span><span=
style=3D"color:rgb(0,0,0)"> _2 </span><span style=3D"color:rgb(102,102,0)"=
>};</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"> =C2=
=A0 =C2=A0</span><span style=3D"color:rgb(102,102,0)">}</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)">=C2=
=A0 =C2=A0 </span><span style=3D"color:rgb(0,0,136)">void</span><span style=
=3D"color:rgb(0,0,0)"> swap</span><span style=3D"color:rgb(102,102,0)">(</s=
pan><span style=3D"color:rgb(0,0,0)">__tuple_struct</span><span style=3D"co=
lor:rgb(102,102,0)">&</span><span style=3D"color:rgb(0,0,0)"> other</sp=
an><span style=3D"color:rgb(102,102,0)">);</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(102,102,0)">}=
;</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,0)"><br>
</span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,136)">tem=
plate</span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:r=
gb(102,102,0)"><</span><span style=3D"color:rgb(0,0,136)">typename</span=
><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,=
0)">...</span><span style=3D"color:rgb(102,0,102)">Ts</span><span style=3D"=
color:rgb(102,102,0)">></span></div>
<div style=3D"font-family:Arial,Helvetica,sans-seri=
f;background-color:rgb(255,255,255)"><span style=3D"color:rgb(0,0,136)">usi=
ng</span><span style=3D"color:rgb(0,0,0)"> tuple </span><span style=3D"colo=
r:rgb(102,102,0)">=3D</span><span style=3D"color:rgb(0,0,0)"> __tuple_struc=
t</span><span style=3D"color:rgb(102,102,0)"><</span><span style=3D"colo=
r:rgb(102,0,102)">Ts</span><span style=3D"color:rgb(102,102,0)">...>;</s=
pan></div>
</div>
</code></div>
<br>
<br>
</div>
<div>The tuple struct is almost implementable with
variadic templates in C++14 - except for the data
members.</div>
<div><br>
</div>
<div><br>
</div>
<div>If that's not clear yet, following implementation
is almost dead simple and you get most of current
std::tuple functionality for free - perfect
initialization, copy/move assignement, copy/move
construction, get<N>.</div>
</div>
</blockquote>
<div><br>
</div>
<div>There are interesting ways to implement tuples in C++14
already, like with something like this</div>
<div><br>
template<class... T><br>
struct tuple<br>
{<br>
=C2=A0 =C2=A0 tuple(T&&... t) :
data(init(std::forward<T>(t)...)) {}<br>
<br>
=C2=A0 =C2=A0 static auto init(T&&... xs)<br>
=C2=A0 =C2=A0 {=C2=A0<br>
</div>
<div>
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return [=3D](auto&& =
f)<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 {</div>
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return f(std::=
forward<T>(xs)...);</div>
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 };=C2=A0</div>
<div>=C2=A0 =C2=A0 }</div>
<div><br>
=C2=A0 =C2=A0 decltype(init(std::declval<T>()...)) da=
ta;</div>
<div>};</div>
</div>
<div><br>
</div>
<div>Note the members are stored in the capture list of the
lambda 'data', and you extract them by applying '=
data' to
any function object as needed.</div>
</div>
<br>
</div>
</div>
<br>
</blockquote>
This is similar/inline with the operator extract defined by David
Sankel in his Blog [1]<br>
I'm wondering how the compiler optimizes the code when I want to
access just a member of a tuple.<br>
<br>
Vicente<br>
<br>
[1]
<a href=3D"http://davidsankel.com/uncategorized/c-language-support-for-patt=
ern-matching-and-variants/" rel=3D"nofollow" target=3D"_blank">http://david=
sankel.com/uncategorized/c-language-support-for-pattern-matching-and-varian=
ts/</a><br>
</div></div></div>
</blockquote></div><div><div class=3D"h5">
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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></div></div>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/d445948c-f623-4af7-be27-40288705bef6%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/d445948c-f623-=
4af7-be27-40288705bef6%40isocpp.org</a>.<br>
</blockquote></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" 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/CAOfiQqmCtbYFrXjKqABc%2B%2BbYkPBP3Z_6=
K2FF9z%3Du3W%2B%3Dj-H_HQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Df=
ooter">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAOfiQq=
mCtbYFrXjKqABc%2B%2BbYkPBP3Z_6K2FF9z%3Du3W%2B%3Dj-H_HQ%40mail.gmail.com</a>=
..<br />
--047d7bdc07ac7e4e59052facfa6c--
.
Author: Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
Date: Mon, 4 Apr 2016 21:45:37 -0700 (PDT)
Raw View
------=_Part_424_1841098.1459831537503
Content-Type: multipart/alternative;
boundary="----=_Part_425_2044590689.1459831537503"
------=_Part_425_2044590689.1459831537503
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Monday, April 4, 2016 at 11:34:29 AM UTC-7, Richard Smith wrote:
>
> On Mon, Apr 4, 2016 at 7:21 AM, <m.ce...@gmail.com <javascript:>> wrote:
>
>> This won't work e.g. for non-copyable types, since there is no way to=20
>> move-initialize lambda capture from pack expansion like here:
>>
>> static auto init(Ts&&... us)
>> {
>> return [xs... =3D us...] (auto&& f)
>>
>
> [xs... =3D std::forward<Ts>(us)...]
>
Either this is an extremely new feature of C++1z, or you are=20
(uncharacteristically) mistaken. At least in C++14, one can't use=20
generalized init-capture to capture a pack, because that would create a=20
closure type containing a "pack of non-static data members", which isn't a=
=20
thing.
http://stackoverflow.com/questions/31556026/using-stdbind-to-capture-a-para=
meter-pack-by-move
http://stackoverflow.com/questions/24816557/generalized-lambda-capture-on-p=
aram-pack
=E2=80=93Arthur
--=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/a2ea1907-9137-41d1-8342-21a2e06ead04%40isocpp.or=
g.
------=_Part_425_2044590689.1459831537503
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Monday, April 4, 2016 at 11:34:29 AM UTC-7, Richard Smi=
th wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: =
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div=
><div class=3D"gmail_quote">On Mon, Apr 4, 2016 at 7:21 AM, <span dir=3D"l=
tr"><<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
0vMwXJFpAQAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:&=
#39;;return true;" onclick=3D"this.href=3D'javascript:';return true=
;">m.ce...@gmail.com</a>></span> wrote:<br><blockquote class=3D"gmail_qu=
ote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex=
"><div dir=3D"ltr"><div>This won't work e.g. for non-copyable types, si=
nce there is no way to move-initialize lambda capture from pack expansion l=
ike here:</div><div><div><br></div><div><div style=3D"border:1px solid rgb(=
187,187,187);word-wrap:break-word;background-color:rgb(250,250,250)"><code>=
<div><div><span style=3D"font-family:Arial,Helvetica,sans-serif">static aut=
o init(Ts&&... us)</span><br></div><div>{</div><div>=C2=A0 =C2=A0 r=
eturn [xs... =3D us...] (auto&& f)</div></div></code></div></div></=
div></div></blockquote><div><br></div><div>[xs... =3D std::forward<Ts>=
;(us)...]</div></div></div></div></blockquote><div><br></div><div>Either th=
is is an extremely new feature of C++1z, or you are (uncharacteristically) =
mistaken. At least in C++14, one can't use generalized init-capture to =
capture a pack, because that would create a closure type containing a "=
;pack of non-static data members", which isn't a thing.</div><div>=
<br></div><div>http://stackoverflow.com/questions/31556026/using-stdbind-to=
-capture-a-parameter-pack-by-move</div><div>http://stackoverflow.com/questi=
ons/24816557/generalized-lambda-capture-on-param-pack<br></div><div><br></d=
iv><div>=E2=80=93Arthur</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/a2ea1907-9137-41d1-8342-21a2e06ead04%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/a2ea1907-9137-41d1-8342-21a2e06ead04=
%40isocpp.org</a>.<br />
------=_Part_425_2044590689.1459831537503--
------=_Part_424_1841098.1459831537503--
.
Author: Richard Smith <richard@metafoo.co.uk>
Date: Tue, 5 Apr 2016 11:42:28 -0700
Raw View
--089e0158b30611b75b052fc1357c
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Mon, Apr 4, 2016 at 9:45 PM, Arthur O'Dwyer <arthur.j.odwyer@gmail.com>
wrote:
> On Monday, April 4, 2016 at 11:34:29 AM UTC-7, Richard Smith wrote:
>>
>> On Mon, Apr 4, 2016 at 7:21 AM, <m.ce...@gmail.com> wrote:
>>
>>> This won't work e.g. for non-copyable types, since there is no way to
>>> move-initialize lambda capture from pack expansion like here:
>>>
>>> static auto init(Ts&&... us)
>>> {
>>> return [xs... =3D us...] (auto&& f)
>>>
>>
>> [xs... =3D std::forward<Ts>(us)...]
>>
>
> Either this is an extremely new feature of C++1z, or you are
> (uncharacteristically) mistaken. At least in C++14, one can't use
> generalized init-capture to capture a pack,
>
Good point :) So we need a fun workaround. Something like this:
template<typename ...Ts> struct tuple {
template<typename T> struct implicit_move {
T t;
implicit_move(T &t) : t(std::forward<T>(t)) {}
implicit_move(implicit_move &o) : t(std::forward<T>(o.t)) {}
implicit_move(implicit_move &&o) : t(std::move(o.t)) {}
};
static auto init(Ts &&...us) {
return [] (implicit_move<Ts> ...us) {
return [us...] (auto &&f) { return f(us.t...); };
} (us...);
}
decltype(init(std::declval<Ts>()...)) storage;
tuple(Ts &&...ts) : storage(init(std::forward<Ts>(ts)...)) {}
template<typename F> auto apply(F &&f) { return storage(f); }
};
because that would create a closure type containing a "pack of non-static
> data members", which isn't a thing.
>
>
> http://stackoverflow.com/questions/31556026/using-stdbind-to-capture-a-pa=
rameter-pack-by-move
>
> http://stackoverflow.com/questions/24816557/generalized-lambda-capture-on=
-param-pack
>
> =E2=80=93Arthur
>
> --
> 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/a2ea1907-913=
7-41d1-8342-21a2e06ead04%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/a2ea1907-91=
37-41d1-8342-21a2e06ead04%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoot=
er>
> .
>
--=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/CAOfiQqmQ1v1aoGXjvRALjkR2od29QZFcrMf7AbNqh%2Boz-=
4-qng%40mail.gmail.com.
--089e0158b30611b75b052fc1357c
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On M=
on, Apr 4, 2016 at 9:45 PM, Arthur O'Dwyer <span dir=3D"ltr"><<a hre=
f=3D"mailto:arthur.j.odwyer@gmail.com" target=3D"_blank">arthur.j.odwyer@gm=
ail.com</a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D=
"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,2=
04,204);border-left-style:solid;padding-left:1ex"><div dir=3D"ltr">On Monda=
y, April 4, 2016 at 11:34:29 AM UTC-7, Richard Smith wrote:<span class=3D""=
><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border=
-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;=
padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"gmail_quote">On Mon, =
Apr 4, 2016 at 7:21 AM, <span dir=3D"ltr"><<a rel=3D"nofollow">m.ce...@=
gmail.com</a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=
=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(20=
4,204,204);border-left-style:solid;padding-left:1ex"><div dir=3D"ltr"><div>=
This won't work e.g. for non-copyable types, since there is no way to m=
ove-initialize lambda capture from pack expansion like here:</div><div><div=
><br></div><div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:b=
reak-word;background-color:rgb(250,250,250)"><code><div><div><span style=3D=
"font-family:Arial,Helvetica,sans-serif">static auto init(Ts&&... u=
s)</span><br></div><div>{</div><div>=C2=A0 =C2=A0 return [xs... =3D us...] =
(auto&& f)</div></div></code></div></div></div></div></blockquote><=
div><br></div><div>[xs... =3D std::forward<Ts>(us)...]</div></div></d=
iv></div></blockquote><div><br></div></span><div>Either this is an extremel=
y new feature of C++1z, or you are (uncharacteristically) mistaken. At leas=
t in C++14, one can't use generalized init-capture to capture a pack,</=
div></div></blockquote><div><br></div><div>Good point :) So we need a fun w=
orkaround. Something like this:</div><div><br></div><div><div>template<t=
ypename ...Ts> struct tuple {</div><div>=C2=A0 template<typename T>=
; struct implicit_move {</div><div>=C2=A0 =C2=A0 T t;</div><div>=C2=A0 =C2=
=A0 implicit_move(T &t) : t(std::forward<T>(t)) {}</div><div>=C2=
=A0 =C2=A0 implicit_move(implicit_move &o) : t(std::forward<T>(o.=
t)) {}</div><div>=C2=A0 =C2=A0 implicit_move(implicit_move &&o) : t=
(std::move(o.t)) {}</div><div>=C2=A0 };</div><div><br></div><div>=C2=A0 sta=
tic auto init(Ts &&...us) {</div><div>=C2=A0 =C2=A0 return [] (impl=
icit_move<Ts> ...us) {</div><div>=C2=A0 =C2=A0 =C2=A0 return [us...] =
(auto &&f) { return f(us.t...); };</div><div>=C2=A0 =C2=A0 } (us...=
);</div><div>=C2=A0 }</div><div><br></div><div>=C2=A0 decltype(init(std::de=
clval<Ts>()...)) storage;</div><div><br></div><div>=C2=A0 tuple(Ts &a=
mp;&...ts) : storage(init(std::forward<Ts>(ts)...)) {}</div><div>=
<br></div><div>=C2=A0 template<typename F> auto apply(F &&f) =
{ return storage(f); }</div><div>};</div></div><div><br></div><blockquote c=
lass=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1p=
x;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1=
ex"><div dir=3D"ltr"><div>because that would create a closure type containi=
ng a "pack of non-static data members", which isn't a thing.<=
/div><div><br></div><div><a href=3D"http://stackoverflow.com/questions/3155=
6026/using-stdbind-to-capture-a-parameter-pack-by-move" target=3D"_blank">h=
ttp://stackoverflow.com/questions/31556026/using-stdbind-to-capture-a-param=
eter-pack-by-move</a></div><div><a href=3D"http://stackoverflow.com/questio=
ns/24816557/generalized-lambda-capture-on-param-pack" target=3D"_blank">htt=
p://stackoverflow.com/questions/24816557/generalized-lambda-capture-on-para=
m-pack</a><br></div><div><br></div><div>=E2=80=93Arthur</div></div><span cl=
ass=3D"">
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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></span>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/a2ea1907-9137-41d1-8342-21a2e06ead04%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/a2ea1907-9137-=
41d1-8342-21a2e06ead04%40isocpp.org</a>.<br>
</blockquote></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" 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/CAOfiQqmQ1v1aoGXjvRALjkR2od29QZFcrMf7=
AbNqh%2Boz-4-qng%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAOfiQqmQ1v1aoG=
XjvRALjkR2od29QZFcrMf7AbNqh%2Boz-4-qng%40mail.gmail.com</a>.<br />
--089e0158b30611b75b052fc1357c--
.
Author: m.cencora@gmail.com
Date: Wed, 6 Apr 2016 07:07:40 -0700 (PDT)
Raw View
------=_Part_131_1416684309.1459951660418
Content-Type: multipart/alternative;
boundary="----=_Part_132_1175734296.1459951660418"
------=_Part_132_1175734296.1459951660418
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
This still won't work for some cases - e.g. non-movable classes
struct my_class_non_movable
{
my_class_non_movable(int) {}
my_class_non_movable(const my_class_non_movable&) {}
my_class_non_movable(my_class_non_movable&&) =3D delete;
};
because decltype(init(std::declval<Ts>()...)) will call implicit_move c-tor=
=20
which tries to call T's move/copy c-tor.
W dniu wtorek, 5 kwietnia 2016 20:42:32 UTC+2 u=C5=BCytkownik Richard Smith=
=20
napisa=C5=82:
>
> On Mon, Apr 4, 2016 at 9:45 PM, Arthur O'Dwyer <arthur....@gmail.com=20
> <javascript:>> wrote:
>
>> On Monday, April 4, 2016 at 11:34:29 AM UTC-7, Richard Smith wrote:
>>>
>>> On Mon, Apr 4, 2016 at 7:21 AM, <m.ce...@gmail.com> wrote:
>>>
>>>> This won't work e.g. for non-copyable types, since there is no way to=
=20
>>>> move-initialize lambda capture from pack expansion like here:
>>>>
>>>> static auto init(Ts&&... us)
>>>> {
>>>> return [xs... =3D us...] (auto&& f)
>>>>
>>>
>>> [xs... =3D std::forward<Ts>(us)...]
>>>
>>
>> Either this is an extremely new feature of C++1z, or you are=20
>> (uncharacteristically) mistaken. At least in C++14, one can't use=20
>> generalized init-capture to capture a pack,
>>
>
> Good point :) So we need a fun workaround. Something like this:
>
> template<typename ...Ts> struct tuple {
> template<typename T> struct implicit_move {
> T t;
> implicit_move(T &t) : t(std::forward<T>(t)) {}
> implicit_move(implicit_move &o) : t(std::forward<T>(o.t)) {}
> implicit_move(implicit_move &&o) : t(std::move(o.t)) {}
> };
>
> static auto init(Ts &&...us) {
> return [] (implicit_move<Ts> ...us) {
> return [us...] (auto &&f) { return f(us.t...); };
> } (us...);
> }
>
> decltype(init(std::declval<Ts>()...)) storage;
>
> tuple(Ts &&...ts) : storage(init(std::forward<Ts>(ts)...)) {}
>
> template<typename F> auto apply(F &&f) { return storage(f); }
> };
>
> because that would create a closure type containing a "pack of non-static=
=20
>> data members", which isn't a thing.
>>
>>
>> http://stackoverflow.com/questions/31556026/using-stdbind-to-capture-a-p=
arameter-pack-by-move
>>
>> http://stackoverflow.com/questions/24816557/generalized-lambda-capture-o=
n-param-pack
>>
>> =E2=80=93Arthur
>>
>> --=20
>> You received this message because you are subscribed to the Google Group=
s=20
>> "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n=20
>> email to std-proposal...@isocpp.org <javascript:>.
>> To post to this group, send email to std-pr...@isocpp.org <javascript:>.
>> To view this discussion on the web visit=20
>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/a2ea1907-91=
37-41d1-8342-21a2e06ead04%40isocpp.org=20
>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/a2ea1907-9=
137-41d1-8342-21a2e06ead04%40isocpp.org?utm_medium=3Demail&utm_source=3Dfoo=
ter>
>> .
>>
>
>
--=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/c6484d8d-c475-4967-a873-3f89708a3e2f%40isocpp.or=
g.
------=_Part_132_1175734296.1459951660418
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">This still won't work for some cases - e.g. non-movabl=
e classes<div><br></div><div><div>struct my_class_non_movable<br></div><div=
>{</div><div>=C2=A0 =C2=A0my_class_non_movable(int) {}</div><div>=C2=A0 =C2=
=A0my_class_non_movable(const my_class_non_movable&) {}</div><div>=C2=
=A0 =C2=A0my_class_non_movable(my_class_non_movable&&) =3D delete;<=
/div><div>};</div><div><br></div><div>because decltype(init(std::declval<=
;Ts><wbr>()...)) will call implicit_move c-tor which tries to call T'=
;s move/copy c-tor.</div><br>W dniu wtorek, 5 kwietnia 2016 20:42:32 UTC+2 =
u=C5=BCytkownik Richard Smith napisa=C5=82:<blockquote class=3D"gmail_quote=
" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding=
-left: 1ex;"><div dir=3D"ltr"><div><div class=3D"gmail_quote">On Mon, Apr 4=
, 2016 at 9:45 PM, Arthur O'Dwyer <span dir=3D"ltr"><<a href=3D"java=
script:" target=3D"_blank" gdf-obfuscated-mailto=3D"eRnHc5a4AQAJ" rel=3D"no=
follow" onmousedown=3D"this.href=3D'javascript:';return true;" oncl=
ick=3D"this.href=3D'javascript:';return true;">arthur....@gmail.com=
</a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin=
:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204)=
;border-left-style:solid;padding-left:1ex"><div dir=3D"ltr">On Monday, Apri=
l 4, 2016 at 11:34:29 AM UTC-7, Richard Smith wrote:<span><blockquote class=
=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;bo=
rder-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">=
<div dir=3D"ltr"><div><div class=3D"gmail_quote">On Mon, Apr 4, 2016 at 7:2=
1 AM, <span dir=3D"ltr"><<a rel=3D"nofollow">m.ce...@gmail.com</a>><=
/span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px =
0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-l=
eft-style:solid;padding-left:1ex"><div dir=3D"ltr"><div>This won't work=
e.g. for non-copyable types, since there is no way to move-initialize lamb=
da capture from pack expansion like here:</div><div><div><br></div><div><di=
v style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;backgroun=
d-color:rgb(250,250,250)"><code><div><div><span style=3D"font-family:Arial,=
Helvetica,sans-serif">static auto init(Ts&&... us)</span><br></div>=
<div>{</div><div>=C2=A0 =C2=A0 return [xs... =3D us...] (auto&& f)<=
/div></div></code></div></div></div></div></blockquote><div><br></div><div>=
[xs... =3D std::forward<Ts>(us)...]</div></div></div></div></blockquo=
te><div><br></div></span><div>Either this is an extremely new feature of C+=
+1z, or you are (uncharacteristically) mistaken. At least in C++14, one can=
't use generalized init-capture to capture a pack,</div></div></blockqu=
ote><div><br></div><div>Good point :) So we need a fun workaround. Somethin=
g like this:</div><div><br></div><div><div>template<typename ...Ts> s=
truct tuple {</div><div>=C2=A0 template<typename T> struct implicit_m=
ove {</div><div>=C2=A0 =C2=A0 T t;</div><div>=C2=A0 =C2=A0 implicit_move(T =
&t) : t(std::forward<T>(t)) {}</div><div>=C2=A0 =C2=A0 implicit_m=
ove(implicit_move &o) : t(std::forward<T>(o.t)) {}</div><div>=C2=
=A0 =C2=A0 implicit_move(implicit_move &&o) : t(std::move(o.t)) {}<=
/div><div>=C2=A0 };</div><div><br></div><div>=C2=A0 static auto init(Ts &am=
p;&...us) {</div><div>=C2=A0 =C2=A0 return [] (implicit_move<Ts> =
....us) {</div><div>=C2=A0 =C2=A0 =C2=A0 return [us...] (auto &&f) {=
return f(us.t...); };</div><div>=C2=A0 =C2=A0 } (us...);</div><div>=C2=A0 =
}</div><div><br></div><div>=C2=A0 decltype(init(std::declval<Ts><wbr>=
()...)) storage;</div><div><br></div><div>=C2=A0 tuple(Ts &&...ts) =
: storage(init(std::forward<Ts>(<wbr>ts)...)) {}</div><div><br></div>=
<div>=C2=A0 template<typename F> auto apply(F &&f) { return s=
torage(f); }</div><div>};</div></div><div><br></div><blockquote class=3D"gm=
ail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-l=
eft-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div d=
ir=3D"ltr"><div>because that would create a closure type containing a "=
;pack of non-static data members", which isn't a thing.</div><div>=
<br></div><div><a href=3D"http://stackoverflow.com/questions/31556026/using=
-stdbind-to-capture-a-parameter-pack-by-move" target=3D"_blank" rel=3D"nofo=
llow" onmousedown=3D"this.href=3D'http://www.google.com/url?q\75http%3A=
%2F%2Fstackoverflow.com%2Fquestions%2F31556026%2Fusing-stdbind-to-capture-a=
-parameter-pack-by-move\46sa\75D\46sntz\0751\46usg\75AFQjCNGTmqgvqS05NEcIxq=
vBMuwZNDHzxA';return true;" onclick=3D"this.href=3D'http://www.goog=
le.com/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F31556026%2Fusin=
g-stdbind-to-capture-a-parameter-pack-by-move\46sa\75D\46sntz\0751\46usg\75=
AFQjCNGTmqgvqS05NEcIxqvBMuwZNDHzxA';return true;">http://stackoverflow.=
com/<wbr>questions/31556026/using-<wbr>stdbind-to-capture-a-<wbr>parameter-=
pack-by-move</a></div><div><a href=3D"http://stackoverflow.com/questions/24=
816557/generalized-lambda-capture-on-param-pack" target=3D"_blank" rel=3D"n=
ofollow" onmousedown=3D"this.href=3D'http://www.google.com/url?q\75http=
%3A%2F%2Fstackoverflow.com%2Fquestions%2F24816557%2Fgeneralized-lambda-capt=
ure-on-param-pack\46sa\75D\46sntz\0751\46usg\75AFQjCNEStZlW_awantELVEecBECq=
vfZ7pg';return true;" onclick=3D"this.href=3D'http://www.google.com=
/url?q\75http%3A%2F%2Fstackoverflow.com%2Fquestions%2F24816557%2Fgeneralize=
d-lambda-capture-on-param-pack\46sa\75D\46sntz\0751\46usg\75AFQjCNEStZlW_aw=
antELVEecBECqvfZ7pg';return true;">http://stackoverflow.com/<wbr>questi=
ons/24816557/<wbr>generalized-lambda-capture-on-<wbr>param-pack</a><br></di=
v><div><br></div><div>=E2=80=93Arthur</div></div><span>
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"=
eRnHc5a4AQAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:&=
#39;;return true;" onclick=3D"this.href=3D'javascript:';return true=
;">std-proposal...@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"eRnHc5a4AQAJ" rel=3D"nofollow" onmousedown=3D"=
this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'=
;javascript:';return true;">std-pr...@isocpp.org</a>.<br></span>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/a2ea1907-9137-41d1-8342-21a2e06ead04%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank" =
rel=3D"nofollow" onmousedown=3D"this.href=3D'https://groups.google.com/=
a/isocpp.org/d/msgid/std-proposals/a2ea1907-9137-41d1-8342-21a2e06ead04%40i=
socpp.org?utm_medium\75email\46utm_source\75footer';return true;" oncli=
ck=3D"this.href=3D'https://groups.google.com/a/isocpp.org/d/msgid/std-p=
roposals/a2ea1907-9137-41d1-8342-21a2e06ead04%40isocpp.org?utm_medium\75ema=
il\46utm_source\75footer';return true;">https://groups.google.com/a/<wb=
r>isocpp.org/d/msgid/std-<wbr>proposals/a2ea1907-9137-41d1-<wbr>8342-21a2e0=
6ead04%40isocpp.org</a><wbr>.<br>
</blockquote></div><br></div></div>
</blockquote></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/c6484d8d-c475-4967-a873-3f89708a3e2f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/c6484d8d-c475-4967-a873-3f89708a3e2f=
%40isocpp.org</a>.<br />
------=_Part_132_1175734296.1459951660418--
------=_Part_131_1416684309.1459951660418--
.
Author: will wray <wjwray@gmail.com>
Date: Thu, 14 Feb 2019 11:12:13 -0800 (PST)
Raw View
------=_Part_449_1582016712.1550171533531
Content-Type: multipart/alternative;
boundary="----=_Part_450_1713082364.1550171533534"
------=_Part_450_1713082364.1550171533534
Content-Type: text/plain; charset="UTF-8"
Reviving this thread on 'simple tuple' implementation with notes & updates
pre C++20.
Plus, thoughts on a use case for structured binding syntax inside a lambda
capture list to
explode and replicate aggregate structure members.
'Structured capture'?
[ [de,st,ru,ct,ur,ed] = structured ]{};
Thus far, the thread discussed:
1. (OP) use of structured bindings to implement simple tuple-like access
to aggregates
2. use of lambda-capture closures to implement simple tuple storage
(1) is now used in several reflection libraries (see e.g. magic_get
core17_generated.hpp
<https://github.com/apolukhin/magic_get/blob/develop/include/boost/pfr/detail/core17_generated.hpp>)
though
the lack of variadic pack SB (as proposed in P1061 Structured Bindings
can introduce a Pack
<http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2018/p1061r0.html>)
means that code has to be written or generated for each member count
'arity'.
(2) doesn't appear to be used (?) in released code, though C++20 lambda
improvements make it
more viable: explicit template arguments, p0428 Familiar template syntax
for generic lambdas
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0428r2.pdf>,
and variadic init-capture, P0780 Allow pack expansion in lambda
init-capture
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0780r2.html> (both
on GCC trunk).
Here's a C++20 port of the core 'C++14 lambda-tuple' (posted by Mathias
Gaunard above)
(the passed-in function 'f' can select an indexed element, tuple / tie
style, or run any for-each algo -
ignore the 'f's in the following - the captured storage is the focus, not
the tuple-like functionality):
auto arg_pack_fwd = []<typename... T>(T&&... args) mutable
{
return [...xs = std::forward<T>(args)]<typename F>(F&& f) {
return std::forward<F>(f)(xs...);
};
};
This solves (I believe) most of the 'perfect forwarding' issues discussed
previously in the thread
and approaches the ability of aggregate-initialization to copy, move or
direct-initialize elements.
There are flaws, though.
The decltype of arg_pack_fwd reflects the pattern of lval and rval args in
its deduced 'template signature'.
This makes it less useful as simple, generic, tuple storage for a type list
and makes it more an 'on the fly'
storage for processing heterogeneous elements.
One particularly unfortunate flaw is that init-capture disables a
superpower of regular by-copy capture:
auto closure_cpy = [](auto const&... args) mutable
{
return [args...]<typename F>(F&& f) {
return std::forward<F>(f)(args...);
};
};
This regular by-copy capture copies anything, arrays included. So, passing
in an array
(string literal here for convenience - not a special case - can be any
array type, rvalue included):
static_assert( sizeof(closure_cpy("copy array into closure"))
== sizeof("copy array into closure") );
Forwarding-in decays the array as is usual for a function argument
initializer:
static_assert( sizeof(arg_pack_fwd("forwarded array decays to pointer"))
== sizeof(char*) );
Ideally, 'perfect' forwarding would forward all arg types and copy arrays,
no decay. I see no current way to do this.
How could we get both non-decayed array capture and forwarding-capture for
other args?
(Preferably maintaining the implicit language-level copy for arrays.)
Lambda by-copy capture is the one place where C++ language confers copy
semantics on C-arrays
(there's a std::swap array specialization, but that's library).
Structured binding, with no reference qualifier on the auto, also copies
arrays, but with a proviso:
constexpr char cpp[][3]{{'C','+','+'}}; // 2D array containing one char[3]
auto [cpp_cpy] = cpp;
static_assert( sizeof(cpp_cpy) == 3
&& ! std::is_const_v<decltype(cpp_cpy)> );
The proviso is that the entire RHS object is copied and the SB-introduced
name then binds to the copied subobject
(so 'cpp_cpy' above is in fact a name for the first 1D-array element of a
copy of the 2D-array cpp).
Names bound by SB are currently forbidden from inclusion in lambda capture
lists, because of this object / subobject
dual identity (though there's a proposal to allow reference capture P1381R0
Reference capture of structured bindings
<http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2018/p1381r0.html>).
What about allowing structured binding syntax inside lambda capture, as
hinted at the top of this lengthy post:
auto sb_fwd = []<typename A>(A&& a) mutable
{
return [[b,c]{std::forward<A>(a)}]<typename F>(F&& f) {
return std::forward<F>(f)(b,c);
};
};
The idea is that this would capture subobjects 'b' and 'c' of object 'a'
by-copy for lvalue 'a' or by-move for rvalue 'a'.
If 'a' is an aggregate structure with two members then the resulting
closure captures just those members, not 'a' itself,
so the lambda may have (could be specified to have) identical layout to the
passed-in struct.
Unlike an actual structured binding, this syntax actually explodes the
members and reassembles them in the closure.
Clearly, variadic structured bindings would be a boon here.
This idea may have been discussed before. Any links?
According to a committee member "Richard said it was doable, thus it is
doable. I have no idea how."
To achieve the 'perfect' pack forwarding with array copy requires wrapping
each arg for the SB to unwrap.
Something like this, perhaps; a forwarding reference wrapper (possibly with
customized tuple access or CTAD):
template <typename T>
struct forward_reference_wrapper {
T&& ref;
constexpr T&& operator ()() const { return std::forward<T>(ref); }
};
And then:
auto arg_pack_frw = []<typename... T>(T&&... args) mutable
{
return [...[xs]{forward_reference_wrapper<T>{args}}]<typename F>(F&& f
) {
return std::forward<F>(f)(xs...);
};
};
The wrapper itself here is an rvalue containing either an rvalue or an
lvalue reference that will either
move-construct or copy-construct xs when destructured. In both cases array
arguments would be copied.
Why care about built-in C-arrays when the usual advice is to wrap 'em like
std::array, for copy etc.?
For generic code; it allows to replicate elements with the same types as
the input source.
The closure itself already wraps by-copy captured arrays and is itself
copyable and move-enabled.
The closure may then be layout-compatible with a structure containing the
same types
(layout order is currently unspecified).
All getting a bit over complex for a simple tuple type.
Still, way simpler than std::tuple with its plethora of carefully
constrained constructors.
When floated a couple of days ago on cpplang slack, the slackers mentioned
possible parsing issues,
colliding with attribute specifiers.
In terms of language mechanics, is something like this doable?
--
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/10cd9258-2454-47e6-a174-407db807fe30%40isocpp.org.
------=_Part_450_1713082364.1550171533534
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Reviving this thread on 'simple tuple' implementat=
ion with notes & updates pre C++20.<div><br><div>Plus, thoughts on a us=
e case for structured binding syntax inside a lambda capture list to</div><=
div>explode and replicate aggregate structure members.</div><div>'Struc=
tured capture'?</div></div><blockquote style=3D"margin: 0 0 0 40px; bor=
der: none; padding: 0px;"><blockquote style=3D"margin: 0 0 0 40px; border: =
none; padding: 0px;"><blockquote style=3D"margin: 0 0 0 40px; border: none;=
padding: 0px;"><div><div>=C2=A0<span class=3D"styled-by-prettify" style=3D=
"font-family: monospace; background-color: rgb(250, 250, 250); color: rgb(0=
, 0, 136);">[ [de,st,ru,ct,ur,ed] =3D structured ]</span><span class=3D"sty=
led-by-prettify" style=3D"font-family: monospace; background-color: rgb(250=
, 250, 250);"><font color=3D"#666600">{};</font></span></div></div></blockq=
uote></blockquote></blockquote><div><div><br></div><div>Thus far, the threa=
d discussed:</div><div><ol><li>(OP) use of structured bindings to implement=
simple tuple-like access to aggregates<br></li><li>use of lambda-capture c=
losures to implement simple tuple storage</li></ol></div><div>(1) is now us=
ed in several reflection libraries (see e.g.=C2=A0<a href=3D"https://github=
..com/apolukhin/magic_get/blob/develop/include/boost/pfr/detail/core17_gener=
ated.hpp">magic_get core17_generated.hpp</a>) though</div><div>=C2=A0 the l=
ack of variadic pack SB (as proposed in <a href=3D"http://www.open-std.org/=
JTC1/SC22/WG21/docs/papers/2018/p1061r0.html">P1061 Structured Bindings can=
introduce a Pack</a>)</div><div>=C2=A0 means that code has to be written o=
r generated for each member count 'arity'.</div><div><br></div><div=
>(2) doesn't appear to be used (?) in released code, though C++20 lambd=
a improvements make it</div><div>=C2=A0 more viable: explicit template argu=
ments,=C2=A0<a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2=
017/p0428r2.pdf">p0428 Familiar template syntax for generic lambdas</a>,</d=
iv><div>=C2=A0 and variadic init-capture,=C2=A0<a href=3D"http://www.open-s=
td.org/jtc1/sc22/wg21/docs/papers/2018/p0780r2.html">P0780 Allow pack expan=
sion in lambda init-capture</a>=C2=A0(both on GCC trunk).</div><div><br>Her=
e's a C++20 port of the core 'C++14 lambda-tuple' (posted by Ma=
thias Gaunard above)</div><div><div>(the passed-in function 'f' can=
select an indexed element, tuple / tie style, or run any for-each algo -</=
div><div>=C2=A0ignore the 'f's in the following - the captured stor=
age is the focus, not the tuple-like functionality):</div></div><div><div><=
br></div><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250=
, 250); border-color: rgb(187, 187, 187); border-style: solid; border-width=
: 1px; overflow-wrap: break-word;"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">=C2=A0</span><span style=3D"color: #008;" class=3D"styled-by-prettify">a=
uto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> arg_pa=
ck_fwd </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">[]<</span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">typename</span><span st=
yle=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;" class=3D"styled-by-prettify">>(</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"styled-by-prettify"> args</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>mutable</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r>=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>=C2=A0=
=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">return</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">[...</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">xs </span><spa=
n 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"co=
lor: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">forward</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;" class=3D"style=
d-by-prettify">>(</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">args</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">)]<</span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
typename</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> F=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">>(</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">F</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">&&</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> f</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br>=C2=A0 =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: #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">forward</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">F</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">>(</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">f</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)(<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify">xs</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">...);</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =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>=C2=A0 </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">};</span></div><=
/code></div><div><br></div><div>This solves (I believe) most of the 'pe=
rfect forwarding' issues discussed previously in the thread</div><div>a=
nd approaches the ability of aggregate-initialization to copy, move or dire=
ct-initialize elements.</div><div><br></div><div>There are flaws, though.</=
div><div><br></div><div><div>The decltype of arg_pack_fwd reflects the patt=
ern of lval and rval args in its deduced 'template signature'.</div=
><div>This makes it less useful as simple, generic, tuple storage for a typ=
e list and makes it more an 'on the fly'</div></div><div>storage fo=
r processing heterogeneous elements.</div><div><br></div><div>One particula=
rly unfortunate flaw is that init-capture disables a superpower of regular =
by-copy capture:</div><div><br></div><div><div class=3D"prettyprint" style=
=3D"border-width: 1px; border-style: solid; border-color: rgb(187, 187, 187=
); background-color: rgb(250, 250, 250); overflow-wrap: break-word;"><code =
class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #=
000;" class=3D"styled-by-prettify">=C2=A0</span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> closure_cpy </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">[](</span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">const</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">&...</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> args</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: #=
008;" class=3D"styled-by-prettify">mutable</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">return</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">[</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">args</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">...]<</span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">typename</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> F</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
gt;(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">F</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">&&</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> f</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: #6=
60;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">return</span><span st=
yle=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">forward</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify"><</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">F</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">>(</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify">f</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">)(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">args=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">...);</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =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>=C2=
=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</sp=
an></div></code></div><div><br></div></div><div>This regular by-copy captur=
e copies anything, arrays included. So, passing in an array<br>(string lite=
ral here for convenience - not a special case - can be any array type, rval=
ue included):<br></div><div><br></div><div class=3D"prettyprint" style=3D"b=
ackground-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); bord=
er-style: solid; border-width: 1px; overflow-wrap: break-word;"><code class=
=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #000;"=
class=3D"styled-by-prettify">=C2=A0 </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">static_assert</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: #008;" class=3D"styled-b=
y-prettify">sizeof</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">c=
losure_cpy</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
(</span><span style=3D"color: #080;" class=3D"styled-by-prettify">"cop=
y array into closure"</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">))</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">=3D=3D</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">sizeof</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>(</span><span style=3D"color: #080;" class=3D"styled-by-prettify">"co=
py array into closure"</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">)=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br><=
/span></div></code></div><div><br></div><div>Forwarding-in decays the array=
as is usual for a function argument initializer:</div><div><br></div><div>=
<div style=3D"color: #000000;background-color: #fffffe;font-family: Consola=
s, " liberation=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" =
normal;font-size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=
=3D""><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 2=
50); border-color: rgb(187, 187, 187); border-style: solid; border-width: 1=
px; overflow-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"s=
ubprettyprint"><span style=3D"color: #000;" class=3D"styled-by-prettify">=
=C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">sta=
tic_assert</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: #008;" class=3D"styled-by-prettify">sizeof</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">arg_pack_fwd</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #080;" class=3D"styled-by-prettify">"forwarded array decays to point=
er"</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 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>=3D=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">sizeof</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">char</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;" cl=
ass=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br></span></div></code></div><br>Ideally, 'perfect&=
#39; forwarding would forward all arg types and copy arrays, no decay. I se=
e no current way to do this.</div></div><div style=3D"" liberation=3D"" mon=
o",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D"" 1=
4px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D""><font color=3D"#000=
000">How could we get both non-decayed array capture</font><span style=3D"c=
olor: rgb(0, 0, 0);">=C2=A0and forwarding-capture for other args?</span></d=
iv><div style=3D"" liberation=3D"" mono",=3D"" courier,=3D"" monospace;font=
-weight:=3D"" normal;font-size:=3D"" 14px;line-height:=3D"" 19px;white-spac=
e:=3D"" pre;"=3D""><span style=3D"color: rgb(0, 0, 0);">(Preferably</span><=
font color=3D"#000000">=C2=A0maintaining the=C2=A0</font><span style=3D"col=
or: rgb(0, 0, 0);">implicit language-level</span><span style=3D"color: rgb(=
0, 0, 0);">=C2=A0</span><span style=3D"color: rgb(0, 0, 0);">copy for array=
s.)</span></div><div style=3D"" liberation=3D"" mono",=3D"" courier,=3D"" m=
onospace;font-weight:=3D"" normal;font-size:=3D"" 14px;line-height:=3D"" 19=
px;white-space:=3D"" pre;"=3D""><font color=3D"#000000"><br>Lambda by-copy =
capture is the one place where C++ language confers copy semantics on C-arr=
ays</font></div><div style=3D"" liberation=3D"" mono",=3D"" courier,=3D"" m=
onospace;font-weight:=3D"" normal;font-size:=3D"" 14px;line-height:=3D"" 19=
px;white-space:=3D"" pre;"=3D""><font color=3D"#000000">(there's a std:=
:swap array specialization, but that's library).</font></div><div style=
=3D"" liberation=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D""=
normal;font-size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=
=3D""><font color=3D"#000000"><br><span style=3D"background-color: rgb(255,=
255, 255);">S</span><span style=3D"background-color: rgb(255, 255, 254);">=
tructured binding, with no reference qualifier on the auto, also copies arr=
ays, but with a proviso:</span></font></div><div style=3D"color: #000000;ba=
ckground-color: #fffffe;font-family: Consolas, " liberation=3D"" mono",=3D"=
" courier,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D"" 14px;lin=
e-height:=3D"" 19px;white-space:=3D"" pre;"=3D""><br></div><div style=3D"ba=
ckground-color: rgb(255, 255, 254);" liberation=3D"" mono",=3D"" courier,=
=3D"" monospace;font-weight:=3D"" normal;font-size:=3D"" 14px;line-height:=
=3D"" 19px;white-space:=3D"" pre;"=3D""><div liberation=3D"" mono",=3D"" co=
urier,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D"" 14px;line-he=
ight:=3D"" 19px;white-space:=3D"" pre;"=3D"" style=3D"color: rgb(0, 0, 0);"=
><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); =
border-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; o=
verflow-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subpre=
ttyprint"><span style=3D"color: #000;" class=3D"styled-by-prettify">=C2=A0 =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">constexpr<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">char</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> cpp</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">[][</span><span style=3D"color: =
#066;" class=3D"styled-by-prettify">3</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">]{{</span><span style=3D"color: #080;" class=3D"=
styled-by-prettify">'C'</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">,</span><span style=3D"color: #080;" class=3D"styled-b=
y-prettify">'+'</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">,</span><span style=3D"color: #080;" class=3D"styled-by-pretti=
fy">'+'</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">}};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #800;" class=3D"styled-by-prettify">// 2D array=
containing one char[3]</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"><br>=C2=A0 </span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">[=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">cpp_cpy</s=
pan><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">=3D</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> cpp</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 </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">static_assert</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">sizeof</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">cpp=
_cpy</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">=3D=3D</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #066;" class=3D"styled-by-prettify">3</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&am=
p;&</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">!</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">is_const_v</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">decltype</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">cpp_cpy</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">)></span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br></span></div></code></div><br>The proviso is that the entire RHS object =
is copied and the SB-introduced name then binds to the copied subobject<br>=
</div><div liberation=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=
=3D"" normal;font-size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" =
pre;"=3D"" style=3D"color: rgb(0, 0, 0);">(so 'cpp_cpy' above is in=
fact a name for the first 1D-array element of a copy of the 2D-array cpp).=
</div><div liberation=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=
=3D"" normal;font-size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" =
pre;"=3D"" style=3D"color: rgb(0, 0, 0);"><br></div><div liberation=3D"" mo=
no",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D"" =
14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D"" style=3D"color: rg=
b(0, 0, 0);">Names bound by SB are currently forbidden from inclusion in la=
mbda capture lists, because of this object / subobject</div><div liberation=
=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-siz=
e:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D"" style=3D"c=
olor: rgb(0, 0, 0);">dual identity (though there's a proposal to allow =
reference capture=C2=A0<a href=3D"http://www.open-std.org/JTC1/SC22/WG21/do=
cs/papers/2018/p1381r0.html">P1381R0 Reference capture of structured bindin=
gs</a>).</div><div liberation=3D"" mono",=3D"" courier,=3D"" monospace;font=
-weight:=3D"" normal;font-size:=3D"" 14px;line-height:=3D"" 19px;white-spac=
e:=3D"" pre;"=3D"" style=3D"color: rgb(0, 0, 0);"><br></div><div liberation=
=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-siz=
e:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D"" style=3D"c=
olor: rgb(0, 0, 0);">What about allowing structured binding syntax inside l=
ambda capture, as hinted at the top of this lengthy post:</div><div liberat=
ion=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-=
size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D"" style=
=3D""><div style=3D"color: rgb(34, 34, 34); background-color: rgb(255, 255,=
255);"><br></div><div class=3D"prettyprint" style=3D"border-width: 1px; bo=
rder-style: solid; border-color: rgb(187, 187, 187); background-color: rgb(=
250, 250, 250); overflow-wrap: break-word;"><code class=3D"prettyprint" sty=
le=3D""><div class=3D"subprettyprint" style=3D""><span style=3D"color: #000=
;" class=3D"styled-by-prettify">=C2=A0</span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> sb_fwd </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">[]<</span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">typename</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> A</span><span style=3D"color: #660;" class=3D"styled-by-prettify">>(<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify">A</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&&</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> a</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: #008;" =
class=3D"styled-by-prettify">mutable</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>=C2=A0 </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">return</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-b=
y-prettify">b</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify">c</spa=
n><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 style=3D"colo=
r: #000;" class=3D"styled-by-prettify">forward</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify">A</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">>(</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">a</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">)}]<</span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">typename</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> F</span><span style=3D"color: #660;" class=3D"styled-by-prettify">>(<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify">F</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&&</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> f</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>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">return</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">forward</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">F</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">>(</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">f</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>)(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">b</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">c</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">};</span></div></code></div><div s=
tyle=3D"color: rgb(34, 34, 34); background-color: rgb(255, 255, 255);"><br>=
</div></div></div><div style=3D"color: #000000;background-color: #fffffe;fo=
nt-family: Consolas, " liberation=3D"" mono",=3D"" courier,=3D"" monospace;=
font-weight:=3D"" normal;font-size:=3D"" 14px;line-height:=3D"" 19px;white-=
space:=3D"" pre;"=3D"">The idea is that this would capture subobjects '=
b' and 'c' of object 'a' by-copy for lvalue 'a'=
or by-move for rvalue 'a'.<br></div><div style=3D"color: #000000;b=
ackground-color: #fffffe;font-family: Consolas, " liberation=3D"" mono",=3D=
"" courier,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D"" 14px;li=
ne-height:=3D"" 19px;white-space:=3D"" pre;"=3D"">If 'a' is an aggr=
egate structure with two members then the resulting closure captures just t=
hose members, not 'a' itself,</div><div style=3D"color: #000000;bac=
kground-color: #fffffe;font-family: Consolas, " liberation=3D"" mono",=3D""=
courier,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D"" 14px;line=
-height:=3D"" 19px;white-space:=3D"" pre;"=3D"">so the lambda may have (cou=
ld be specified to have) identical layout to the passed-in struct.</div><di=
v style=3D"color: #000000;background-color: #fffffe;font-family: Consolas, =
" liberation=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" nor=
mal;font-size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D"=
"><br></div><div style=3D"color: #000000;background-color: #fffffe;font-fam=
ily: Consolas, " liberation=3D"" mono",=3D"" courier,=3D"" monospace;font-w=
eight:=3D"" normal;font-size:=3D"" 14px;line-height:=3D"" 19px;white-space:=
=3D"" pre;"=3D"">Unlike an actual structured binding, this syntax actually =
explodes the members and reassembles them in the closure.</div><div style=
=3D"color: #000000;background-color: #fffffe;font-family: Consolas, " liber=
ation=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;fon=
t-size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D"">Clear=
ly, variadic structured bindings would be a boon here.</div><div style=3D"c=
olor: #000000;background-color: #fffffe;font-family: Consolas, " liberation=
=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-siz=
e:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D""><br></div>=
<div style=3D"color: #000000;background-color: #fffffe;font-family: Consola=
s, " liberation=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" =
normal;font-size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=
=3D"">This idea may have been discussed before. Any links?</div><div style=
=3D"color: #000000;background-color: #fffffe;font-family: Consolas, " liber=
ation=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;fon=
t-size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D"">Accor=
ding to a committee member=C2=A0 =C2=A0"Richard said it was doable, th=
us it is doable. I have no idea how."</div><div style=3D"color: #00000=
0;background-color: #fffffe;font-family: Consolas, " liberation=3D"" mono",=
=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D"" 14px=
;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D""><br></div><div style=
=3D"color: #000000;background-color: #fffffe;font-family: Consolas, " liber=
ation=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;fon=
t-size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D"">To ac=
hieve the 'perfect' pack forwarding with array copy requires wrappi=
ng each arg for the SB to unwrap.</div><div style=3D"color: #000000;backgro=
und-color: #fffffe;font-family: Consolas, " liberation=3D"" mono",=3D"" cou=
rier,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D"" 14px;line-hei=
ght:=3D"" 19px;white-space:=3D"" pre;"=3D"">Something like this, perhaps; a=
forwarding reference wrapper (possibly with customized tuple access or CTA=
D):</div><div style=3D"color: #000000;background-color: #fffffe;font-family=
: Consolas, " liberation=3D"" mono",=3D"" courier,=3D"" monospace;font-weig=
ht:=3D"" normal;font-size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D=
"" pre;"=3D""><br></div><div style=3D"color: #000000;background-color: #fff=
ffe;font-family: Consolas, " liberation=3D"" mono",=3D"" courier,=3D"" mono=
space;font-weight:=3D"" normal;font-size:=3D"" 14px;line-height:=3D"" 19px;=
white-space:=3D"" pre;"=3D""><div liberation=3D"" mono",=3D"" courier,=3D""=
monospace;font-weight:=3D"" normal;font-size:=3D"" 14px;line-height:=3D"" =
19px;white-space:=3D"" pre;"=3D""><div class=3D"prettyprint" style=3D"backg=
round-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-s=
tyle: solid; border-width: 1px; overflow-wrap: break-word;"><code class=3D"=
prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">=C2=A0 </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">template</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify"><</span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">typename</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> 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>=C2=
=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">struct=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> forward_r=
eference_wrapper </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r>=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #000;" class=3D"styled-=
by-prettify">T</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&&</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">ref</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span></di=
v><div class=3D"subprettyprint"><span style=3D"color: #000;" class=3D"style=
d-by-prettify"></span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">=C2=A0 =C2=A0 =C2=A0=C2=A0<span style=3D"background-color: rgb(255, 25=
5, 254); font-family: Arial, Helvetica, sans-serif; color: rgb(0, 0, 255);"=
>constexpr</span><span style=3D"background-color: rgb(255, 255, 254); color=
: rgb(0, 0, 0); font-family: Arial, Helvetica, sans-serif;"> T&& </=
span><span style=3D"background-color: rgb(255, 255, 254); font-family: Aria=
l, Helvetica, sans-serif; color: rgb(0, 0, 255);">operator</span><span styl=
e=3D"background-color: rgb(255, 255, 254); color: rgb(0, 0, 0); font-family=
: Arial, Helvetica, sans-serif;"> ()() </span><span style=3D"background-col=
or: rgb(255, 255, 254); font-family: Arial, Helvetica, sans-serif; color: r=
gb(0, 0, 255);">const</span><span style=3D"background-color: rgb(255, 255, =
254); color: rgb(0, 0, 0); font-family: Arial, Helvetica, sans-serif;"> {=
=C2=A0</span><span style=3D"background-color: rgb(255, 255, 254); font-fami=
ly: Arial, Helvetica, sans-serif; color: rgb(0, 0, 255);">return</span><spa=
n style=3D"background-color: rgb(255, 255, 254); color: rgb(0, 0, 0); font-=
family: Arial, Helvetica, sans-serif;"> std::forward<T>(ref);=C2=A0</=
span><span style=3D"background-color: rgb(255, 255, 254); color: rgb(0, 0, =
0); font-family: Arial, Helvetica, sans-serif;">}</span><span style=3D"back=
ground-color: rgb(255, 255, 254); color: rgb(0, 0, 0); font-family: Arial, =
Helvetica, sans-serif;"><br></span>=C2=A0 };</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br></span></div></code></div><div><br></=
div>And then:</div><div liberation=3D"" mono",=3D"" courier,=3D"" monospace=
;font-weight:=3D"" normal;font-size:=3D"" 14px;line-height:=3D"" 19px;white=
-space:=3D"" pre;"=3D""><br></div><div liberation=3D"" mono",=3D"" courier,=
=3D"" monospace;font-weight:=3D"" normal;font-size:=3D"" 14px;line-height:=
=3D"" 19px;white-space:=3D"" pre;"=3D""><div class=3D"prettyprint" style=3D=
"border-width: 1px; border-style: solid; border-color: rgb(187, 187, 187); =
color: rgb(34, 34, 34); background-color: rgb(250, 250, 250); overflow-wrap=
: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0</span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> arg_pack_frw </span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">=3D</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: #0=
08;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">...</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">>(</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">T</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&&...</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> args</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: #008;" class=3D"styled-by-prettify">mutable</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><s=
pan 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 =C2=A0 </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">return</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">[...[</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">xs</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">]{</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">forward_reference_wrapper</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;" c=
lass=3D"styled-by-prettify">>{</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">args</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">}}]<</span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">typename</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> F</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">>(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
F</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&&=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> f</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">return</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">forward</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">F</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">>(</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">f</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">)(</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
">xs</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 =C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">};<=
/span></div></code></div></div></div><div style=3D"color: #000000;backgroun=
d-color: #fffffe;font-family: Consolas, " liberation=3D"" mono",=3D"" couri=
er,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D"" 14px;line-heigh=
t:=3D"" 19px;white-space:=3D"" pre;"=3D""><br></div><div style=3D"color: #0=
00000;background-color: #fffffe;font-family: Consolas, " liberation=3D"" mo=
no",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D"" =
14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D"">The wrapper itself=
here is an rvalue containing either an rvalue or an lvalue reference that =
will either</div><div style=3D"color: #000000;background-color: #fffffe;fon=
t-family: Consolas, " liberation=3D"" mono",=3D"" courier,=3D"" monospace;f=
ont-weight:=3D"" normal;font-size:=3D"" 14px;line-height:=3D"" 19px;white-s=
pace:=3D"" pre;"=3D"">move-construct or copy-construct xs when destructured=
.. In both cases array arguments would be copied.</div><div style=3D"color: =
#000000;background-color: #fffffe;font-family: Consolas, " liberation=3D"" =
mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D"=
" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D""><br></div><div s=
tyle=3D"color: #000000;background-color: #fffffe;font-family: Consolas, " l=
iberation=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal=
;font-size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D""><=
div liberation=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" n=
ormal;font-size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=
=3D"">Why care about built-in C-arrays when the usual advice is to wrap =
9;em like std::array, for copy etc.?</div><div liberation=3D"" mono",=3D"" =
courier,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D"" 14px;line-=
height:=3D"" 19px;white-space:=3D"" pre;"=3D""><br></div><div liberation=3D=
"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-size:=
=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D"">For generic =
code; it allows to replicate elements with the same types as the input sour=
ce.</div><div liberation=3D"" mono",=3D"" courier,=3D"" monospace;font-weig=
ht:=3D"" normal;font-size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D=
"" pre;"=3D"">The closure itself already wraps by-copy captured arrays and =
is itself copyable and move-enabled.<br></div><div liberation=3D"" mono",=
=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D"" 14px=
;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D""><div liberation=3D"" m=
ono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D""=
14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D"">The closure may t=
hen be layout-compatible with a structure containing the same types</div><d=
iv liberation=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" no=
rmal;font-size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D=
"">(layout order is currently unspecified).</div><div><br></div></div>All g=
etting a bit over complex for a simple tuple type.</div><div style=3D"color=
: #000000;background-color: #fffffe;font-family: Consolas, " liberation=3D"=
" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-size:=
=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D"">Still, way s=
impler than std::tuple with its plethora of carefully constrained construct=
ors.</div></div></div><div style=3D"color: #000000;background-color: #fffff=
e;font-family: Consolas, " liberation=3D"" mono",=3D"" courier,=3D"" monosp=
ace;font-weight:=3D"" normal;font-size:=3D"" 14px;line-height:=3D"" 19px;wh=
ite-space:=3D"" pre;"=3D""><br></div><div style=3D"color: #000000;backgroun=
d-color: #fffffe;font-family: Consolas, " liberation=3D"" mono",=3D"" couri=
er,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D"" 14px;line-heigh=
t:=3D"" 19px;white-space:=3D"" pre;"=3D"">When floated a couple of days ago=
on cpplang slack, the slackers mentioned possible parsing issues,</div><di=
v style=3D"color: #000000;background-color: #fffffe;font-family: Consolas, =
" liberation=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" nor=
mal;font-size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D"=
">colliding with attribute specifiers.</div><div style=3D"color: #000000;ba=
ckground-color: #fffffe;font-family: Consolas, " liberation=3D"" mono",=3D"=
" courier,=3D"" monospace;font-weight:=3D"" normal;font-size:=3D"" 14px;lin=
e-height:=3D"" 19px;white-space:=3D"" pre;"=3D""><br></div><div style=3D"co=
lor: #000000;background-color: #fffffe;font-family: Consolas, " liberation=
=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-siz=
e:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D"">In terms o=
f language mechanics, is something like this doable?</div><div style=3D"col=
or: #000000;background-color: #fffffe;font-family: Consolas, " liberation=
=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" normal;font-siz=
e:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=3D""><br></div>=
<div style=3D"color: #000000;background-color: #fffffe;font-family: Consola=
s, " liberation=3D"" mono",=3D"" courier,=3D"" monospace;font-weight:=3D"" =
normal;font-size:=3D"" 14px;line-height:=3D"" 19px;white-space:=3D"" pre;"=
=3D""><br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/10cd9258-2454-47e6-a174-407db807fe30%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/10cd9258-2454-47e6-a174-407db807fe30=
%40isocpp.org</a>.<br />
------=_Part_450_1713082364.1550171533534--
------=_Part_449_1582016712.1550171533531--
.