Topic: Choosing constructor at runtime for non-copyable,


Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Wed, 17 Dec 2014 09:16:47 -0800 (PST)
Raw View
------=_Part_3534_385316339.1418836607753
Content-Type: multipart/alternative;
 boundary="----=_Part_3535_1348513868.1418836607753"

------=_Part_3535_1348513868.1418836607753
Content-Type: text/plain; charset=UTF-8

If you have a type with a deleted copy and move constructors, there doesn't
seem to be a way to choose which constructor to use to initialize an object
without using dynamic allocation.

struct Foo {
  Foo(int);
  Foo(string);
  Foo(const Foo&) = delete;
  Foo(Foo&&) = delete;
};

auto f = condition ? std::make_unique<Foo>(1) : std::make_unique<Foo>("abc"
); //Ok
auto f = condition ? Foo(1) : Foo("abc"); //Error: this requires a move or
copy constructor

Non-copyable/movable types come up in systems where we maintain external
pointers to objects. Particularly in callback or event based systems where
your queue holds pointers to the functors it will call. Moving your object
to a new memory address would invalidate pointers so we need a policy of
making them not-copyable/movable to prevent this kind of bug at compile
time.

While these kinds of objects are almost always dynamically allocated
sometimes they are not when they are placed directly as a data member of a
class or locally on the stack to be used for a short period of time.

Why is it that so called copy initialization requires a copy/move
constructor even though any compiler will elide the copy and just directly
initialize the object? Is there some corner cases where this rule is
actually necessary? If the rule could be removed, then we could use
the ternary operator to select constructors at runtime.



--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_3535_1348513868.1418836607753
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>If you have a type with a deleted copy and move const=
ructors, there doesn't seem to be a way to choose which constructor to use =
to initialize an object without using dynamic allocation.</div><div>&nbsp;<=
/div><div><div style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: br=
eak-word; background-color: rgb(250, 250, 250);" class=3D"prettyprint"><cod=
e class=3D"prettyprint"><div class=3D"subprettyprint"><font color=3D"#00008=
8"><span style=3D"color: rgb(0, 0, 136);" class=3D"styled-by-prettify">stru=
ct</span></font><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: rgb(102, 0, 102);" class=3D"styled-by-=
prettify">Foo</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by=
-prettify"> </span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled=
-by-prettify">{</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-=
by-prettify"><br>&nbsp; </span><span style=3D"color: rgb(102, 0, 102);" cla=
ss=3D"styled-by-prettify">Foo</span><span style=3D"color: rgb(102, 102, 0);=
" class=3D"styled-by-prettify">(</span><span style=3D"color: rgb(0, 0, 136)=
;" class=3D"styled-by-prettify">int</span><span style=3D"color: rgb(102, 10=
2, 0);" class=3D"styled-by-prettify">);</span><span style=3D"color: rgb(0, =
0, 0);" class=3D"styled-by-prettify"><br>&nbsp; </span><span style=3D"color=
: rgb(102, 0, 102);" class=3D"styled-by-prettify">Foo</span><span style=3D"=
color: rgb(102, 102, 0);" class=3D"styled-by-prettify">(</span><span style=
=3D"color: rgb(0, 0, 136);" class=3D"styled-by-prettify">string</span><span=
 style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettify">);</span><=
span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"><br>&nbsp;=
 </span><span style=3D"color: rgb(102, 0, 102);" class=3D"styled-by-prettif=
y">Foo</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-pr=
ettify">(</span><span style=3D"color: rgb(0, 0, 136);" class=3D"styled-by-p=
rettify">const</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: rgb(102, 0, 102);" class=3D"style=
d-by-prettify">Foo</span><span style=3D"color: rgb(102, 102, 0);" class=3D"=
styled-by-prettify">&amp;)</span><span style=3D"color: rgb(0, 0, 0);" class=
=3D"styled-by-prettify"> </span><span style=3D"color: rgb(102, 102, 0);" cl=
ass=3D"styled-by-prettify">=3D</span><span style=3D"color: rgb(0, 0, 0);" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: rgb(0, 0, 136);" =
class=3D"styled-by-prettify">delete</span><span style=3D"color: rgb(102, 10=
2, 0);" class=3D"styled-by-prettify">;</span><span style=3D"color: rgb(0, 0=
, 0);" class=3D"styled-by-prettify"><br>&nbsp; </span><span style=3D"color:=
 rgb(102, 0, 102);" class=3D"styled-by-prettify">Foo</span><span style=3D"c=
olor: rgb(102, 102, 0);" class=3D"styled-by-prettify">(</span><span style=
=3D"color: rgb(102, 0, 102);" class=3D"styled-by-prettify">Foo</span><span =
style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettify">&amp;&amp;)=
</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettify"=
>=3D</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify=
"> </span><span style=3D"color: rgb(0, 0, 136);" class=3D"styled-by-prettif=
y">delete</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by=
-prettify">;</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-=
prettify"><br></span><span style=3D"color: rgb(102, 102, 0);" class=3D"styl=
ed-by-prettify">};</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styl=
ed-by-prettify"><br><br></span><span style=3D"color: rgb(0, 0, 136);" class=
=3D"styled-by-prettify">auto</span><span style=3D"color: rgb(0, 0, 0);" cla=
ss=3D"styled-by-prettify"> f </span><span style=3D"color: rgb(102, 102, 0);=
" class=3D"styled-by-prettify">=3D</span><span style=3D"color: rgb(0, 0, 0)=
;" class=3D"styled-by-prettify"> condition </span><span style=3D"color: rgb=
(102, 102, 0);" class=3D"styled-by-prettify">?</span><span style=3D"color: =
rgb(0, 0, 0);" class=3D"styled-by-prettify"> std</span><span style=3D"color=
: rgb(102, 102, 0);" class=3D"styled-by-prettify">::</span><span style=3D"c=
olor: rgb(0, 0, 0);" class=3D"styled-by-prettify">make_unique</span><span s=
tyle=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettify">&lt;</span><=
span style=3D"color: rgb(102, 0, 102);" class=3D"styled-by-prettify">Foo</s=
pan><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettify">&=
gt;(</span><span style=3D"color: rgb(0, 102, 102);" class=3D"styled-by-pret=
tify">1</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-p=
rettify">)</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by=
-prettify">:</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-=
prettify"> std</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styl=
ed-by-prettify">::</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styl=
ed-by-prettify">make_unique</span><span style=3D"color: rgb(102, 102, 0);" =
class=3D"styled-by-prettify">&lt;</span><span style=3D"color: rgb(102, 0, 1=
02);" class=3D"styled-by-prettify">Foo</span><span style=3D"color: rgb(102,=
 102, 0);" class=3D"styled-by-prettify">&gt;(</span><span style=3D"color: r=
gb(0, 136, 0);" class=3D"styled-by-prettify">"abc"</span><span style=3D"col=
or: rgb(102, 102, 0);" class=3D"styled-by-prettify">);</span><span style=3D=
"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"> </span><span style=3D"=
color: rgb(136, 0, 0);" class=3D"styled-by-prettify">//Ok</span><span style=
=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"><br></span><span sty=
le=3D"color: rgb(0, 0, 136);" class=3D"styled-by-prettify">auto</span><span=
 style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"> f </span><spa=
n style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prettify">=3D</span=
><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-prettify"> conditi=
on </span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-by-prett=
ify">?</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: rgb(102, 0, 102);" class=3D"styled-by-pre=
ttify">Foo</span><span style=3D"color: rgb(102, 102, 0);" class=3D"styled-b=
y-prettify">(</span><span style=3D"color: rgb(0, 102, 102);" class=3D"style=
d-by-prettify">1</span><span style=3D"color: rgb(102, 102, 0);" class=3D"st=
yled-by-prettify">)</span><span style=3D"color: rgb(0, 0, 0);" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: rgb(102, 102, 0);" class=3D"=
styled-by-prettify">:</span><span style=3D"color: rgb(0, 0, 0);" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: rgb(102, 0, 102);" class=
=3D"styled-by-prettify">Foo</span><span style=3D"color: rgb(102, 102, 0);" =
class=3D"styled-by-prettify">(</span><span style=3D"color: rgb(0, 136, 0);"=
 class=3D"styled-by-prettify">"abc"</span><span style=3D"color: rgb(102, 10=
2, 0);" class=3D"styled-by-prettify">);</span><span style=3D"color: rgb(0, =
0, 0);" class=3D"styled-by-prettify"> </span><span style=3D"color: rgb(136,=
 0, 0);" class=3D"styled-by-prettify">//Error: this requires a move or copy=
 constructor</span><span style=3D"color: rgb(0, 0, 0);" class=3D"styled-by-=
prettify"><br></span></div></code></div><br>Non-copyable/movable types come=
 up in systems where we maintain external pointers to objects. Particularly=
 in callback or event based systems where your queue holds pointers to the =
functors it will call. Moving your object to a new memory address would inv=
alidate pointers so we need a policy of making them not-copyable/movable to=
 prevent this kind&nbsp;of&nbsp;bug at compile time.</div><div>&nbsp;</div>=
<div>While these kinds&nbsp;of objects are almost always dynamically alloca=
ted sometimes they are not when they are placed directly as a data member o=
f a class or locally on the stack to be used for a short period of time.</d=
iv><div>&nbsp;</div><div>Why is it that so called copy initialization requi=
res a copy/move constructor even though any compiler will elide the copy an=
d just directly initialize the object? Is there some corner cases where thi=
s rule is actually necessary? If the rule could be removed, then we could u=
se the&nbsp;ternary operator to select constructors at runtime.</div><p>&nb=
sp;</p></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_3535_1348513868.1418836607753--
------=_Part_3534_385316339.1418836607753--

.


Author: Matthew Woehlke <mw_triad@users.sourceforge.net>
Date: Wed, 17 Dec 2014 12:28:47 -0500
Raw View
On 2014-12-17 12:16, Matthew Fioravante wrote:
> struct Foo {
>   Foo(int);
>   Foo(string);
>   Foo(const Foo&) = delete;
>   Foo(Foo&&) = delete;
> };
>
> auto f = condition ? std::make_unique<Foo>(1) : std::make_unique<Foo>("abc"
> ); //Ok
> auto f = condition ? Foo(1) : Foo("abc"); //Error: this requires a move or
> copy constructor

auto&& f = (argc > 1) ? Foo(1) : Foo("abc"); // Okay

ISTR muttering noises recently about making copy/move elision mandatory
in cases like this, which would eliminate the need for the rvalue reference.

--
Matthew

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: Andy Prowl <andy.prowl@gmail.com>
Date: Tue, 23 Dec 2014 14:14:17 -0800 (PST)
Raw View
------=_Part_3193_258389755.1419372857723
Content-Type: multipart/alternative;
 boundary="----=_Part_3194_544678051.1419372857723"

------=_Part_3194_544678051.1419372857723
Content-Type: text/plain; charset=UTF-8

On Wednesday, December 17, 2014 6:29:05 PM UTC+1, Matthew Woehlke wrote:
>
>
> ISTR muttering noises recently about making copy/move elision mandatory
> in cases like this, which would eliminate the need for the rvalue
> reference.
>
> --
> Matthew
>
>
The possibility of making copy/move elision mandatory was recently
suggested by Richard Smith in this thread
<https://groups.google.com/a/isocpp.org/d/topic/std-proposals/ITDME5hYiPw/discussion> as
a way to make AAA style more consistently applicable.

Kind regards,

Andy

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_3194_544678051.1419372857723
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Wednesday, December 17, 2014 6:29:05 PM UTC+1, Matthew =
Woehlke wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><br>ISTR mutteri=
ng noises recently about making copy/move elision mandatory
<br>in cases like this, which would eliminate the need for the rvalue refer=
ence.
<br>
<br>--=20
<br>Matthew
<br>
<br></blockquote><div><br>The possibility of making copy/move elision manda=
tory was recently suggested by Richard Smith in <a href=3D"https://groups.g=
oogle.com/a/isocpp.org/d/topic/std-proposals/ITDME5hYiPw/discussion">this t=
hread</a>&nbsp;as a way to make AAA style more consistently applicable.<br>=
<br>Kind regards,<br><br>Andy<br><br></div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_3194_544678051.1419372857723--
------=_Part_3193_258389755.1419372857723--

.


Author: Myriachan <myriachan@gmail.com>
Date: Tue, 6 Jan 2015 18:22:19 -0800 (PST)
Raw View
------=_Part_211_1297616486.1420597339895
Content-Type: multipart/alternative;
 boundary="----=_Part_212_1343844917.1420597339895"

------=_Part_212_1343844917.1420597339895
Content-Type: text/plain; charset=UTF-8

On Tuesday, December 23, 2014 2:14:17 PM UTC-8, Andy Prowl wrote:
>
> On Wednesday, December 17, 2014 6:29:05 PM UTC+1, Matthew Woehlke wrote:
>>
>>
>> ISTR muttering noises recently about making copy/move elision mandatory
>> in cases like this, which would eliminate the need for the rvalue
>> reference.
>>
>> --
>> Matthew
>>
>>
>
There's always the hackity hack hack way, too:

alignas(Foo) unsigned char fooBuffer[sizeof(Foo)];
Foo &f = *(condition ? new(fooBuffer) Foo(1) : new(fooBuffer) Foo("abc"));

Melissa

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_212_1343844917.1420597339895
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Tuesday, December 23, 2014 2:14:17 PM UTC-8, Andy Prowl=
 wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.=
8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">On Wed=
nesday, December 17, 2014 6:29:05 PM UTC+1, Matthew Woehlke wrote:<blockquo=
te class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><br>ISTR muttering noises recently about mak=
ing copy/move elision mandatory
<br>in cases like this, which would eliminate the need for the rvalue refer=
ence.
<br>
<br>--=20
<br>Matthew
<br>
<br></blockquote><div><br></div></div></blockquote><div><br>There's always =
the hackity hack hack way, too:<br><br><div class=3D"prettyprint" style=3D"=
background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); bor=
der-style: solid; border-width: 1px; word-wrap: break-word;"><code class=3D=
"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">alignas</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">Foo</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: #008;" class=3D"styled-by-prettify">unsigned</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">char</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> fooBuffer</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">[</span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">sizeof</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #606;" cla=
ss=3D"styled-by-prettify">Foo</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">)];</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br></span><span style=3D"color: #606;" class=3D"styled-by-pret=
tify">Foo</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">f </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: #000;"=
 class=3D"styled-by-prettify">condition </span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">?</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">new</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">(</span><code class=3D"prettyprint"><span style=3D"color: #000;" class=
=3D"styled-by-prettify">fooBuffer</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">) </span></code><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Foo</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">(</span><span style=3D"color: #066;" class=3D"styled-by-pr=
ettify">1</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: #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">new</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">(</span><code class=3D"prettyprint"><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">fooBuffer</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify"></span></code><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;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"s=
tyled-by-prettify">Foo</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">(</span><span style=3D"color: #080;" class=3D"styled-by-prettif=
y">"abc"</span><span style=3D"color: #660;" class=3D"styled-by-prettify">))=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></spa=
n></div></code></div><br>Melissa<br></div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_212_1343844917.1420597339895--
------=_Part_211_1297616486.1420597339895--

.


Author: Matthew Fioravante <fmatthew5876@gmail.com>
Date: Tue, 6 Jan 2015 18:24:01 -0800 (PST)
Raw View
------=_Part_2524_1392633539.1420597441891
Content-Type: multipart/alternative;
 boundary="----=_Part_2525_567621320.1420597441891"

------=_Part_2525_567621320.1420597441891
Content-Type: text/plain; charset=UTF-8



On Tuesday, January 6, 2015 9:22:20 PM UTC-5, Myriachan wrote:
>
>
> There's always the hackity hack hack way, too:
>
> alignas(Foo) unsigned char fooBuffer[sizeof(Foo)];
> Foo &f = *(condition ? new(fooBuffer) Foo(1) : new(fooBuffer) Foo("abc"));
>
>
That's a bit too hackity for me. The destructor isn't called automatically
when the scope exits.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_2525_567621320.1420597441891
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Tuesday, January 6, 2015 9:22:20 PM UTC-5, Myri=
achan wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><=
div><br>There's always the hackity hack hack way, too:<br><br><div style=3D=
"background-color:rgb(250,250,250);border-color:rgb(187,187,187);border-sty=
le:solid;border-width:1px;word-wrap:break-word"><code><div><span style=3D"c=
olor:#000">alignas</span><span style=3D"color:#660">(</span><span style=3D"=
color:#606">Foo</span><span style=3D"color:#660">)</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#008">unsigned</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#008">char</span><span style=3D"col=
or:#000"> fooBuffer</span><span style=3D"color:#660">[</span><span style=3D=
"color:#008">sizeof</span><span style=3D"color:#660">(</span><span style=3D=
"color:#606">Foo</span><span style=3D"color:#660">)];</span><span style=3D"=
color:#000"><br></span><span style=3D"color:#606">Foo</span><span style=3D"=
color:#000"> </span><span style=3D"color:#660">&amp;</span><span style=3D"c=
olor:#000">f </span><span style=3D"color:#660">=3D</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#660">*(</span><span style=3D"color:#=
000">condition </span><span style=3D"color:#660">?</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#008">new</span><span style=3D"color:=
#660">(</span><code><span style=3D"color:#000">fooBuffer</span><span style=
=3D"color:#660">) </span></code><span style=3D"color:#606">Foo</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"c=
olor:#660">:</span><span style=3D"color:#000"> </span><span style=3D"color:=
#008">new</span><span style=3D"color:#660">(</span><code><span style=3D"col=
or:#000">fooBuffer</span><span style=3D"color:#660"></span></code><span sty=
le=3D"color:#000"></span><span style=3D"color:#660">)</span><span style=3D"=
color:#000"> </span><span style=3D"color:#606">Foo</span><span style=3D"col=
or:#660">(</span><span style=3D"color:#080">"abc"</span><span style=3D"colo=
r:#660">));</span><span style=3D"color:#000"><br></span></div></code></div>=
<br></div></div></blockquote><div><br></div><div>That's a bit too hackity f=
or me. The destructor isn't called automatically when the scope exits.&nbsp=
;</div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_2525_567621320.1420597441891--
------=_Part_2524_1392633539.1420597441891--

.