Topic: Choosing constructor at runtime for
Author: Farid Mehrabi <farid.mehrabi@gmail.com>
Date: Sun, 11 Jan 2015 21:06:28 +0330
Raw View
--001a11c383e4979550050c63d545
Content-Type: text/plain; charset=UTF-8
there appears to be the flexible solution of 'std::optional<T>' too. the
hack solution can also be wrapped in a carefully designed template.
regards,
FM.
2015-01-07 5:54 GMT+03:30 Matthew Fioravante <fmatthew5876@gmail.com>:
>
>
> 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/.
--
how am I supposed to end the twisted road of your hair in the dark night??
unless the candle of your face does turn a lamp up on my way!!!
--
---
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/.
--001a11c383e4979550050c63d545
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"rtl"><div dir=3D"ltr">there appears to be the flexible solution=
of 'std::optional<T>' too. the hack solution can also be wra=
pped in a carefully designed template.</div><div dir=3D"ltr"><br></div><div=
dir=3D"ltr">regards,</div><div dir=3D"ltr">FM.</div></div><div class=3D"gm=
ail_extra"><div dir=3D"ltr"><br><div class=3D"gmail_quote">2015-01-07 5:54 =
GMT+03:30 Matthew Fioravante <span dir=3D"ltr"><<a href=3D"mailto:fmatth=
ew5876@gmail.com" target=3D"_blank">fmatthew5876@gmail.com</a>></span>:<=
br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left=
:1px #ccc solid;padding-left:1ex"><span class=3D""><br><br>On Tuesday, Janu=
ary 6, 2015 9:22:20 PM UTC-5, Myriachan wrote:<blockquote class=3D"gmail_qu=
ote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding=
-left:1ex"><div dir=3D"ltr"><div><br>There's always the hackity hack ha=
ck way, too:<br><br><div style=3D"background-color:rgb(250,250,250);border-=
color:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:break-=
word"><code><div><span style=3D"color:#000">alignas</span><span style=3D"co=
lor:#660">(</span><span style=3D"color:#606">Foo</span><span style=3D"color=
:#660">)</span><span style=3D"color:#000"> </span><span style=3D"color:#008=
">unsigned</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
08">char</span><span style=3D"color:#000"> fooBuffer</span><span style=3D"c=
olor:#660">[</span><span style=3D"color:#008">sizeof</span><span style=3D"c=
olor:#660">(</span><span style=3D"color:#606">Foo</span><span style=3D"colo=
r:#660">)];</span><span style=3D"color:#000"><br></span><span style=3D"colo=
r:#606">Foo</span><span style=3D"color:#000"> </span><span style=3D"color:#=
660">&</span><span style=3D"color:#000">f </span><span style=3D"color:#=
660">=3D</span><span style=3D"color:#000"> </span><span style=3D"color:#660=
">*(</span><span style=3D"color:#000">condition </span><span style=3D"color=
:#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"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"colo=
r:#000"> </span><span style=3D"color:#660">:</span><span style=3D"color:#00=
0"> </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"col=
or:#660"></span></code><span style=3D"color:#000"></span><span style=3D"col=
or:#660">)</span><span style=3D"color:#000"> </span><span style=3D"color:#6=
06">Foo</span><span style=3D"color:#660">(</span><span style=3D"color:#080"=
>"abc"</span><span style=3D"color:#660">));</span><span style=3D"=
color:#000"><br></span></div></code></div><br></div></div></blockquote><div=
><br></div></span><div>That's a bit too hackity for me. The destructor =
isn't called automatically when the scope exits.=C2=A0</div></blockquot=
e></div><div class=3D"HOEnZb"><div class=3D"h5">
<p></p>
-- <br>
<br>
--- <br>
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></div><br clear=3D"all"><div><br></div>-- <br><div class=3D"gma=
il_signature"><div dir=3D"ltr">how am I supposed to end the twisted road of=
=C2=A0 your hair in the dark night??<br>unless the candle of your face does=
turn a lamp up on my way!!!<br></div></div>
</div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--001a11c383e4979550050c63d545--
.