Topic: Decomposition of std::complex.
Author: 3dw4rd@verizon.net
Date: Thu, 13 Apr 2017 15:11:28 -0700 (PDT)
Raw View
------=_Part_1178_2054269446.1492121488413
Content-Type: multipart/alternative;
boundary="----=_Part_1179_908813261.1492121488415"
------=_Part_1179_908813261.1492121488415
Content-Type: text/plain; charset=UTF-8
In many uses of std::complex
one wants to capture the real and imaginary parts in separate variables
either to use them in subsequent calculations or to modify them
individually.
There are many options:
These options reflect an over-encapsulation of std::complex, which everyone
agrees is a struct with two floating point numbers, real part and imaginary
part, in that order.
Attempting to use a decomposition declaration for a complex number is an
error because of the pretension (ostensibly for C compatibility) the
complex numbers are opaque.
The rvalue and lvalue decomposition of std::complex can be accomplished
with a simple pure-library extension:
Provide a tuple interface to std::complex.
// Tuple interface to class template complex.
#define __cxx_lib_tuple_complex 201705
// Declare tuple_size.
template<typename RealTp>
class tuple_size;
// Partial specialization for std::complex.
template<typename RealTp>
struct tuple_size<std::complex<RealTp>>
: public integral_constant<std::size_t, 2> { };
// Declare tuple_element.
template<std::size_t _Int, typename RealTp>
class tuple_element;
// Partial specialization for std::complex.
template<std::size_t _Int, typename RealTp>
struct tuple_element<_Int, std::complex<RealTp>>
{
static_assert(_Int < 2, "index is out of bounds");
typedef RealTp type;
};
// Decompose complex as rvalues.
template<std::size_t _Int, typename RealTp>
constexpr const RealTp
get(const std::complex<RealTp>& z)
{
static_assert(_Int < 2, "index is out of bounds");
return _Int == 0 ? z.real() : z.imag();
}
// Decompose complex as lvalues.
template<std::size_t _Int, typename RealTp>
constexpr RealTp&
get(std::complex<RealTp>& z)
{
static_assert(_Int < 2, "index is out of bounds");
auto w = reinterpret_cast<RealTp(&)[2]>(z);
return _Int == 0 ? w[0] : w[1];
}
Then we have the following behavior:
template<typename Tp>
void
test_complex_decomp()
{
std::complex<Tp> z(1, 2);
auto [x, y] = z;
std::cout << "z = " << z << '\n';
std::cout << "z parts:" << ' ' << x << ' ' << y << '\n';
z.real(3);
z.imag(4);
std::cout << "z = " << z << '\n';
std::cout << "z parts:" << ' ' << x << ' ' << y << '\n';
std::complex<Tp> w(1, 2);
std::cout << "w = " << w << '\n';
auto& [p, q] = w;
w.real(3);
w.imag(4);
std::cout << "w = " << w << '\n';
std::cout << "w parts:" << ' ' << p << ' ' << q << '\n';
p = -5;
q = -6;
std::cout << "w = " << w << '\n';
std::cout << "w parts:" << ' ' << p << ' ' << q << '\n';
return;
}
int
main()
{
test_complex_decomp<double>();
return 0;
}
-------------------
z = (1,2)
z parts: 1 2
z = (3,4)
z parts: 1 2
w = (1,2)
w = (3,4)
w parts: 3 4
w = (-5,-6)
w parts: -5 -6
-------------------
The static cast, ugly as it is, is required to be valid by conforming
implementations of complex.
29.5 Complex numbers [complex.numbers] p4, specifically 4.1-4.3.
This solution elegantly isolates user code from this wart.
--
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/74a45396-2e35-4231-86b9-4caceb531239%40isocpp.org.
------=_Part_1179_908813261.1492121488415
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">In many uses of std::complex<br> one wants to capture the =
real and imaginary parts in separate variables either to use them in subseq=
uent calculations or to modify them individually.<br>There are many options=
:<br><br>These options reflect an over-encapsulation of std::complex, which=
everyone agrees is a struct with two floating point numbers, real part and=
imaginary part, in that order.<br>Attempting to use a decomposition declar=
ation for a complex number is an error because of the pretension (ostensibl=
y for C compatibility) the complex numbers are opaque.<br><br>The rvalue an=
d lvalue decomposition of std::complex can be accomplished with a simple pu=
re-library extension:<br>Provide a tuple interface to std::complex.<br><br>=
<div style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, =
187, 187); border-style: solid; border-width: 1px; overflow-wrap: break-wor=
d;" class=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"subpret=
typrint"><span style=3D"color: #000;" class=3D"styled-by-prettify">=C2=A0 <=
/span><span style=3D"color: #800;" class=3D"styled-by-prettify">// Tuple in=
terface to class template complex.</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #800;" class=3D"st=
yled-by-prettify">#define</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> __cxx_lib_tuple_complex </span><span style=3D"color: #066;"=
class=3D"styled-by-prettify">201705</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br><br>=C2=A0 </span><span style=3D"color: #800;=
" class=3D"styled-by-prettify">// Declare tuple_size.</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">template</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" clas=
s=3D"styled-by-prettify">RealTp</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">></span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> tuple_size</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br><br>=C2=A0 </span><span style=3D"color: #800;" class=3D"styl=
ed-by-prettify">// Partial specialization for std::complex.</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">template</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify"><</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: #606;=
" class=3D"styled-by-prettify">RealTp</span><span style=3D"color: #660;" cl=
ass=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">struct</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> tuple_size</span><span style=3D"color: #660;" cla=
ss=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"styled-by-prett=
ify">complex</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
"><</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Real=
Tp</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"> </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">public</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> integral_constant</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"colo=
r: #000;" class=3D"styled-by-prettify">size_t</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: #066;" class=3D"sty=
led-by-prettify">2</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">></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 st=
yle=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br><br>=C2=A0 </span><span style=
=3D"color: #800;" class=3D"styled-by-prettify">// Declare tuple_element.</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">template</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><sp=
an 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">size_t _Int</span><span style=3D"co=
lor: #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"> </span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">RealTp</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">></span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-=
by-prettify">class</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> tuple_element</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br><br>=C2=A0 </span><span style=3D"color: #800;" class=3D"styled-by-pr=
ettify">// Partial specialization for std::complex.</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">template</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">std</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">size_t _Int</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: #000;" class=3D"styled-by-prettify">=
</span><span style=3D"color: #606;" class=3D"styled-by-prettify">RealTp</s=
pan><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">struct</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> tuple_element<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">_Int</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"styled-by-prettify">complex</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify"><</span><span style=3D"color: #606;" class=3D"=
styled-by-prettify">RealTp</span><span style=3D"color: #660;" class=3D"styl=
ed-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"style=
d-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #008;"=
class=3D"styled-by-prettify">static_assert</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">_Int </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: #066;" class=3D"styled-by-pretti=
fy">2</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #080;" class=3D"styled-by-prettify">"index is out of b=
ounds"</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-pr=
ettify">typedef</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Real=
Tp</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> type</s=
pan><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 </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">};</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>=C2=A0 </span>=
<span style=3D"color: #800;" class=3D"styled-by-prettify">// Decompose comp=
lex as rvalues.</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br>=C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">template</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy"><</span><span style=3D"color: #000;" class=3D"styled-by-prettify">st=
d</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">size_t _Int</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;"=
class=3D"styled-by-prettify">RealTp</span><span style=3D"color: #660;" cla=
ss=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;" c=
lass=3D"styled-by-prettify">constexpr</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">const</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-pretti=
fy">RealTp</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-pr=
ettify">get</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>(</span><span style=3D"color: #008;" class=3D"styled-by-prettify">const</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">complex</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"co=
lor: #606;" class=3D"styled-by-prettify">RealTp</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">>&</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> z</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br>=C2=A0 =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">static_assert</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">_Int </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-p=
rettify">2</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">"index is out=
of bounds"</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r>=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-p=
rettify"> _Int </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">=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: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">?</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> z</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">real</span><span style=3D"color: #660;" class=3D"st=
yled-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"> z</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">imag</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><br>=C2=A0 </span><span style=3D"=
color: #800;" class=3D"styled-by-prettify">// Decompose complex as lvalues.=
</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">template<=
/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 s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">size_t _Int</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;" cla=
ss=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">RealTp</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">></span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-=
by-prettify">constexpr</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettif=
y">RealTp</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
amp;</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-pretti=
fy">get</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">complex</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"co=
lor: #606;" class=3D"styled-by-prettify">RealTp</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">>&</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> z</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br>=C2=A0 =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">static_assert</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">_Int </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-p=
rettify">2</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">"index is out=
of bounds"</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r>=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-=
by-prettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> w </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">reinterpret_cast=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span=
><span style=3D"color: #606;" class=3D"styled-by-prettify">RealTp</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">(&)[</span><span=
style=3D"color: #066;" class=3D"styled-by-prettify">2</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">]>(</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">z</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"colo=
r: #008;" class=3D"styled-by-prettify">return</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> _Int </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">=3D=3D</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"st=
yled-by-prettify">0</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"> w</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">[</span><span sty=
le=3D"color: #066;" class=3D"styled-by-prettify">0</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: #660;" class=
=3D"styled-by-prettify">:</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> w</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">[</span><span style=3D"color: #066;" class=3D"styled-by-prettify">1<=
/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: #660;" class=3D"styled-by-prettify">}</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span></div=
></code></div><br><br>Then we have the following behavior:<br><br><div styl=
e=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187)=
; border-style: solid; border-width: 1px; overflow-wrap: break-word;" class=
=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"subprettyprint">=
<span style=3D"color: #008;" class=3D"styled-by-prettify">template</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">typename</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #606;" class=3D"styled-by-prettify">Tp</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">></span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br>=C2=A0 </span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">void</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br>=C2=A0 test_complex_decomp</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 </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 std</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">complex</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify"><</span><span style=3D"color: #606;" class=3D"st=
yled-by-prettify">Tp</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">></span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> z</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</s=
pan><span style=3D"color: #066;" 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"> </span><span style=3D"color: #=
066;" class=3D"styled-by-prettify">2</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;"=
class=3D"styled-by-prettify">auto</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: #000;" class=3D"styled-by-pret=
tify">x</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> y</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=
: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> z</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>=C2=A0 =C2=A0 std</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">cout </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=
">"z =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: #000;" class=3D"styled-by-prettify"> =
z </span><span style=3D"color: #660;" class=3D"styled-by-prettify"><<=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #080;" class=3D"styled-by-prettify">'\n'</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 std</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify">cout </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">"z parts:"</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify"><<</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #080;" c=
lass=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"st=
yled-by-prettify"> x </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify"><<</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #080;" 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"> y </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify"><<</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #080;" class=3D"styled-by-prettify">'\n'</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br><br>=C2=A0 =C2=A0 z</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">real</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;" class=3D"=
styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br>=C2=A0 =C2=A0 z</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">.</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">imag</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">(</span><span style=3D"color: #066;" class=3D"styled-by-prettify">4</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 st=
d</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">cout </span><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: #080;" class=3D"styled-by-prettify">"z =3D "</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"colo=
r: #000;" class=3D"styled-by-prettify"> z </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">'\n'</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>=C2=A0 =C2=A0 std</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">cout </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=
">"z parts:"</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y"><<</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #080;" class=3D"styled-by-prettify">' &#=
39;</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"> x </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify"><<</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #080;" class=3D"styled-by-prettify">' '</span><span style=3D"col=
or: #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"> y </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"style=
d-by-prettify">'\n'</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br><br>=C2=A0 =C2=A0 std</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">complex</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify"><</span><span style=3D"color: #606;" class=3D"styled-by-pre=
ttify">Tp</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> w</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span s=
tyle=3D"color: #066;" class=3D"styled-by-prettify">1</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: #066;" class=
=3D"styled-by-prettify">2</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br>=C2=A0 =C2=A0 std</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">cout </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify"><<</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #080;" class=3D"styled-by-prettify">"=
w =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: #000;" class=3D"styled-by-prettify"> w </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify"><<</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #080;" class=3D"styled-by-prettify">'\n'</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">auto</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">p</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> q</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</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> w</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br><br>=C2=A0 =C2=A0 w</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">real</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">(</span><span style=3D"color: #066;" class=3D"styl=
ed-by-prettify">3</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br>=C2=A0 =C2=A0 w</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">i=
mag</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span style=3D"color: #066;" class=3D"styled-by-prettify">4</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 std</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">cout </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify"><<</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #080;=
" class=3D"styled-by-prettify">"w =3D "</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;"=
class=3D"styled-by-prettify"><<</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> w </span><span style=3D"color: #660;" class=3D=
"styled-by-prettify"><<</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #080;" class=3D"styled-by-=
prettify">'\n'</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br>=C2=A0 =C2=A0 std</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">cout </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">"w pa=
rts:"</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><sp=
an style=3D"color: #080;" class=3D"styled-by-prettify">' '</span><s=
pan 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"> p </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: #080;" =
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"s=
tyled-by-prettify"> q </span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify"><<</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #080;" class=3D"styled-by-prettify"=
>'\n'</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><b=
r>=C2=A0 =C2=A0 p </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">=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: #066;" class=3D"styled-by-prettify">5</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 q </span><span st=
yle=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: #6=
60;" class=3D"styled-by-prettify">-</span><span style=3D"color: #066;" clas=
s=3D"styled-by-prettify">6</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br>=C2=A0 =C2=A0 std</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">cout </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify"><<</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #080;" class=3D"styled-by-prettify">"=
w =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: #000;" class=3D"styled-by-prettify"> w </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify"><<</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #080;" class=3D"styled-by-prettify">'\n'</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 std</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">cout </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify"><<</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #080;" c=
lass=3D"styled-by-prettify">"w parts:"</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;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=3D"st=
yled-by-prettify">' '</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-=
prettify"><<</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> p </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: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify"><<</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> q </span><span styl=
e=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">'\n'</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br><br>=C2=A0 =C2=A0 </span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">return</span><span style=3D"colo=
r: #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><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br>main</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><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 test_complex_decomp</span><span style=3D"color: #080;" class=3D"styled-=
by-prettify"><double></span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">();</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">return</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">0<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br><br></span></div></code></div><=
br><br>-------------------<br>z =3D (1,2)<br>z parts: 1 2<br>z =3D (3,4)<br=
>z parts: 1 2<br>w =3D (1,2)<br>w =3D (3,4)<br>w parts: 3 4<br>w =3D (-5,-6=
)<br>w parts: -5 -6<br>-------------------<br><br>The static cast, ugly as =
it is, is required to be valid by conforming implementations of complex.<br=
>29.5 Complex numbers [complex.numbers] p4, specifically 4.1-4.3.<br>This s=
olution elegantly isolates user code from this wart.<br><br></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/74a45396-2e35-4231-86b9-4caceb531239%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/74a45396-2e35-4231-86b9-4caceb531239=
%40isocpp.org</a>.<br />
------=_Part_1179_908813261.1492121488415--
------=_Part_1178_2054269446.1492121488413--
.
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Fri, 14 Apr 2017 19:01:55 +0200
Raw View
This is a multi-part message in MIME format.
--------------405F0B4D6009C044D992406E
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Le 14/04/2017 =C3=A0 00:11, 3dw4rd@verizon.net a =C3=A9crit :
> In many uses of std::complex
> one wants to capture the real and imaginary parts in separate=20
> variables either to use them in subsequent calculations or to modify=20
> them individually.
> There are many options:
>
> These options reflect an over-encapsulation of std::complex, which=20
> everyone agrees is a struct with two floating point numbers, real part=20
> and imaginary part, in that order.
> Attempting to use a decomposition declaration for a complex number is=20
> an error because of the pretension (ostensibly for C compatibility)=20
> the complex numbers are opaque.
Humm, it is not so opaque as you can get the representation as a c-array.
This means that we should already be able to apply structured binding=20
using the cast
|auto&[p,q]=3D|||reinterpret_cast<Tp(&)[2]>(z)|;
|
Nevertheles I agree with you that your proposal makes this cleaner and=20
more explicit. Complex should be a ProductType.
>
> The rvalue and lvalue decomposition of std::complex can be=20
> accomplished with a simple pure-library extension:
> Provide a tuple interface to std::complex.
>
> |
> // Tuple interface to class template complex.
> #define__cxx_lib_tuple_complex 201705
>
> // Declare tuple_size.
> template<typenameRealTp>
> classtuple_size;
>
> // Partial specialization for std::complex.
> template<typenameRealTp>
> structtuple_size<std::complex<RealTp>>
> :publicintegral_constant<std::size_t,2>{};
>
> // Declare tuple_element.
> template<std::size_t _Int,typenameRealTp>
> classtuple_element;
>
> // Partial specialization for std::complex.
> template<std::size_t _Int,typenameRealTp>
> structtuple_element<_Int,std::complex<RealTp>>
> {
> static_assert(_Int <2,"index is out of bounds");
> typedefRealTptype;
> };
>
> // Decompose complex as rvalues.
> template<std::size_t _Int,typenameRealTp>
> constexprconstRealTp
> get(conststd::complex<RealTp>&z)
> {
> static_assert(_Int <2,"index is out of bounds");
> return_Int =3D=3D0?z.real():z.imag();
> }
>
> // Decompose complex as lvalues.
> template<std::size_t _Int,typenameRealTp>
> constexprRealTp&
> get(std::complex<RealTp>&z)
> {
> static_assert(_Int <2,"index is out of bounds");
> autow =3Dreinterpret_cast<RealTp(&)[2]>(z);
> return_Int =3D=3D0?w[0]:w[1];
> }
>
> |
>
I believed that this reinterpret_cast was UB, but as you note below, it=20
is defined by the standard.
>
> Then we have the following behavior:
>
> |
> template<typenameTp>
> void
> test_complex_decomp()
> {
> std::complex<Tp>z(1,2);
>
> auto[x,y]=3Dz;
> std::cout <<"z =3D "<<z <<'\n';
> std::cout <<"z parts:"<<' '<<x <<' '<<y <<'\n';
>
> |
|I'm not sure if you believe this implies a call to get to decomponse as=20
rvalues, but it isn't.
It just copies the complex to a temporary, ||and then calls get on this=20
temporary.
|
> |
> z.real(3);
> z.imag(4);
> std::cout <<"z =3D "<<z <<'\n';
> std::cout <<"z parts:"<<' '<<x <<' '<<y <<'\n';
>
> std::complex<Tp>w(1,2);
> std::cout <<"w =3D "<<w <<'\n';
> auto&[p,q]=3Dw;
>
> |
|I'm not sure if you believe this implies a call to get to decomponse as=20
lvalues, but it isn't.
||It just takes store a reference to the complex in a temporary, and=20
then calls get on this temporary reference.
|
> |
> |
> |
> w.real(3);
> w.imag(4);
> std::cout <<"w =3D "<<w <<'\n';
> std::cout <<"w parts:"<<' '<<p <<' '<<q <<'\n';
>
> p =3D-5;
> q =3D-6;
> std::cout <<"w =3D "<<w <<'\n';
> std::cout <<"w parts:"<<' '<<p <<' '<<q <<'\n';
>
> return;
> }
>
> int
> main()
> {
> test_complex_decomp<double>();
> return0;
> }
>
> |
>
>
> -------------------
> z =3D (1,2)
> z parts: 1 2
> z =3D (3,4)
> z parts: 1 2
> w =3D (1,2)
> w =3D (3,4)
> w parts: 3 4
> w =3D (-5,-6)
> w parts: -5 -6
> -------------------
>
> The static cast, ugly as it is, is required to be valid by conforming=20
> implementations of complex.
Are you talking of the reinterpret_cast?
> 29.5 Complex numbers [complex.numbers] p4, specifically 4.1-4.3.
> This solution elegantly isolates user code from this wart.
I believe that you need const/non const lvalue/rvalue decomposition, but=20
maybe I'm wrong.
|template<std::size_t _Int,typenameRealTp>
constexprconstRealTp&&
get(const std::complex<RealTp>&& z)
{
static_assert(_Int <2,"index is out of bounds");
return_Int =3D=3D0?z.real():z.imag();
}
|
||template<std::size_t _Int,typenameRealTp>
constexprRealTp&&
get(std::complex<RealTp>&& z)
{
static_assert(_Int <2,"index is out of bounds");
return_Int =3D=3D0?z.real():z.imag();
}
| // Decompose complex as lvalues.
template<std::size_t _Int,typenameRealTp>
constexprRealTp&
get(std::complex<RealTp>&z)
{
static_assert(_Int <2,"index is out of bounds");
autow =3Dreinterpret_cast<RealTp(&)[2]>(z);
return_Int =3D=3D0?w[0]:w[1];
}
|
|// Decompose complex as lvalues.
template<std::size_t _Int,typenameRealTp>
constexprRealTpconst&
get(const std::complex<RealTp>&z)
{
static_assert(_Int <2,"index is out of bounds");
autow =3Dreinterpret_cast<RealTpconst(&)[2]>(z);
return_Int =3D=3D0?w[0]:w[1];
}
|
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/4259d7dc-f060-dc27-5004-37bf4726e456%40wanadoo.f=
r.
--------------405F0B4D6009C044D992406E
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 14/04/2017 =C3=A0 00:11,
<a class=3D"moz-txt-link-abbreviated" href=3D"mailto:3dw4rd@verizon.n=
et">3dw4rd@verizon.net</a> a =C3=A9crit=C2=A0:<br>
</div>
<blockquote
cite=3D"mid:74a45396-2e35-4231-86b9-4caceb531239@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">In many uses of std::complex<br>
one wants to capture the real and imaginary parts in separate
variables either to use them in subsequent calculations or to
modify them individually.<br>
There are many options:<br>
<br>
These options reflect an over-encapsulation of std::complex,
which everyone agrees is a struct with two floating point
numbers, real part and imaginary part, in that order.<br>
Attempting to use a decomposition declaration for a complex
number is an error because of the pretension (ostensibly for C
compatibility) the complex numbers are opaque.<br>
</div>
</blockquote>
Humm, it is not so opaque as you can get the representation as a
c-array.<br>
<br>
This means that we should already be able to apply structured
binding using the cast<br>
<br>
<code class=3D"prettyprint"><span style=3D"color: #000;"
class=3D"styled-by-prettify">=C2=A0 =C2=A0 </span><span style=3D"co=
lor:
#008;" class=3D"styled-by-prettify">auto</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">p</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> q</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</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span></code>=
<code
class=3D"prettyprint"><span style=3D"color: #000;"
class=3D"styled-by-prettify"><code class=3D"prettyprint"><span
style=3D"color: #000;" class=3D"styled-by-prettify"></span><spa=
n
style=3D"color: #008;" class=3D"styled-by-prettify">reinterpret=
_cast</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</span>=
<span
style=3D"color: #606;" class=3D"styled-by-prettify">Tp</span><s=
pan
style=3D"color: #660;" class=3D"styled-by-prettify">(&)[</s=
pan><span
style=3D"color: #066;" class=3D"styled-by-prettify">2</span><sp=
an
style=3D"color: #660;" class=3D"styled-by-prettify">]>(</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify">z</span><sp=
an
style=3D"color: #660;" class=3D"styled-by-prettify">)</span></c=
ode></span><span
style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
</span></code><br>
Nevertheles I agree with you that your proposal makes this cleaner
and more explicit. Complex should be a ProductType.<br>
<blockquote
cite=3D"mid:74a45396-2e35-4231-86b9-4caceb531239@isocpp.org"
type=3D"cite">
<div dir=3D"ltr"><br>
The rvalue and lvalue decomposition of std::complex can be
accomplished with a simple pure-library extension:<br>
Provide a tuple interface to std::complex.<br>
<br>
<div style=3D"background-color: rgb(250, 250, 250); border-color:
rgb(187, 187, 187); border-style: solid; border-width: 1px;
overflow-wrap: break-word;" class=3D"prettyprint"><code
class=3D"prettyprint">
<div class=3D"subprettyprint"><span style=3D"color: #000;"
class=3D"styled-by-prettify">=C2=A0 </span><span style=3D"c=
olor:
#800;" class=3D"styled-by-prettify">// Tuple interface to
class template complex.</span><span style=3D"color: #000;"
class=3D"styled-by-prettify"><br>
</span><span style=3D"color: #800;"
class=3D"styled-by-prettify">#define</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
__cxx_lib_tuple_complex </span><span style=3D"color:
#066;" class=3D"styled-by-prettify">201705</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
<br>
=C2=A0 </span><span style=3D"color: #800;"
class=3D"styled-by-prettify">// Declare tuple_size.</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">template</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</s=
pan><span
style=3D"color: #008;" class=3D"styled-by-prettify">typenam=
e</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp<=
/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 </span><span style=3D"color: #008;"
class=3D"styled-by-prettify">class</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
tuple_size</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">;</span><span style=3D"color:
#000;" class=3D"styled-by-prettify"><br>
<br>
=C2=A0 </span><span style=3D"color: #800;"
class=3D"styled-by-prettify">// Partial specialization for
std::complex.</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">template</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</s=
pan><span
style=3D"color: #008;" class=3D"styled-by-prettify">typenam=
e</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp<=
/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 </span><span style=3D"color: #008;"
class=3D"styled-by-prettify">struct</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
tuple_size</span><span style=3D"color: #660;"
class=3D"styled-by-prettify"><</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">std</sp=
an><span
style=3D"color: #660;" class=3D"styled-by-prettify">::</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify">complex=
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</s=
pan><span
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp<=
/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"> </span><span
style=3D"color: #008;" class=3D"styled-by-prettify">public<=
/span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
integral_constant</span><span style=3D"color: #660;"
class=3D"styled-by-prettify"><</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">std</sp=
an><span
style=3D"color: #660;" class=3D"styled-by-prettify">::</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify">size_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: #066;" class=3D"styled-by-prettify">2</span=
><span
style=3D"color: #660;" class=3D"styled-by-prettify">></s=
pan><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #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">};</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
<br>
=C2=A0 </span><span style=3D"color: #800;"
class=3D"styled-by-prettify">// Declare tuple_element.</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
=C2=A0 </span><span style=3D"color: #008;"
class=3D"styled-by-prettify">template</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</s=
pan><span
style=3D"color: #000;" class=3D"styled-by-prettify">std</sp=
an><span
style=3D"color: #660;" class=3D"styled-by-prettify">::</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify">size_t
_Int</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"> </span=
><span
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp<=
/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 </span><span style=3D"color: #008;"
class=3D"styled-by-prettify">class</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
tuple_element</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">;</span><span style=3D"color:
#000;" class=3D"styled-by-prettify"><br>
<br>
=C2=A0 </span><span style=3D"color: #800;"
class=3D"styled-by-prettify">// Partial specialization for
std::complex.</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">template</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</s=
pan><span
style=3D"color: #000;" class=3D"styled-by-prettify">std</sp=
an><span
style=3D"color: #660;" class=3D"styled-by-prettify">::</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify">size_t
_Int</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"> </span=
><span
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp<=
/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 </span><span style=3D"color: #008;"
class=3D"styled-by-prettify">struct</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">
tuple_element</span><span style=3D"color: #660;"
class=3D"styled-by-prettify"><</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">_Int</s=
pan><span
style=3D"color: #660;" class=3D"styled-by-prettify">,</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify"> std</s=
pan><span
style=3D"color: #660;" class=3D"styled-by-prettify">::</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify">complex=
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</s=
pan><span
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp<=
/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 =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: #000;" class=3D"styled-by-prettify">_Int </=
span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</s=
pan><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #066;" class=3D"styled-by-prettify">2</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">"index
is out of bounds"</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-prettify">typedef</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp<=
/span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> type</=
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>
<br>
=C2=A0 </span><span style=3D"color: #800;"
class=3D"styled-by-prettify">// Decompose complex as
rvalues.</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">template</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</s=
pan><span
style=3D"color: #000;" class=3D"styled-by-prettify">std</sp=
an><span
style=3D"color: #660;" class=3D"styled-by-prettify">::</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify">size_t
_Int</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"> </span=
><span
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp<=
/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 </span><span style=3D"color: #008;"
class=3D"styled-by-prettify">constexpr</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #008;" class=3D"styled-by-prettify">const</=
span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp<=
/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">get</span><span style=3D"color=
:
#660;" class=3D"styled-by-prettify">(</span><span
style=3D"color: #008;" class=3D"styled-by-prettify">const</=
span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> std</s=
pan><span
style=3D"color: #660;" class=3D"styled-by-prettify">::</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify">complex=
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</s=
pan><span
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp<=
/span><span
style=3D"color: #660;" class=3D"styled-by-prettify">>&am=
p;</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> z</spa=
n><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 =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: #000;" class=3D"styled-by-prettify">_Int </=
span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</s=
pan><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #066;" class=3D"styled-by-prettify">2</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">"index
is out of bounds"</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-prettify">return</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> _Int <=
/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: #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"> z</spa=
n><span
style=3D"color: #660;" class=3D"styled-by-prettify">.</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify">real</s=
pan><span
style=3D"color: #660;" class=3D"styled-by-prettify">()</spa=
n><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"> z</spa=
n><span
style=3D"color: #660;" class=3D"styled-by-prettify">.</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify">imag</s=
pan><span
style=3D"color: #660;" class=3D"styled-by-prettify">();</sp=
an><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
=C2=A0 =C2=A0 </span><span style=3D"color: #660;"
class=3D"styled-by-prettify">}</span><span style=3D"color:
#000;" class=3D"styled-by-prettify"><br>
<br>
=C2=A0 </span><span style=3D"color: #800;"
class=3D"styled-by-prettify">// Decompose complex as
lvalues.</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">template</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</s=
pan><span
style=3D"color: #000;" class=3D"styled-by-prettify">std</sp=
an><span
style=3D"color: #660;" class=3D"styled-by-prettify">::</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify">size_t
_Int</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"> </span=
><span
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp<=
/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 </span><span style=3D"color: #008;"
class=3D"styled-by-prettify">constexpr</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp<=
/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">get</span><span style=3D"color=
:
#660;" class=3D"styled-by-prettify">(</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">std</sp=
an><span
style=3D"color: #660;" class=3D"styled-by-prettify">::</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify">complex=
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</s=
pan><span
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp<=
/span><span
style=3D"color: #660;" class=3D"styled-by-prettify">>&am=
p;</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> z</spa=
n><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 =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: #000;" class=3D"styled-by-prettify">_Int </=
span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</s=
pan><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #066;" class=3D"styled-by-prettify">2</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">"index
is out of bounds"</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-prettify">auto</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> w </sp=
an><span
style=3D"color: #660;" class=3D"styled-by-prettify">=3D</sp=
an><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #008;" class=3D"styled-by-prettify">reinter=
pret_cast</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</s=
pan><span
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp<=
/span><span
style=3D"color: #660;" class=3D"styled-by-prettify">(&)=
[</span><span
style=3D"color: #066;" class=3D"styled-by-prettify">2</span=
><span
style=3D"color: #660;" class=3D"styled-by-prettify">]>(<=
/span><span
style=3D"color: #000;" class=3D"styled-by-prettify">z</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: #008;"
class=3D"styled-by-prettify">return</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> _Int <=
/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: #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"> w</spa=
n><span
style=3D"color: #660;" 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: #660;" class=3D"styled-by-prettify">:</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify"> w</spa=
n><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;" class=3D"styled-by-prettify">];</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
=C2=A0 =C2=A0 </span><span style=3D"color: #660;"
class=3D"styled-by-prettify">}</span><span style=3D"color:
#000;" class=3D"styled-by-prettify"><br>
<br>
</span></div>
</code></div>
<br>
</div>
</blockquote>
I believed that this reinterpret_cast was UB, but as you note below,
it is defined by the standard.<br>
<br>
<blockquote
cite=3D"mid:74a45396-2e35-4231-86b9-4caceb531239@isocpp.org"
type=3D"cite">
<div dir=3D"ltr"><br>
Then we have the following behavior:<br>
<br>
<div style=3D"background-color: rgb(250, 250, 250); border-color:
rgb(187, 187, 187); border-style: solid; border-width: 1px;
overflow-wrap: break-word;" class=3D"prettyprint"><code
class=3D"prettyprint">
<div class=3D"subprettyprint"><span style=3D"color: #008;"
class=3D"styled-by-prettify">template</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</s=
pan><span
style=3D"color: #008;" class=3D"styled-by-prettify">typenam=
e</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #606;" class=3D"styled-by-prettify">Tp</spa=
n><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 </span><span style=3D"color: #008;"
class=3D"styled-by-prettify">void</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
=C2=A0 test_complex_decomp</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><span style=3D"color:
#000;" class=3D"styled-by-prettify"><br>
=C2=A0 =C2=A0 std</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">::</span><span style=3D"color:
#000;" class=3D"styled-by-prettify">complex</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</s=
pan><span
style=3D"color: #606;" class=3D"styled-by-prettify">Tp</spa=
n><span
style=3D"color: #660;" class=3D"styled-by-prettify">></s=
pan><span
style=3D"color: #000;" class=3D"styled-by-prettify"> z</spa=
n><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;" class=3D"styled-by-prettify">,</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #066;" class=3D"styled-by-prettify">2</span=
><span
style=3D"color: #660;" class=3D"styled-by-prettify">);</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
<br>
=C2=A0 =C2=A0 </span><span style=3D"color: #008;"
class=3D"styled-by-prettify">auto</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">x</span=
><span
style=3D"color: #660;" class=3D"styled-by-prettify">,</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify"> y</spa=
n><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</sp=
an><span
style=3D"color: #000;" class=3D"styled-by-prettify"> z</spa=
n><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 std</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">::</span><span style=3D"color:
#000;" class=3D"styled-by-prettify">cout </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">"z =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: #000;" class=3D"styled-by-prettify"> z </sp=
an><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">'\n'</s=
pan><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 std</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">::</span><span style=3D"color:
#000;" class=3D"styled-by-prettify">cout </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">"z
parts:"</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: #080;" class=3D"styled-by-prettify">' '</sp=
an><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #660;" class=3D"styled-by-prettify"><<=
;</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> x </sp=
an><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">' '</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"> y </sp=
an><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">'\n'</s=
pan><span
style=3D"color: #660;" class=3D"styled-by-prettify">;</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
<br>
</span></div>
</code></div>
</div>
</blockquote>
<code>I'm not sure if you believe this implies a call to get to
decomponse as rvalues, but it isn't.<br>
It just copies the complex to a temporary, </code><code>and then
calls get on this temporary.<br>
<br>
</code>
<blockquote
cite=3D"mid:74a45396-2e35-4231-86b9-4caceb531239@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">
<div style=3D"background-color: rgb(250, 250, 250); border-color:
rgb(187, 187, 187); border-style: solid; border-width: 1px;
overflow-wrap: break-word;" class=3D"prettyprint"><code
class=3D"prettyprint">
<div class=3D"subprettyprint"><span style=3D"color: #000;"
class=3D"styled-by-prettify">=C2=A0 =C2=A0 z</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">.</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify">real</s=
pan><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;" class=3D"styled-by-prettify">);</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
=C2=A0 =C2=A0 z</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">.</span><span style=3D"color:
#000;" class=3D"styled-by-prettify">imag</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span
style=3D"color: #066;" class=3D"styled-by-prettify">4</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 std</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">::</span><span style=3D"color:
#000;" class=3D"styled-by-prettify">cout </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">"z =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: #000;" class=3D"styled-by-prettify"> z </sp=
an><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">'\n'</s=
pan><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 std</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">::</span><span style=3D"color:
#000;" class=3D"styled-by-prettify">cout </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">"z
parts:"</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: #080;" class=3D"styled-by-prettify">' '</sp=
an><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #660;" class=3D"styled-by-prettify"><<=
;</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> x </sp=
an><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">' '</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"> y </sp=
an><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">'\n'</s=
pan><span
style=3D"color: #660;" class=3D"styled-by-prettify">;</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
<br>
=C2=A0 =C2=A0 std</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">::</span><span style=3D"color:
#000;" class=3D"styled-by-prettify">complex</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</s=
pan><span
style=3D"color: #606;" class=3D"styled-by-prettify">Tp</spa=
n><span
style=3D"color: #660;" class=3D"styled-by-prettify">></s=
pan><span
style=3D"color: #000;" class=3D"styled-by-prettify"> w</spa=
n><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;" class=3D"styled-by-prettify">,</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #066;" class=3D"styled-by-prettify">2</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 std</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">::</span><span style=3D"color:
#000;" class=3D"styled-by-prettify">cout </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">"w =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: #000;" class=3D"styled-by-prettify"> w </sp=
an><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">'\n'</s=
pan><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">auto</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">p</span=
><span
style=3D"color: #660;" class=3D"styled-by-prettify">,</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify"> q</spa=
n><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</sp=
an><span
style=3D"color: #000;" class=3D"styled-by-prettify"> w</spa=
n><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>
</blockquote>
<code>I'm not sure if you believe this implies a call to get to
decomponse as lvalues, but it isn't.<br>
</code><code>It just takes store a reference to the complex in a
temporary, and then calls get on this temporary reference.<br>
</code>
<blockquote
cite=3D"mid:74a45396-2e35-4231-86b9-4caceb531239@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">
<div style=3D"background-color: rgb(250, 250, 250); border-color:
rgb(187, 187, 187); border-style: solid; border-width: 1px;
overflow-wrap: break-word;" class=3D"prettyprint"><code
class=3D"prettyprint">
<div class=3D"subprettyprint"><span style=3D"color: #000;"
class=3D"styled-by-prettify"></span></div>
</code></div>
</div>
</blockquote>
<br>
<blockquote
cite=3D"mid:74a45396-2e35-4231-86b9-4caceb531239@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">
<div style=3D"background-color: rgb(250, 250, 250); border-color:
rgb(187, 187, 187); border-style: solid; border-width: 1px;
overflow-wrap: break-word;" class=3D"prettyprint"><code
class=3D"prettyprint">
<div class=3D"subprettyprint"><span style=3D"color: #000;"
class=3D"styled-by-prettify">=C2=A0 =C2=A0 w</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">.</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify">real</s=
pan><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;" class=3D"styled-by-prettify">);</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
=C2=A0 =C2=A0 w</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">.</span><span style=3D"color:
#000;" class=3D"styled-by-prettify">imag</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span
style=3D"color: #066;" class=3D"styled-by-prettify">4</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 std</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">::</span><span style=3D"color:
#000;" class=3D"styled-by-prettify">cout </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">"w =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: #000;" class=3D"styled-by-prettify"> w </sp=
an><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">'\n'</s=
pan><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 std</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">::</span><span style=3D"color:
#000;" class=3D"styled-by-prettify">cout </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">"w
parts:"</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: #080;" class=3D"styled-by-prettify">' '</sp=
an><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #660;" class=3D"styled-by-prettify"><<=
;</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> p </sp=
an><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">' '</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"> q </sp=
an><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">'\n'</s=
pan><span
style=3D"color: #660;" class=3D"styled-by-prettify">;</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
<br>
=C2=A0 =C2=A0 p </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: #660;" class=3D"styled-by-prettify">-</span=
><span
style=3D"color: #066;" class=3D"styled-by-prettify">5</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 q </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: #660;" class=3D"styled-by-prettify">-</span=
><span
style=3D"color: #066;" class=3D"styled-by-prettify">6</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 std</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">::</span><span style=3D"color:
#000;" class=3D"styled-by-prettify">cout </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">"w =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: #000;" class=3D"styled-by-prettify"> w </sp=
an><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">'\n'</s=
pan><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 std</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">::</span><span style=3D"color:
#000;" class=3D"styled-by-prettify">cout </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">"w
parts:"</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: #080;" class=3D"styled-by-prettify">' '</sp=
an><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span
style=3D"color: #660;" class=3D"styled-by-prettify"><<=
;</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> p </sp=
an><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">' '</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"> q </sp=
an><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">'\n'</s=
pan><span
style=3D"color: #660;" class=3D"styled-by-prettify">;</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
<br>
=C2=A0 =C2=A0 </span><span style=3D"color: #008;"
class=3D"styled-by-prettify">return</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><span style=3D"color:
#000;" class=3D"styled-by-prettify"><br>
<br>
</span><span style=3D"color: #008;"
class=3D"styled-by-prettify">int</span><span style=3D"color=
:
#000;" class=3D"styled-by-prettify"><br>
main</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 test_complex_decomp</span><span style=3D"color: #080=
;"
class=3D"styled-by-prettify"><double></span><span
style=3D"color: #660;" class=3D"styled-by-prettify">();</sp=
an><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
=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"> </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"><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></div>
</code></div>
<br>
<br>
-------------------<br>
z =3D (1,2)<br>
z parts: 1 2<br>
z =3D (3,4)<br>
z parts: 1 2<br>
w =3D (1,2)<br>
w =3D (3,4)<br>
w parts: 3 4<br>
w =3D (-5,-6)<br>
w parts: -5 -6<br>
-------------------<br>
<br>
The static cast, ugly as it is, is required to be valid by
conforming implementations of complex.<br>
</div>
</blockquote>
Are you talking of the reinterpret_cast?<br>
<blockquote
cite=3D"mid:74a45396-2e35-4231-86b9-4caceb531239@isocpp.org"
type=3D"cite">
<div dir=3D"ltr">29.5 Complex numbers [complex.numbers] p4,
specifically 4.1-4.3.<br>
This solution elegantly isolates user code from this wart.</div>
</blockquote>
I believe that you need const/non const lvalue/rvalue decomposition,
but maybe I'm wrong.<br>
<br>
<code class=3D"prettyprint"><span style=3D"color: #000;"
class=3D"styled-by-prettify">=C2=A0 </span><span style=3D"color: #0=
08;"
class=3D"styled-by-prettify">template</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"styled-by-prettify">size_t _Int</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: #000;" class=3D"styled-by-prettify"> </span><span
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp</span><s=
pan
style=3D"color: #660;" class=3D"styled-by-prettify">></span><spa=
n
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">constexpr</span><span style=3D"color:
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color:
#008;" class=3D"styled-by-prettify">const</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp</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">get</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">(const </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">complex</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</span><spa=
n
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp</span><s=
pan
style=3D"color: #660;" class=3D"styled-by-prettify">>&</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify">& z</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 =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: #000;" class=3D"styled-by-prettify">_Int </span><sp=
an
style=3D"color: #660;" class=3D"styled-by-prettify"><</span><spa=
n
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span
style=3D"color: #066;" class=3D"styled-by-prettify">2</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">"index is out o=
f
bounds"</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-prettify">return</span><span style=3D"color:
#000;" class=3D"styled-by-prettify"> _Int </span><span
style=3D"color: #660;" class=3D"styled-by-prettify">=3D=3D</span><s=
pan
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: #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"> z</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">real</span><spa=
n
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"> z</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">imag</span><spa=
n
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>
<br>
</span></code><br>
<code class=3D"prettyprint"><span style=3D"color: #000;"
class=3D"styled-by-prettify"><code class=3D"prettyprint"><span
style=3D"color: #000;" class=3D"styled-by-prettify">=C2=A0 </sp=
an><span
style=3D"color: #008;" class=3D"styled-by-prettify">template</s=
pan><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><s=
pan
style=3D"color: #000;" class=3D"styled-by-prettify">size_t _Int=
</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">,</span><sp=
an
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an
style=3D"color: #008;" class=3D"styled-by-prettify">typename</s=
pan><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp</spa=
n><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">constexpr</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an
style=3D"color: #000;" class=3D"styled-by-prettify"></span><spa=
n
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp&=
&</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">get</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><s=
pan
style=3D"color: #000;" class=3D"styled-by-prettify">complex</sp=
an><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</span>=
<span
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp</spa=
n><span
style=3D"color: #660;" class=3D"styled-by-prettify">>&</=
span><span
style=3D"color: #000;" class=3D"styled-by-prettify">& z</sp=
an><span
style=3D"color: #660;" class=3D"styled-by-prettify">)</span><sp=
an
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 =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><sp=
an
style=3D"color: #000;" class=3D"styled-by-prettify">_Int </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: #066;" class=3D"styled-by-prettify">2</span><sp=
an
style=3D"color: #660;" class=3D"styled-by-prettify">,</span><sp=
an
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an
style=3D"color: #080;" class=3D"styled-by-prettify">"index is
out of bounds"</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-prettify">return</span><span style=3D"color:
#000;" class=3D"styled-by-prettify"> _Int </span><span
style=3D"color: #660;" class=3D"styled-by-prettify">=3D=3D</spa=
n><span
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an
style=3D"color: #066;" class=3D"styled-by-prettify">0</span><sp=
an
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an
style=3D"color: #660;" class=3D"styled-by-prettify">?</span><sp=
an
style=3D"color: #000;" class=3D"styled-by-prettify"> z</span><s=
pan
style=3D"color: #660;" class=3D"styled-by-prettify">.</span><sp=
an
style=3D"color: #000;" class=3D"styled-by-prettify">real</span>=
<span
style=3D"color: #660;" class=3D"styled-by-prettify">()</span><s=
pan
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an
style=3D"color: #660;" class=3D"styled-by-prettify">:</span><sp=
an
style=3D"color: #000;" class=3D"styled-by-prettify"> z</span><s=
pan
style=3D"color: #660;" class=3D"styled-by-prettify">.</span><sp=
an
style=3D"color: #000;" class=3D"styled-by-prettify">imag</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>
</span></code>=C2=A0 </span><span style=3D"color: #800;"
class=3D"styled-by-prettify">// Decompose complex as lvalues.</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
=C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">template</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
style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">size_t _Int</sp=
an><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: #000;" class=3D"styled-by-prettify"> </span><span
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp</span><s=
pan
style=3D"color: #660;" class=3D"styled-by-prettify">></span><spa=
n
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">constexpr</span><span style=3D"color:
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color:
#606;" class=3D"styled-by-prettify">RealTp</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">&</span><sp=
an
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">get</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"styled-by-prettify">complex</span><span style=3D"color:
#660;" class=3D"styled-by-prettify"><</span><span style=3D"color=
:
#606;" class=3D"styled-by-prettify">RealTp</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">>&</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify"> z</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 =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: #000;" class=3D"styled-by-prettify">_Int </span><sp=
an
style=3D"color: #660;" class=3D"styled-by-prettify"><</span><spa=
n
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span
style=3D"color: #066;" class=3D"styled-by-prettify">2</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">"index is out o=
f
bounds"</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-prettify">auto</span><span style=3D"color: #000;=
"
class=3D"styled-by-prettify"> w </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">reinterpret_cast</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</span><spa=
n
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp</span><s=
pan
style=3D"color: #660;" class=3D"styled-by-prettify">(&)[</span>=
<span
style=3D"color: #066;" class=3D"styled-by-prettify">2</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">]>(</span><s=
pan
style=3D"color: #000;" class=3D"styled-by-prettify">z</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-prettify">return</span><span style=3D"color:
#000;" class=3D"styled-by-prettify"> _Int </span><span
style=3D"color: #660;" class=3D"styled-by-prettify">=3D=3D</span><s=
pan
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: #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"> w</span><span
style=3D"color: #660;" 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: #660;" class=3D"styled-by-prettify">:</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> w</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;" 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>
</span></code><br>
<code class=3D"prettyprint"><span style=3D"color: #000;"
class=3D"styled-by-prettify">=C2=A0 </span><span style=3D"color: #8=
00;"
class=3D"styled-by-prettify">// Decompose complex as lvalues.</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify"><br>
=C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">template</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
style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span
style=3D"color: #000;" class=3D"styled-by-prettify">size_t _Int</sp=
an><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: #000;" class=3D"styled-by-prettify"> </span><span
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp</span><s=
pan
style=3D"color: #660;" class=3D"styled-by-prettify">></span><spa=
n
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">constexpr</span><span style=3D"color:
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color:
#606;" class=3D"styled-by-prettify">RealTp</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"> const&</sp=
an><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">get</span><span style=3D"color: #660;"
class=3D"styled-by-prettify">(const </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">complex</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</span><spa=
n
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp</span><s=
pan
style=3D"color: #660;" class=3D"styled-by-prettify">>&</span=
><span
style=3D"color: #000;" class=3D"styled-by-prettify"> z</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 =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: #000;" class=3D"styled-by-prettify">_Int </span><sp=
an
style=3D"color: #660;" class=3D"styled-by-prettify"><</span><spa=
n
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span
style=3D"color: #066;" class=3D"styled-by-prettify">2</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">"index is out o=
f
bounds"</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-prettify">auto</span><span style=3D"color: #000;=
"
class=3D"styled-by-prettify"> w </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">reinterpret_cast</span><span
style=3D"color: #660;" class=3D"styled-by-prettify"><</span><spa=
n
style=3D"color: #606;" class=3D"styled-by-prettify">RealTp</span><s=
pan
style=3D"color: #660;" class=3D"styled-by-prettify"> const(&)[<=
/span><span
style=3D"color: #066;" class=3D"styled-by-prettify">2</span><span
style=3D"color: #660;" class=3D"styled-by-prettify">]>(</span><s=
pan
style=3D"color: #000;" class=3D"styled-by-prettify">z</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-prettify">return</span><span style=3D"color:
#000;" class=3D"styled-by-prettify"> _Int </span><span
style=3D"color: #660;" class=3D"styled-by-prettify">=3D=3D</span><s=
pan
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: #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"> w</span><span
style=3D"color: #660;" 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: #660;" class=3D"styled-by-prettify">:</span><span
style=3D"color: #000;" class=3D"styled-by-prettify"> w</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;" 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>
</span></code><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/4259d7dc-f060-dc27-5004-37bf4726e456%=
40wanadoo.fr?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4259d7dc-f060-dc27-5004-37bf4726e456=
%40wanadoo.fr</a>.<br />
--------------405F0B4D6009C044D992406E--
.
Author: 3dw4rd@verizon.net
Date: Fri, 14 Apr 2017 13:01:17 -0700 (PDT)
Raw View
------=_Part_1227_1652640001.1492200077632
Content-Type: multipart/alternative;
boundary="----=_Part_1228_1846414457.1492200077635"
------=_Part_1228_1846414457.1492200077635
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Friday, April 14, 2017 at 1:02:02 PM UTC-4, Vicente J. Botet Escriba=20
wrote:
>
> Le 14/04/2017 =C3=A0 00:11, 3dw...@verizon.net <javascript:> a =C3=A9crit=
:
>
> In many uses of std::complex
> one wants to capture the real and imaginary parts in separate variables=
=20
> either to use them in subsequent calculations or to modify them=20
> individually.
> There are many options:
>
> These options reflect an over-encapsulation of std::complex, which=20
> everyone agrees is a struct with two floating point numbers, real part an=
d=20
> imaginary part, in that order.
> Attempting to use a decomposition declaration for a complex number is an=
=20
> error because of the pretension (ostensibly for C compatibility) the=20
> complex numbers are opaque.
>
> Humm, it is not so opaque as you can get the representation as a c-array.
>
> This means that we should already be able to apply structured binding=20
> using the cast
>
> auto& [p, q] =3D reinterpret_cast<Tp(&)[2]>(z);
>
This is certainly legal now. That's how I implement this. It's just fugly=
=20
and obscure for users.
> Nevertheles I agree with you that your proposal makes this cleaner and=20
> more explicit. Complex should be a ProductType.
>
>
> The rvalue and lvalue decomposition of std::complex can be accomplished=
=20
> with a simple pure-library extension:
> Provide a tuple interface to std::complex.
>
> // Tuple interface to class template complex.
> #define __cxx_lib_tuple_complex 201705
>
> // Declare tuple_size.
> template<typename RealTp>
> class tuple_size;
>
> // Partial specialization for std::complex.
> template<typename RealTp>
> struct tuple_size<std::complex<RealTp>>
> : public integral_constant<std::size_t, 2> { };
>
> // Declare tuple_element.
> template<std::size_t _Int, typename RealTp>
> class tuple_element;
>
> // Partial specialization for std::complex.
> template<std::size_t _Int, typename RealTp>
> struct tuple_element<_Int, std::complex<RealTp>>
> {
> static_assert(_Int < 2, "index is out of bounds");
> typedef RealTp type;
> };
>
> // Decompose complex as rvalues.
> template<std::size_t _Int, typename RealTp>
> constexpr const RealTp
> get(const std::complex<RealTp>& z)
> {
> static_assert(_Int < 2, "index is out of bounds");
> return _Int =3D=3D 0 ? z.real() : z.imag();
> }
>
> // Decompose complex as lvalues.
> template<std::size_t _Int, typename RealTp>
> constexpr RealTp&
> get(std::complex<RealTp>& z)
> {
> static_assert(_Int < 2, "index is out of bounds");
> auto w =3D reinterpret_cast<RealTp(&)[2]>(z);
> return _Int =3D=3D 0 ? w[0] : w[1];
> }
>
>
> I believed that this reinterpret_cast was UB, but as you note below, it i=
s=20
> defined by the standard.
>
>
> Then we have the following behavior:
>
> template<typename Tp>
> void
> test_complex_decomp()
> {
> std::complex<Tp> z(1, 2);
>
> auto [x, y] =3D z;
> std::cout << "z =3D " << z << '\n';
> std::cout << "z parts:" << ' ' << x << ' ' << y << '\n';
>
> I'm not sure if you believe this implies a call to get to decomponse as=
=20
> rvalues, but it isn't.
> It just copies the complex to a temporary, and then calls get on this=20
> temporary.
>
The z, x, y part is lvalue decomp.
..=20
>
> z.real(3);
> z.imag(4);
> std::cout << "z =3D " << z << '\n';
> std::cout << "z parts:" << ' ' << x << ' ' << y << '\n';
>
> std::complex<Tp> w(1, 2);
> std::cout << "w =3D " << w << '\n';
> auto& [p, q] =3D w;
>
> I'm not sure if you believe this implies a call to get to decomponse as=
=20
> lvalues, but it isn't.
> It just takes store a reference to the complex in a temporary, and then=
=20
> calls get on this temporary reference.
>
The w, p, q part is rvalue decomp.
=20
>
> w.real(3);
> w.imag(4);
> std::cout << "w =3D " << w << '\n';
> std::cout << "w parts:" << ' ' << p << ' ' << q << '\n';
>
> p =3D -5;
> q =3D -6;
> std::cout << "w =3D " << w << '\n';
> std::cout << "w parts:" << ' ' << p << ' ' << q << '\n';
>
> return;
> }
>
> int
> main()
> {
> test_complex_decomp<double>();
> return 0;
> }
>
>
>
> -------------------
> z =3D (1,2)
> z parts: 1 2
> z =3D (3,4)
> z parts: 1 2
> w =3D (1,2)
> w =3D (3,4)
> w parts: 3 4
> w =3D (-5,-6)
> w parts: -5 -6
> -------------------
>
> The static cast, ugly as it is, is required to be valid by conforming=20
> implementations of complex.
>
> Are you talking of the reinterpret_cast?
>
Yes, reinterpret_cast. sorry.
=20
> 29.5 Complex numbers [complex.numbers] p4, specifically 4.1-4.3.
> This solution elegantly isolates user code from this wart.
>
> I believe that you need const/non const lvalue/rvalue decomposition, but=
=20
> maybe I'm wrong.
>
> template<std::size_t _Int, typename RealTp>
> constexpr const RealTp&&
> get(const std::complex<RealTp>&& z)
> {
> static_assert(_Int < 2, "index is out of bounds");
> return _Int =3D=3D 0 ? z.real() : z.imag();
> }
>
> Not sure about this one. I think it just might not be useful.=20
>
> template<std::size_t _Int, typename RealTp>
> constexpr RealTp&&
> get(std::complex<RealTp>&& z)
> {
> static_assert(_Int < 2, "index is out of bounds");
> return _Int =3D=3D 0 ? z.real() : z.imag();
> }
>
I think you're right here. std::array has at least this one.
=20
> // Decompose complex as lvalues.
>
// Decompose complex as rvalues.
> template<std::size_t _Int, typename RealTp>
> constexpr RealTp&
> get(std::complex<RealTp>& z)
> {
> static_assert(_Int < 2, "index is out of bounds");
> auto w =3D reinterpret_cast<RealTp(&)[2]>(z);
> return _Int =3D=3D 0 ? w[0] : w[1];
> }
>
> // Decompose complex as lvalues.
> template<std::size_t _Int, typename RealTp>
> constexpr RealTp const&
> get(const std::complex<RealTp>& z)
> {
> static_assert(_Int < 2, "index is out of bounds");
> auto w =3D reinterpret_cast<RealTp const(&)[2]>(z);
> return _Int =3D=3D 0 ? w[0] : w[1];
> }
>
> =20
Thank you for looking this over.
Ed
=20
> Vicente
>
=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/5fc8b8b9-c0f6-4620-b54a-62acde6cb7f0%40isocpp.or=
g.
------=_Part_1228_1846414457.1492200077635
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Friday, April 14, 2017 at 1:02:02 PM UTC-4, Vic=
ente J. Botet Escriba wrote:<blockquote class=3D"gmail_quote" style=3D"marg=
in: 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 14/04/2017 =C3=A0 00:11,
<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"AC=
xwaUT8DAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'javascript:=
9;;return true;" onclick=3D"this.href=3D'javascript:';return true;"=
>3dw...@verizon.net</a> a =C3=A9crit=C2=A0:<br>
</div>
<blockquote type=3D"cite">
<div dir=3D"ltr">In many uses of std::complex<br>
one wants to capture the real and imaginary parts in separate
variables either to use them in subsequent calculations or to
modify them individually.<br>
There are many options:<br>
<br>
These options reflect an over-encapsulation of std::complex,
which everyone agrees is a struct with two floating point
numbers, real part and imaginary part, in that order.<br>
Attempting to use a decomposition declaration for a complex
number is an error because of the pretension (ostensibly for C
compatibility) the complex numbers are opaque.<br>
</div>
</blockquote>
Humm, it is not so opaque as you can get the representation as a
c-array.<br>
<br>
This means that we should already be able to apply structured
binding using the cast<br>
<br>
<code><span style=3D"color:#000">=C2=A0 =C2=A0 </span><span style=3D"co=
lor:#008">auto</span><span style=3D"color:#660">&</span><span style=3D"=
color:#000"> </span><span style=3D"color:#660">[</span><span style=3D"color=
:#000">p</span><span style=3D"color:#660">,</span><span style=3D"color:#000=
"> q</span><span style=3D"color:#660">]</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </sp=
an></code><code><span style=3D"color:#000"><code><span style=3D"color:#000"=
></span><span style=3D"color:#008">reinterpret_cast</span><span style=3D"co=
lor:#660"><</span><span style=3D"color:#606">Tp</span><span style=3D"col=
or:#660">(&)[</span><span style=3D"color:#066">2</span><span style=3D"c=
olor:#660">]>(</span><span style=3D"color:#000">z</span><span style=3D"c=
olor:#660">)</span></code></span><span style=3D"color:#660">;</span><span s=
tyle=3D"color:#000"><br></span></code></div></blockquote><div><br>This is c=
ertainly legal now.=C2=A0 That's how I implement this.=C2=A0 It's j=
ust fugly and obscure for users.<br><br></div><blockquote class=3D"gmail_qu=
ote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padd=
ing-left: 1ex;"><div bgcolor=3D"#FFFFFF" text=3D"#000000"><code><span style=
=3D"color:#000">
</span></code><br>
Nevertheles I agree with you that your proposal makes this cleaner
and more explicit. Complex should be a ProductType.<br>
<blockquote type=3D"cite">
<div dir=3D"ltr"><br>
The rvalue and lvalue decomposition of std::complex can be
accomplished with a simple pure-library extension:<br>
Provide a tuple interface to std::complex.<br>
<br>
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(18=
7,187,187);border-style:solid;border-width:1px"><code>
<div><span style=3D"color:#000">=C2=A0 </span><span style=3D"co=
lor:#800">// Tuple interface to
class template complex.</span><span style=3D"color:#000"><b=
r>
</span><span style=3D"color:#800">#define</span><span style=
=3D"color:#000">
__cxx_lib_tuple_complex </span><span style=3D"color:#066">2=
01705</span><span style=3D"color:#000"><br>
<br>
=C2=A0 </span><span style=3D"color:#800">// Declare tuple_s=
ize.</span><span style=3D"color:#000"><br>
=C2=A0 </span><span style=3D"color:#008">template</span><sp=
an style=3D"color:#660"><</span><span style=3D"color:#008">typename</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#606">RealTp</spa=
n><span style=3D"color:#660">></span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#008">class</span=
><span style=3D"color:#000">
tuple_size</span><span style=3D"color:#660">;</span><span s=
tyle=3D"color:#000"><br>
<br>
=C2=A0 </span><span style=3D"color:#800">// Partial special=
ization for
std::complex.</span><span style=3D"color:#000"><br>
=C2=A0 </span><span style=3D"color:#008">template</span><sp=
an style=3D"color:#660"><</span><span style=3D"color:#008">typename</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#606">RealTp</spa=
n><span style=3D"color:#660">></span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#008">struct</spa=
n><span style=3D"color:#000">
tuple_size</span><span style=3D"color:#660"><</span><spa=
n style=3D"color:#000">std</span><span style=3D"color:#660">::</span><span =
style=3D"color:#000">complex</span><span style=3D"color:#660"><</span><s=
pan style=3D"color:#606">RealTp</span><span style=3D"color:#660"><wbr>>&=
gt;</span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#660">:</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#008">public</span><sp=
an style=3D"color:#000">
integral_constant</span><span style=3D"color:#660"><</sp=
an><span style=3D"color:#000">std</span><span style=3D"color:#660">::</span=
><span style=3D"color:#000">size_t</span><span style=3D"color:#660">,</span=
><span style=3D"color:#000"> </span><span style=3D"color:#066">2</span><spa=
n style=3D"color:#660">></span><span style=3D"color:#000"> </span><span =
style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">};</span><span style=3D"color:#000"><br>
<br>
=C2=A0 </span><span style=3D"color:#800">// Declare tuple_e=
lement.</span><span style=3D"color:#000"><br>
=C2=A0 </span><span style=3D"color:#008">template</span><sp=
an style=3D"color:#660"><</span><span style=3D"color:#000">std</span><sp=
an style=3D"color:#660">::</span><span style=3D"color:#000">size_t
_Int</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">typename</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#606">RealTp</span><span sty=
le=3D"color:#660">></span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#008">class</span=
><span style=3D"color:#000">
tuple_element</span><span style=3D"color:#660">;</span><spa=
n style=3D"color:#000"><br>
<br>
=C2=A0 </span><span style=3D"color:#800">// Partial special=
ization for
std::complex.</span><span style=3D"color:#000"><br>
=C2=A0 </span><span style=3D"color:#008">template</span><sp=
an style=3D"color:#660"><</span><span style=3D"color:#000">std</span><sp=
an style=3D"color:#660">::</span><span style=3D"color:#000">size_t
_Int</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">typename</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#606">RealTp</span><span sty=
le=3D"color:#660">></span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#008">struct</spa=
n><span style=3D"color:#000">
tuple_element</span><span style=3D"color:#660"><</span><=
span style=3D"color:#000">_Int</span><span style=3D"color:#660">,</span><sp=
an style=3D"color:#000"> std</span><span style=3D"color:#660">::</span><spa=
n style=3D"color:#000">complex</span><span style=3D"color:#660"><</span>=
<span style=3D"color:#606">RealTp</span><span style=3D"color:#660">>>=
</span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#660">{</span><sp=
an style=3D"color:#000"><br>
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">stat=
ic_assert</span><span style=3D"color:#660">(</span><span style=3D"color:#00=
0">_Int </span><span style=3D"color:#660"><</span><span style=3D"color:#=
000"> </span><span style=3D"color:#066">2</span><span style=3D"color:#660">=
,</span><span style=3D"color:#000"> </span><span style=3D"color:#080">"=
;index
is out of bounds"</span><span style=3D"color:#660">);<=
/span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">type=
def</span><span style=3D"color:#000"> </span><span style=3D"color:#606">Rea=
lTp</span><span style=3D"color:#000"> type</span><span style=3D"color:#660"=
>;</span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#660">};</span><s=
pan style=3D"color:#000"><br>
<br>
=C2=A0 </span><span style=3D"color:#800">// Decompose compl=
ex as
rvalues.</span><span style=3D"color:#000"><br>
=C2=A0 </span><span style=3D"color:#008">template</span><sp=
an style=3D"color:#660"><</span><span style=3D"color:#000">std</span><sp=
an style=3D"color:#660">::</span><span style=3D"color:#000">size_t
_Int</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">typename</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#606">RealTp</span><span sty=
le=3D"color:#660">></span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#008">constexpr</=
span><span style=3D"color:#000"> </span><span style=3D"color:#008">const</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#606">RealTp</s=
pan><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#008">get</span><=
span style=3D"color:#660">(</span><span style=3D"color:#008">const</span><s=
pan style=3D"color:#000"> std</span><span style=3D"color:#660">::</span><sp=
an style=3D"color:#000">complex</span><span style=3D"color:#660"><</span=
><span style=3D"color:#606">RealTp</span><span style=3D"color:#660">>&am=
p;</span><span style=3D"color:#000"> z</span><span style=3D"color:#660">)</=
span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#660">{</span><sp=
an style=3D"color:#000"><br>
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">stat=
ic_assert</span><span style=3D"color:#660">(</span><span style=3D"color:#00=
0">_Int </span><span style=3D"color:#660"><</span><span style=3D"color:#=
000"> </span><span style=3D"color:#066">2</span><span style=3D"color:#660">=
,</span><span style=3D"color:#000"> </span><span style=3D"color:#080">"=
;index
is out of bounds"</span><span style=3D"color:#660">);<=
/span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">retu=
rn</span><span style=3D"color:#000"> _Int </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:#000"> </span><span style=3D"color:#660">?</s=
pan><span style=3D"color:#000"> z</span><span style=3D"color:#660">.</span>=
<span style=3D"color:#000">real</span><span style=3D"color:#660">()</span><=
span style=3D"color:#000"> </span><span style=3D"color:#660">:</span><span =
style=3D"color:#000"> z</span><span style=3D"color:#660">.</span><span styl=
e=3D"color:#000">imag</span><span style=3D"color:#660">();</span><span styl=
e=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><sp=
an style=3D"color:#000"><br>
<br>
=C2=A0 </span><span style=3D"color:#800">// Decompose compl=
ex as
lvalues.</span><span style=3D"color:#000"><br>
=C2=A0 </span><span style=3D"color:#008">template</span><sp=
an style=3D"color:#660"><</span><span style=3D"color:#000">std</span><sp=
an style=3D"color:#660">::</span><span style=3D"color:#000">size_t
_Int</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">typename</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#606">RealTp</span><span sty=
le=3D"color:#660">></span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#008">constexpr</=
span><span style=3D"color:#000"> </span><span style=3D"color:#606">RealTp</=
span><span style=3D"color:#660">&</span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#008">get</span><=
span style=3D"color:#660">(</span><span style=3D"color:#000">std</span><spa=
n style=3D"color:#660">::</span><span style=3D"color:#000">complex</span><s=
pan style=3D"color:#660"><</span><span style=3D"color:#606">RealTp</span=
><span style=3D"color:#660">>&</span><span style=3D"color:#000"> z</=
span><span style=3D"color:#660">)</span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#660">{</span><sp=
an style=3D"color:#000"><br>
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">stat=
ic_assert</span><span style=3D"color:#660">(</span><span style=3D"color:#00=
0">_Int </span><span style=3D"color:#660"><</span><span style=3D"color:#=
000"> </span><span style=3D"color:#066">2</span><span style=3D"color:#660">=
,</span><span style=3D"color:#000"> </span><span style=3D"color:#080">"=
;index
is out of bounds"</span><span style=3D"color:#660">);<=
/span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">auto=
</span><span style=3D"color:#000"> w </span><span style=3D"color:#660">=3D<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#008">reinter=
pret_cast</span><span style=3D"color:#660"><</span><span style=3D"color:=
#606">RealTp</span><span style=3D"color:#660">(&)[</span><span style=3D=
"color:#066">2</span><span style=3D"color:#660">]><wbr>(</span><span sty=
le=3D"color:#000">z</span><span style=3D"color:#660">);</span><span style=
=3D"color:#000"><br>
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">retu=
rn</span><span style=3D"color:#000"> _Int </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:#000"> </span><span style=3D"color:#660">?</s=
pan><span style=3D"color:#000"> w</span><span style=3D"color:#660">[</span>=
<span style=3D"color:#066">0</span><span style=3D"color:#660">]</span><span=
style=3D"color:#000"> </span><span style=3D"color:#660">:</span><span styl=
e=3D"color:#000"> w</span><span style=3D"color:#660">[</span><span style=3D=
"color:#066">1</span><span style=3D"color:#660">];</span><span style=3D"col=
or:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><sp=
an style=3D"color:#000"><br>
<br>
</span></div>
</code></div>
<br>
</div>
</blockquote>
I believed that this reinterpret_cast was UB, but as you note below,
it is defined by the standard.<br>
<br>
<blockquote type=3D"cite">
<div dir=3D"ltr"><br>
Then we have the following behavior:<br>
<br>
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(18=
7,187,187);border-style:solid;border-width:1px"><code>
<div><span style=3D"color:#008">template</span><span style=3D"c=
olor:#660"><</span><span style=3D"color:#008">typename</span><span style=
=3D"color:#000"> </span><span style=3D"color:#606">Tp</span><span style=3D"=
color:#660">></span><span style=3D"color:#000"><br>
=C2=A0 </span><span style=3D"color:#008">void</span><span s=
tyle=3D"color:#000"><br>
=C2=A0 test_complex_decomp</span><span style=3D"color:#660"=
>()</span><span style=3D"color:#000"><br>
=C2=A0 </span><span style=3D"color:#660">{</span><span styl=
e=3D"color:#000"><br>
=C2=A0 =C2=A0 std</span><span style=3D"color:#660">::</span=
><span style=3D"color:#000">complex</span><span style=3D"color:#660"><</=
span><span style=3D"color:#606">Tp</span><span style=3D"color:#660">></s=
pan><span style=3D"color:#000"> z</span><span style=3D"color:#660">(</span>=
<span style=3D"color:#066">1</span><span style=3D"color:#660">,</span><span=
style=3D"color:#000"> </span><span style=3D"color:#066">2</span><span styl=
e=3D"color:#660">);</span><span style=3D"color:#000"><br>
<br>
=C2=A0 =C2=A0 </span><span style=3D"color:#008">auto</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#660">[</span><span=
style=3D"color:#000">x</span><span style=3D"color:#660">,</span><span styl=
e=3D"color:#000"> y</span><span style=3D"color:#660">]</span><span style=3D=
"color:#000"> </span><span style=3D"color:#660">=3D</span><span style=3D"co=
lor:#000"> z</span><span style=3D"color:#660">;</span><span style=3D"color:=
#000"><br>
=C2=A0 =C2=A0 std</span><span style=3D"color:#660">::</span=
><span style=3D"color:#000">cout </span><span style=3D"color:#660"><<=
</span><span style=3D"color:#000"> </span><span style=3D"color:#080">"=
z =3D "</span><span style=3D"color:#000"> </span><span style=3D"color:=
#660"><<</span><span style=3D"color:#000"> z </span><span style=3D"co=
lor:#660"><<</span><span style=3D"color:#000"> </span><span style=3D"=
color:#080">'\n'</span><span style=3D"color:#660">;</span><span sty=
le=3D"color:#000"><br>
=C2=A0 =C2=A0 std</span><span style=3D"color:#660">::</span=
><span style=3D"color:#000">cout </span><span style=3D"color:#660"><<=
</span><span style=3D"color:#000"> </span><span style=3D"color:#080">"=
z
parts:"</span><span style=3D"color:#000"> </span><span=
style=3D"color:#660"><<</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#080">' '</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#660"><<</span><span style=3D"color:#000"> x <=
/span><span style=3D"color:#660"><<</span><span style=3D"color:#000">=
</span><span style=3D"color:#080">' '</span><span style=3D"color:#=
000"> </span><span style=3D"color:#660"><<</span><span style=3D"color=
:#000"> y </span><span style=3D"color:#660"><<</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#080">'\n'</span><span styl=
e=3D"color:#660">;</span><span style=3D"color:#000"><br>
<br>
</span></div>
</code></div>
</div>
</blockquote>
<code>I'm not sure if you believe this implies a call to get to
decomponse as rvalues, but it isn't.<br>
It just copies the complex to a temporary, </code><code>and then
calls get on this temporary.<br></code></div></blockquote><div><br>Th=
e z, x, y part is lvalue decomp.<br>. <br></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"><code>
<br>
</code>
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(18=
7,187,187);border-style:solid;border-width:1px"><code>
<div><span style=3D"color:#000">=C2=A0 =C2=A0 z</span><span sty=
le=3D"color:#660">.</span><span style=3D"color:#000">real</span><span style=
=3D"color:#660">(</span><span style=3D"color:#066">3</span><span style=3D"c=
olor:#660">);</span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 z</span><span style=3D"color:#660">.</span><s=
pan style=3D"color:#000">imag</span><span style=3D"color:#660">(</span><spa=
n style=3D"color:#066">4</span><span style=3D"color:#660">);</span><span st=
yle=3D"color:#000"><br>
=C2=A0 =C2=A0 std</span><span style=3D"color:#660">::</span=
><span style=3D"color:#000">cout </span><span style=3D"color:#660"><<=
</span><span style=3D"color:#000"> </span><span style=3D"color:#080">"=
z =3D "</span><span style=3D"color:#000"> </span><span style=3D"color:=
#660"><<</span><span style=3D"color:#000"> z </span><span style=3D"co=
lor:#660"><<</span><span style=3D"color:#000"> </span><span style=3D"=
color:#080">'\n'</span><span style=3D"color:#660">;</span><span sty=
le=3D"color:#000"><br>
=C2=A0 =C2=A0 std</span><span style=3D"color:#660">::</span=
><span style=3D"color:#000">cout </span><span style=3D"color:#660"><<=
</span><span style=3D"color:#000"> </span><span style=3D"color:#080">"=
z
parts:"</span><span style=3D"color:#000"> </span><span=
style=3D"color:#660"><<</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#080">' '</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#660"><<</span><span style=3D"color:#000"> x <=
/span><span style=3D"color:#660"><<</span><span style=3D"color:#000">=
</span><span style=3D"color:#080">' '</span><span style=3D"color:#=
000"> </span><span style=3D"color:#660"><<</span><span style=3D"color=
:#000"> y </span><span style=3D"color:#660"><<</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#080">'\n'</span><span styl=
e=3D"color:#660">;</span><span style=3D"color:#000"><br>
<br>
=C2=A0 =C2=A0 std</span><span style=3D"color:#660">::</span=
><span style=3D"color:#000">complex</span><span style=3D"color:#660"><</=
span><span style=3D"color:#606">Tp</span><span style=3D"color:#660">></s=
pan><span style=3D"color:#000"> w</span><span style=3D"color:#660">(</span>=
<span style=3D"color:#066">1</span><span style=3D"color:#660">,</span><span=
style=3D"color:#000"> </span><span style=3D"color:#066">2</span><span styl=
e=3D"color:#660">);</span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 std</span><span style=3D"color:#660">::</span=
><span style=3D"color:#000">cout </span><span style=3D"color:#660"><<=
</span><span style=3D"color:#000"> </span><span style=3D"color:#080">"=
w =3D "</span><span style=3D"color:#000"> </span><span style=3D"color:=
#660"><<</span><span style=3D"color:#000"> w </span><span style=3D"co=
lor:#660"><<</span><span style=3D"color:#000"> </span><span style=3D"=
color:#080">'\n'</span><span style=3D"color:#660">;</span><span sty=
le=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#008">auto</span>=
<span style=3D"color:#660">&</span><span style=3D"color:#000"> </span><=
span style=3D"color:#660">[</span><span style=3D"color:#000">p</span><span =
style=3D"color:#660">,</span><span style=3D"color:#000"> q</span><span styl=
e=3D"color:#660">]</span><span style=3D"color:#000"> </span><span style=3D"=
color:#660">=3D</span><span style=3D"color:#000"> w</span><span style=3D"co=
lor:#660">;</span><span style=3D"color:#000"><br>
<br>
</span></div>
</code></div>
</div>
</blockquote>
<code>I'm not sure if you believe this implies a call to get to
decomponse as lvalues, but it isn't.<br>
</code><code>It just takes store a reference to the complex in a
temporary, and then calls get on this temporary reference.<br></code>=
</div></blockquote><div><br>The w, p, q part is rvalue decomp.<br>=C2=A0<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"><code>
</code>
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(18=
7,187,187);border-style:solid;border-width:1px"><code>
<div><span style=3D"color:#000"></span></div>
</code></div>
</div>
</blockquote>
<br>
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div style=3D"background-color:rgb(250,250,250);border-color:rgb(18=
7,187,187);border-style:solid;border-width:1px"><code>
<div><span style=3D"color:#000">=C2=A0 =C2=A0 w</span><span sty=
le=3D"color:#660">.</span><span style=3D"color:#000">real</span><span style=
=3D"color:#660">(</span><span style=3D"color:#066">3</span><span style=3D"c=
olor:#660">);</span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 w</span><span style=3D"color:#660">.</span><s=
pan style=3D"color:#000">imag</span><span style=3D"color:#660">(</span><spa=
n style=3D"color:#066">4</span><span style=3D"color:#660">);</span><span st=
yle=3D"color:#000"><br>
=C2=A0 =C2=A0 std</span><span style=3D"color:#660">::</span=
><span style=3D"color:#000">cout </span><span style=3D"color:#660"><<=
</span><span style=3D"color:#000"> </span><span style=3D"color:#080">"=
w =3D "</span><span style=3D"color:#000"> </span><span style=3D"color:=
#660"><<</span><span style=3D"color:#000"> w </span><span style=3D"co=
lor:#660"><<</span><span style=3D"color:#000"> </span><span style=3D"=
color:#080">'\n'</span><span style=3D"color:#660">;</span><span sty=
le=3D"color:#000"><br>
=C2=A0 =C2=A0 std</span><span style=3D"color:#660">::</span=
><span style=3D"color:#000">cout </span><span style=3D"color:#660"><<=
</span><span style=3D"color:#000"> </span><span style=3D"color:#080">"=
w
parts:"</span><span style=3D"color:#000"> </span><span=
style=3D"color:#660"><<</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#080">' '</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#660"><<</span><span style=3D"color:#000"> p <=
/span><span style=3D"color:#660"><<</span><span style=3D"color:#000">=
</span><span style=3D"color:#080">' '</span><span style=3D"color:#=
000"> </span><span style=3D"color:#660"><<</span><span style=3D"color=
:#000"> q </span><span style=3D"color:#660"><<</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#080">'\n'</span><span styl=
e=3D"color:#660">;</span><span style=3D"color:#000"><br>
<br>
=C2=A0 =C2=A0 p </span><span style=3D"color:#660">=3D</span=
><span style=3D"color:#000"> </span><span style=3D"color:#660">-</span><spa=
n style=3D"color:#066">5</span><span style=3D"color:#660">;</span><span sty=
le=3D"color:#000"><br>
=C2=A0 =C2=A0 q </span><span style=3D"color:#660">=3D</span=
><span style=3D"color:#000"> </span><span style=3D"color:#660">-</span><spa=
n style=3D"color:#066">6</span><span style=3D"color:#660">;</span><span sty=
le=3D"color:#000"><br>
=C2=A0 =C2=A0 std</span><span style=3D"color:#660">::</span=
><span style=3D"color:#000">cout </span><span style=3D"color:#660"><<=
</span><span style=3D"color:#000"> </span><span style=3D"color:#080">"=
w =3D "</span><span style=3D"color:#000"> </span><span style=3D"color:=
#660"><<</span><span style=3D"color:#000"> w </span><span style=3D"co=
lor:#660"><<</span><span style=3D"color:#000"> </span><span style=3D"=
color:#080">'\n'</span><span style=3D"color:#660">;</span><span sty=
le=3D"color:#000"><br>
=C2=A0 =C2=A0 std</span><span style=3D"color:#660">::</span=
><span style=3D"color:#000">cout </span><span style=3D"color:#660"><<=
</span><span style=3D"color:#000"> </span><span style=3D"color:#080">"=
w
parts:"</span><span style=3D"color:#000"> </span><span=
style=3D"color:#660"><<</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#080">' '</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#660"><<</span><span style=3D"color:#000"> p <=
/span><span style=3D"color:#660"><<</span><span style=3D"color:#000">=
</span><span style=3D"color:#080">' '</span><span style=3D"color:#=
000"> </span><span style=3D"color:#660"><<</span><span style=3D"color=
:#000"> q </span><span style=3D"color:#660"><<</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#080">'\n'</span><span styl=
e=3D"color:#660">;</span><span style=3D"color:#000"><br>
<br>
=C2=A0 =C2=A0 </span><span style=3D"color:#008">return</spa=
n><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>
=C2=A0 </span><span style=3D"color:#660">}</span><span styl=
e=3D"color:#000"><br>
<br>
</span><span style=3D"color:#008">int</span><span style=3D"co=
lor:#000"><br>
main</span><span style=3D"color:#660">()</span><span style=
=3D"color:#000"><br>
</span><span style=3D"color:#660">{</span><span style=3D"colo=
r:#000"><br>
=C2=A0 test_complex_decomp</span><span style=3D"color:#080"=
><double></span><span style=3D"color:#660">();</span><span style=3D"c=
olor:#000"><br>
=C2=A0 </span><span style=3D"color:#008">return</span><span=
style=3D"color:#000"> </span><span style=3D"color:#066">0</span><span styl=
e=3D"color:#660">;</span><span style=3D"color:#000"><br>
</span><span style=3D"color:#660">}</span><span style=3D"colo=
r:#000"><br>
<br>
</span></div>
</code></div>
<br>
<br>
-------------------<br>
z =3D (1,2)<br>
z parts: 1 2<br>
z =3D (3,4)<br>
z parts: 1 2<br>
w =3D (1,2)<br>
w =3D (3,4)<br>
w parts: 3 4<br>
w =3D (-5,-6)<br>
w parts: -5 -6<br>
-------------------<br>
<br>
The static cast, ugly as it is, is required to be valid by
conforming implementations of complex.<br>
</div>
</blockquote>
Are you talking of the reinterpret_cast?<br></div></blockquote><div><br=
>Yes, reinterpret_cast. sorry.<br>=C2=A0<br></div><blockquote class=3D"gmai=
l_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">29.5 Complex numbers [complex.numbers] p4,
specifically 4.1-4.3.<br>
This solution elegantly isolates user code from this wart.</div>
</blockquote>
I believe that you need const/non const lvalue/rvalue decomposition,
but maybe I'm wrong.<br>
<br>
<code><span style=3D"color:#000">=C2=A0 </span><span style=3D"color:#00=
8">template</span><span style=3D"color:#660"><</span><span style=3D"colo=
r:#000">std</span><span style=3D"color:#660">::</span><span style=3D"color:=
#000">size_t _Int</span><span style=3D"color:#660">,</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#008">typename</span><span style=3D=
"color:#000"> </span><span style=3D"color:#606">RealTp</span><span style=3D=
"color:#660">></span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#008">constexpr</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#008">const</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#606">RealTp</span><spa=
n style=3D"color:#000">&&<br>
=C2=A0 =C2=A0 </span><span style=3D"color:#008">get</span><span sty=
le=3D"color:#660">(const </span><span style=3D"color:#000">std</span><span =
style=3D"color:#660">::</span><span style=3D"color:#000">complex</span><spa=
n style=3D"color:#660"><</span><span style=3D"color:#606">RealTp</span><=
span style=3D"color:#660">>&</span><span style=3D"color:#000">& =
z</span><span style=3D"color:#660">)</span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"><br>
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">static_asser=
t</span><span style=3D"color:#660">(</span><span style=3D"color:#000">_Int =
</span><span style=3D"color:#660"><</span><span style=3D"color:#000"> </=
span><span style=3D"color:#066">2</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#080">"index i=
s out of
bounds"</span><span style=3D"color:#660">);</span><span style=
=3D"color:#000"><br>
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">return</span=
><span style=3D"color:#000"> _Int </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:#000"> </span><span style=3D"color:#660">?</span><spa=
n style=3D"color:#000"> z</span><span style=3D"color:#660">.</span><span st=
yle=3D"color:#000">real</span><span style=3D"color:#660">()</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#660">:</span><span style=3D=
"color:#000"> z</span><span style=3D"color:#660">.</span><span style=3D"col=
or:#000">imag</span><span style=3D"color:#660">();</span><span style=3D"col=
or:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><span style=
=3D"color:#000"><br>
<br></span></code></div></blockquote><div>Not sure about this one.=
=C2=A0 I think it just might not be useful. <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"><code><sp=
an style=3D"color:#000">
</span></code><br>
<code><span style=3D"color:#000"><code><span style=3D"color:#000">=C2=
=A0 </span><span style=3D"color:#008">template</span><span style=3D"color:#=
660"><</span><span style=3D"color:#000">std</span><span style=3D"color:#=
660">::</span><span style=3D"color:#000">size_t _Int</span><span style=3D"c=
olor:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:=
#008">typename</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#606">RealTp</span><span style=3D"color:#660">></span><span style=3D"c=
olor:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#008">constexpr</span=
><span style=3D"color:#000"> </span><span style=3D"color:#000"></span><span=
style=3D"color:#606">RealTp&&</span><span style=3D"color:#000"><br=
>
=C2=A0 =C2=A0 </span><span style=3D"color:#008">get</span><span=
style=3D"color:#660">(</span><span style=3D"color:#000">std</span><span st=
yle=3D"color:#660">::</span><span style=3D"color:#000">complex</span><span =
style=3D"color:#660"><</span><span style=3D"color:#606">RealTp</span><sp=
an style=3D"color:#660">>&</span><span style=3D"color:#000">& z<=
/span><span style=3D"color:#660">)</span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#660">{</span><span s=
tyle=3D"color:#000"><br>
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">static_a=
ssert</span><span style=3D"color:#660">(</span><span style=3D"color:#000">_=
Int </span><span style=3D"color:#660"><</span><span style=3D"color:#000"=
> </span><span style=3D"color:#066">2</span><span style=3D"color:#660">,</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#080">"ind=
ex is
out of bounds"</span><span style=3D"color:#660">);</span><=
span style=3D"color:#000"><br>
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">return</=
span><span style=3D"color:#000"> _Int </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:#000"> </span><span style=3D"color:#660">?</span>=
<span style=3D"color:#000"> z</span><span style=3D"color:#660">.</span><spa=
n style=3D"color:#000">real</span><span style=3D"color:#660">()</span><span=
style=3D"color:#000"> </span><span style=3D"color:#660">:</span><span styl=
e=3D"color:#000"> z</span><span style=3D"color:#660">.</span><span style=3D=
"color:#000">imag</span><span style=3D"color:#660">();</span><span style=3D=
"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><span s=
tyle=3D"color:#000"><br></span></code></span></code></div></blockquote><div=
><br>I think you're right here.=C2=A0 std::array has at least this one.=
<br>=C2=A0</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"><code><span style=3D"color:#000"><code><span =
style=3D"color:#000">
</span></code>=C2=A0 </span><span style=3D"color:#800">// Decompo=
se complex as lvalues.</span><span style=3D"color:#000"><br></span></code><=
/div></blockquote><div>=C2=A0<code><span style=3D"color:#000">=C2=A0 </span=
><span style=3D"color:#800">// Decompose complex as rvalues.</span><span st=
yle=3D"color:#000"><br></span></code></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"><code><span style=3D=
"color:#000">
=C2=A0 </span><span style=3D"color:#008">template</span><span style=
=3D"color:#660"><</span><span style=3D"color:#000">std</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">size_t _Int</span><span=
style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#008">typename</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#606">RealTp</span><span style=3D"color:#660">></span><span=
style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#008">constexpr</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#606">RealTp</span><sp=
an style=3D"color:#660">&</span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#008">get</span><span sty=
le=3D"color:#660">(</span><span style=3D"color:#000">std</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">complex</span><span sty=
le=3D"color:#660"><</span><span style=3D"color:#606">RealTp</span><span =
style=3D"color:#660">>&</span><span style=3D"color:#000"> z</span><s=
pan style=3D"color:#660">)</span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"><br>
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">static_asser=
t</span><span style=3D"color:#660">(</span><span style=3D"color:#000">_Int =
</span><span style=3D"color:#660"><</span><span style=3D"color:#000"> </=
span><span style=3D"color:#066">2</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#080">"index i=
s out of
bounds"</span><span style=3D"color:#660">);</span><span style=
=3D"color:#000"><br>
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">auto</span><=
span style=3D"color:#000"> w </span><span style=3D"color:#660">=3D</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#008">reinterpret_cas=
t</span><span style=3D"color:#660"><</span><span style=3D"color:#606">Re=
alTp</span><span style=3D"color:#660">(&)[</span><span style=3D"color:#=
066">2</span><span style=3D"color:#660">]><wbr>(</span><span style=3D"co=
lor:#000">z</span><span style=3D"color:#660">);</span><span style=3D"color:=
#000"><br>
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">return</span=
><span style=3D"color:#000"> _Int </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:#000"> </span><span style=3D"color:#660">?</span><spa=
n style=3D"color:#000"> w</span><span style=3D"color:#660">[</span><span st=
yle=3D"color:#066">0</span><span style=3D"color:#660">]</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">:</span><span style=3D"c=
olor:#000"> w</span><span style=3D"color:#660">[</span><span style=3D"color=
:#066">1</span><span style=3D"color:#660">];</span><span style=3D"color:#00=
0"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><span style=
=3D"color:#000"><br>
</span></code><br>
<code><span style=3D"color:#000">=C2=A0 </span><span style=3D"color:#80=
0">// Decompose complex as lvalues.</span><span style=3D"color:#000"><br>
=C2=A0 </span><span style=3D"color:#008">template</span><span style=
=3D"color:#660"><</span><span style=3D"color:#000">std</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">size_t _Int</span><span=
style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#008">typename</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#606">RealTp</span><span style=3D"color:#660">></span><span=
style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#008">constexpr</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#606">RealTp</span><sp=
an style=3D"color:#660"> const&</span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#008">get</span><span sty=
le=3D"color:#660">(const </span><span style=3D"color:#000">std</span><span =
style=3D"color:#660">::</span><span style=3D"color:#000">complex</span><spa=
n style=3D"color:#660"><</span><span style=3D"color:#606">RealTp</span><=
span style=3D"color:#660">>&</span><span style=3D"color:#000"> z</sp=
an><span style=3D"color:#660">)</span><span style=3D"color:#000"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"><br>
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">static_asser=
t</span><span style=3D"color:#660">(</span><span style=3D"color:#000">_Int =
</span><span style=3D"color:#660"><</span><span style=3D"color:#000"> </=
span><span style=3D"color:#066">2</span><span style=3D"color:#660">,</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#080">"index i=
s out of
bounds"</span><span style=3D"color:#660">);</span><span style=
=3D"color:#000"><br>
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">auto</span><=
span style=3D"color:#000"> w </span><span style=3D"color:#660">=3D</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#008">reinterpret_cas=
t</span><span style=3D"color:#660"><</span><span style=3D"color:#606">Re=
alTp</span><span style=3D"color:#660"> const(&)[</span><span style=3D"c=
olor:#066">2</span><span style=3D"color:#660">]>(</span><span style=3D"c=
olor:#000">z</span><span style=3D"color:#660">);</span><span style=3D"color=
:#000"><br>
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">return</span=
><span style=3D"color:#000"> _Int </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:#000"> </span><span style=3D"color:#660">?</span><spa=
n style=3D"color:#000"> w</span><span style=3D"color:#660">[</span><span st=
yle=3D"color:#066">0</span><span style=3D"color:#660">]</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">:</span><span style=3D"c=
olor:#000"> w</span><span style=3D"color:#660">[</span><span style=3D"color=
:#066">1</span><span style=3D"color:#660">];</span><span style=3D"color:#00=
0"><br>
=C2=A0 =C2=A0 </span><span style=3D"color:#660">}</span><span style=
=3D"color:#000"><br>
</span></code><br></div></blockquote><div>=C2=A0</div><div>Thank you =
for looking this over.<br>Ed<br><br>=C2=A0<br></div><blockquote class=3D"gm=
ail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc soli=
d;padding-left: 1ex;"><div bgcolor=3D"#FFFFFF" text=3D"#000000">
Vicente<br></div></blockquote><div>=C2=A0</div><div>=C2=A0</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/5fc8b8b9-c0f6-4620-b54a-62acde6cb7f0%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/5fc8b8b9-c0f6-4620-b54a-62acde6cb7f0=
%40isocpp.org</a>.<br />
------=_Part_1228_1846414457.1492200077635--
------=_Part_1227_1652640001.1492200077632--
.