Topic: Nested std::optional clarification


Author: Thiago Macieira <thiago@macieira.org>
Date: Wed, 15 Jan 2014 12:47:10 -0800
Raw View
Hello

After the discussion in QString and QVariant's nullness, I'd like a
clarification for std::optional containing another std::optional. Given

 std::optional<std::optional<int>> opt;

Can the outer optional be engaged and contain a disengaged inner value?

 using namespace std;
 optional<int> o1{};  // disengaged
 optional<int> o2{0}; // engaged

 optional<optional<int>> oo1{}; // definitely disengaged
 optional<optional<int>> oo2{o2}; // definitely engaged
 optional<optional<int>> oo3{o1}; // engaged?

 oo1 = nullopt; // disengaged
 oo3 = optional<int>(nullopt); // engaged?

 oo3 = optional<long>(nullopt); // engaged, disengaged or doesn't compile?

I'm asking because the QVariant behaviour is probably slightly different. A
QVariant containing a null QString (or any other type with a member isNull()
returning bool) is also null.

Following the same line of thought, what happens to optionals containing
pointers? I'm guessing that the choice of name "engaged" and "disengaged"
explicitly separate from the inner type's null or non-null.

 optional<char *> o1{nullptr};  // engaged to a null pointer?
 optional<char *> o2{nullopt}; // disengaged

QVariant doesn't treat pointers specially: a QVariant containing a null
pointer is not null, but you can make it null / disengage it.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

--

---
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: "Billy O'Neal" <billy.oneal@gmail.com>
Date: Wed, 15 Jan 2014 13:07:38 -0800
Raw View
--089e011608ae405afc04f008b507
Content-Type: text/plain; charset=UTF-8

> Can the outer optional be engaged and contain a disengaged inner value?

As proposed for C++14 (and cut from C++14), yes.

Billy O'Neal
https://github.com/BillyONeal/ <https://bitbucket.org/BillyONeal/>
http://stackoverflow.com/users/82320/billy-oneal


On Wed, Jan 15, 2014 at 12:47 PM, Thiago Macieira <thiago@macieira.org>wrote:

> Hello
>
> After the discussion in QString and QVariant's nullness, I'd like a
> clarification for std::optional containing another std::optional. Given
>
>         std::optional<std::optional<int>> opt;
>
> Can the outer optional be engaged and contain a disengaged inner value?
>
>         using namespace std;
>         optional<int> o1{};  // disengaged
>         optional<int> o2{0}; // engaged
>
>         optional<optional<int>> oo1{}; // definitely disengaged
>         optional<optional<int>> oo2{o2}; // definitely engaged
>         optional<optional<int>> oo3{o1}; // engaged?
>
>         oo1 = nullopt;  // disengaged
>         oo3 = optional<int>(nullopt);   // engaged?
>
>         oo3 = optional<long>(nullopt); // engaged, disengaged or doesn't
> compile?
>
> I'm asking because the QVariant behaviour is probably slightly different. A
> QVariant containing a null QString (or any other type with a member
> isNull()
> returning bool) is also null.
>
> Following the same line of thought, what happens to optionals containing
> pointers? I'm guessing that the choice of name "engaged" and "disengaged"
> explicitly separate from the inner type's null or non-null.
>
>         optional<char *> o1{nullptr};  // engaged to a null pointer?
>         optional<char *> o2{nullopt}; // disengaged
>
> QVariant doesn't treat pointers specially: a QVariant containing a null
> pointer is not null, but you can make it null / disengage it.
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>    Software Architect - Intel Open Source Technology Center
>       PGP/GPG: 0x6EF45358; fingerprint:
>       E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
>
> --
>
> ---
> 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/.
>

--

---
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/.

--089e011608ae405afc04f008b507
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><span style=3D"font-family:arial,sans-serif;font-size:13px=
">&gt; Can the outer optional be engaged and contain a disengaged inner val=
ue?</span><br><div><span style=3D"font-family:arial,sans-serif;font-size:13=
px"><br>

</span></div><div><span style=3D"font-family:arial,sans-serif;font-size:13p=
x">As proposed for C++14 (and cut from C++14), yes.</span></div></div><div =
class=3D"gmail_extra"><br clear=3D"all"><div><div dir=3D"ltr"><div>Billy O&=
#39;Neal</div>

<div><a href=3D"https://bitbucket.org/BillyONeal/" target=3D"_blank">https:=
//github.com/BillyONeal/</a></div><div><a href=3D"http://stackoverflow.com/=
users/82320/billy-oneal" target=3D"_blank">http://stackoverflow.com/users/8=
2320/billy-oneal</a></div>

</div></div>
<br><br><div class=3D"gmail_quote">On Wed, Jan 15, 2014 at 12:47 PM, Thiago=
 Macieira <span dir=3D"ltr">&lt;<a href=3D"mailto:thiago@macieira.org" targ=
et=3D"_blank">thiago@macieira.org</a>&gt;</span> wrote:<br><blockquote clas=
s=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;pad=
ding-left:1ex">

Hello<br>
<br>
After the discussion in QString and QVariant&#39;s nullness, I&#39;d like a=
<br>
clarification for std::optional containing another std::optional. Given<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 std::optional&lt;std::optional&lt;int&gt;&gt; o=
pt;<br>
<br>
Can the outer optional be engaged and contain a disengaged inner value?<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 using namespace std;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 optional&lt;int&gt; o1{}; =C2=A0// disengaged<b=
r>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 optional&lt;int&gt; o2{0}; // engaged<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 optional&lt;optional&lt;int&gt;&gt; oo1{}; // d=
efinitely disengaged<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 optional&lt;optional&lt;int&gt;&gt; oo2{o2}; //=
 definitely engaged<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 optional&lt;optional&lt;int&gt;&gt; oo3{o1}; //=
 engaged?<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 oo1 =3D nullopt; =C2=A0// disengaged<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 oo3 =3D optional&lt;int&gt;(nullopt); =C2=A0 //=
 engaged?<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 oo3 =3D optional&lt;long&gt;(nullopt); // engag=
ed, disengaged or doesn&#39;t compile?<br>
<br>
I&#39;m asking because the QVariant behaviour is probably slightly differen=
t. A<br>
QVariant containing a null QString (or any other type with a member isNull(=
)<br>
returning bool) is also null.<br>
<br>
Following the same line of thought, what happens to optionals containing<br=
>
pointers? I&#39;m guessing that the choice of name &quot;engaged&quot; and =
&quot;disengaged&quot;<br>
explicitly separate from the inner type&#39;s null or non-null.<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 optional&lt;char *&gt; o1{nullptr}; =C2=A0// en=
gaged to a null pointer?<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 optional&lt;char *&gt; o2{nullopt}; // disengag=
ed<br>
<br>
QVariant doesn&#39;t treat pointers specially: a QVariant containing a null=
<br>
pointer is not null, but you can make it null / disengage it.<br>
<span class=3D"HOEnZb"><font color=3D"#888888">--<br>
Thiago Macieira - thiago (AT) <a href=3D"http://macieira.info" target=3D"_b=
lank">macieira.info</a> - thiago (AT) <a href=3D"http://kde.org" target=3D"=
_blank">kde.org</a><br>
=C2=A0 =C2=A0Software Architect - Intel Open Source Technology Center<br>
=C2=A0 =C2=A0 =C2=A0 PGP/GPG: 0x6EF45358; fingerprint:<br>
=C2=A0 =C2=A0 =C2=A0 E067 918B B660 DBD1 105C =C2=A0966C 33F5 F005 6EF4 535=
8<br>
<br>
--<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%2Bunsubscribe@isocpp.org">std-propo=
sals+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/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</font></span></blockquote></div><br></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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 />

--089e011608ae405afc04f008b507--

.


Author: =?UTF-8?Q?Andrzej_Krzemie=C5=84ski?= <akrzemi1@gmail.com>
Date: Thu, 16 Jan 2014 01:11:54 -0800 (PST)
Raw View
------=_Part_153_27772335.1389863514662
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



W dniu =C5=9Broda, 15 stycznia 2014 21:47:10 UTC+1 u=C5=BCytkownik Thiago M=
acieira=20
napisa=C5=82:
>
> Hello=20
>
> After the discussion in QString and QVariant's nullness, I'd like a=20
> clarification for std::optional containing another std::optional. Given=
=20
>
>         std::optional<std::optional<int>> opt;=20
>
> Can the outer optional be engaged and contain a disengaged inner value?=
=20
>

Yes, the shortest way to do this would be:
  optional<optional<int>> opt {in_place}; // or
  optional<optional<int>> opt {in_place, nullopt};

Tag in_place means "create an engaged optional and initialize the contained=
=20
value (in our case optional<int>) with the following (possibly empty) list=
=20
of arguments".


>         using namespace std;=20
>         optional<int> o1{};  // disengaged=20
>         optional<int> o2{0}; // engaged=20
>
>         optional<optional<int>> oo1{}; // definitely disengaged=20
>         optional<optional<int>> oo2{o2}; // definitely engaged=20
>         optional<optional<int>> oo3{o1}; // engaged?=20
>

The third case: outer optional is engaged, the inner optional is=20
disengaged. But you involved a move construction, which was not necessary.
=20

>
>         oo1 =3D nullopt;        // disengaged=20
>         oo3 =3D optional<int>(nullopt);        // engaged?=20
>

Again, outer is engaged, the inner is disengaged. You can acheive the same=
=20
(but faster) with:

  oo3.emplace(); // or
  oo3.emplace(nullopt);
=20

>
>         oo3 =3D optional<long>(nullopt); // engaged, disengaged or doesn'=
t=20
> compile?=20
>

Will not compile: unlike boost::optional, std::optional does not allow=20
conversions between optional<T> and  optional<U>.=20


> I'm asking because the QVariant behaviour is probably slightly different.=
=20
> A=20
> QVariant containing a null QString (or any other type with a member=20
> isNull()=20
> returning bool) is also null.=20
>

std::optional is different here.
=20

>
> Following the same line of thought, what happens to optionals containing=
=20
> pointers? I'm guessing that the choice of name "engaged" and "disengaged"=
=20
> explicitly separate from the inner type's null or non-null.=20
>

Correct, and "nullopt" to separate from "nullptr".
=20

>
>         optional<char *> o1{nullptr};  // engaged to a null pointer?=20
>         optional<char *> o2{nullopt}; // disengaged=20
>

o1 is engaged. o2 is disengaged.
=20

>
> QVariant doesn't treat pointers specially: a QVariant containing a null=
=20
> pointer is not null, but you can make it null / disengage it.=20
>

Same with std::optional.=20

Regards,
&rzej

--=20

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

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

<div dir=3D"ltr"><br><br>W dniu =C5=9Broda, 15 stycznia 2014 21:47:10 UTC+1=
 u=C5=BCytkownik Thiago Macieira napisa=C5=82:<blockquote class=3D"gmail_qu=
ote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padd=
ing-left: 1ex;">Hello
<br>
<br>After the discussion in QString and QVariant's nullness, I'd like a=20
<br>clarification for std::optional containing another std::optional. Given
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::optional&lt;std::<=
wbr>optional&lt;int&gt;&gt; opt;
<br>
<br>Can the outer optional be engaged and contain a disengaged inner value?
<br></blockquote><div><br>Yes, the shortest way to do this would be:<br>&nb=
sp; optional&lt;optional&lt;int&gt;&gt; opt {in_place}; // or<br>&nbsp; opt=
ional&lt;optional&lt;int&gt;&gt; opt {in_place, nullopt};<br><br>Tag in_pla=
ce means "create an engaged optional and initialize the contained value (in=
 our case optional&lt;int&gt;) with the following (possibly empty) list of =
arguments".<br><br></div><blockquote class=3D"gmail_quote" style=3D"margin:=
 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;using namespace std;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;optional&lt;int&gt; o1{=
}; &nbsp;// disengaged
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;optional&lt;int&gt; o2{=
0}; // engaged
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;optional&lt;optional&lt=
;int&gt;<wbr>&gt; oo1{}; // definitely disengaged
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;optional&lt;optional&lt=
;int&gt;<wbr>&gt; oo2{o2}; // definitely engaged
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;optional&lt;optional&lt=
;int&gt;<wbr>&gt; oo3{o1}; // engaged?
<br></blockquote><div><br>The third case: outer optional is engaged, the in=
ner optional is disengaged. But you involved a move construction, which was=
 not necessary.<br>&nbsp;<br></div><blockquote class=3D"gmail_quote" style=
=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: =
1ex;">
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;oo1 =3D nullopt;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// disengaged
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;oo3 =3D optional&lt;int=
&gt;(nullopt);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<wbr>&nbsp;// engag=
ed?
<br></blockquote><div><br>Again, outer is engaged, the inner is disengaged.=
 You can acheive the same (but faster) with:<br><br>&nbsp; oo3.emplace(); /=
/ or<br>&nbsp; oo3.emplace(nullopt);<br>&nbsp;<br></div><blockquote class=
=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #cc=
c solid;padding-left: 1ex;">
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;oo3 =3D optional&lt;lon=
g&gt;(nullopt); // engaged, disengaged or doesn't compile?
<br></blockquote><div><br>Will not compile: unlike boost::optional, std::op=
tional does not allow conversions between optional&lt;T&gt; and&nbsp; optio=
nal&lt;U&gt;. <br><br></div><blockquote class=3D"gmail_quote" style=3D"marg=
in: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
<br>I'm asking because the QVariant behaviour is probably slightly differen=
t. A=20
<br>QVariant containing a null QString (or any other type with a member isN=
ull()=20
<br>returning bool) is also null.
<br></blockquote><div><br>std::optional is different here.<br>&nbsp;<br></d=
iv><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;=
border-left: 1px #ccc solid;padding-left: 1ex;">
<br>Following the same line of thought, what happens to optionals containin=
g=20
<br>pointers? I'm guessing that the choice of name "engaged" and "disengage=
d"=20
<br>explicitly separate from the inner type's null or non-null.
<br></blockquote><div><br>Correct, and "nullopt" to separate from "nullptr"=
..<br>&nbsp;<br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;optional&lt;char *&gt; =
o1{nullptr}; &nbsp;// engaged to a null pointer?
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;optional&lt;char *&gt; =
o2{nullopt}; // disengaged
<br></blockquote><div><br>o1 is engaged. o2 is disengaged.<br>&nbsp;<br></d=
iv><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;=
border-left: 1px #ccc solid;padding-left: 1ex;">
<br>QVariant doesn't treat pointers specially: a QVariant containing a null=
=20
<br>pointer is not null, but you can make it null / disengage it.
<br></blockquote><div><br>Same with std::optional. <br><br>Regards,<br>&amp=
;rzej<br></div></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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_153_27772335.1389863514662--

.


Author: Casey Carter <cartec69@gmail.com>
Date: Thu, 16 Jan 2014 14:24:14 -0800 (PST)
Raw View
------=_Part_2870_30212304.1389911054451
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Thursday, January 16, 2014 3:11:54 AM UTC-6, Andrzej Krzemie=C5=84ski wr=
ote:
>
> After the discussion in QString and QVariant's nullness, I'd like a=20
>> clarification for std::optional containing another std::optional. Given=
=20
>>
>>         std::optional<std::optional<int>> opt;=20
>>
>> Can the outer optional be engaged and contain a disengaged inner value?=
=20
>>
>
> Yes, the shortest way to do this would be:
>   optional<optional<int>> opt {in_place}; // or
>   optional<optional<int>> opt {in_place, nullopt};
>

My first thought was that {{}} would be the shortest initializer to=20
accomplish this. My implementation accepts it:

optional<optional<int>> opt{{}};
assert(!!opt);
assert(!*opt);

Did I screw something up?

--=20

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

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

<div dir=3D"ltr">On Thursday, January 16, 2014 3:11:54 AM UTC-6, Andrzej Kr=
zemie=C5=84ski wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr"><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.=
8ex;border-left:1px #ccc solid;padding-left:1ex">After the discussion in QS=
tring and QVariant's nullness, I'd like a=20
<br>clarification for std::optional containing another std::optional. Given
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::optional&lt;std::<=
wbr>optional&lt;int&gt;&gt; opt;
<br>
<br>Can the outer optional be engaged and contain a disengaged inner value?
<br></blockquote><div><br>Yes, the shortest way to do this would be:<br>&nb=
sp; optional&lt;optional&lt;int&gt;&gt; opt {in_place}; // or<br>&nbsp; opt=
ional&lt;optional&lt;int&gt;&gt; opt {in_place, nullopt};<br></div></div></=
blockquote><div><br></div><div>My first thought was that {{}} would be the =
shortest initializer to accomplish this. My implementation accepts it:</div=
><div><br></div><div><div class=3D"prettyprint" style=3D"background-color: =
rgb(250, 250, 250); border: 1px solid rgb(187, 187, 187); word-wrap: break-=
word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">optional</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">optional</span><span style=3D"colo=
r: #080;" class=3D"styled-by-prettify">&lt;int&gt;</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> opt</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">{{}};</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">assert</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">(!!</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">opt</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">assert</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">(!*</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">opt</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br></span></div></code></div><br></div>=
<div><span style=3D"font-size: 13px;">Did I screw something up?</span><br><=
/div></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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_2870_30212304.1389911054451--

.


Author: =?UTF-8?Q?Andrzej_Krzemie=C5=84ski?= <akrzemi1@gmail.com>
Date: Fri, 17 Jan 2014 00:16:49 -0800 (PST)
Raw View
------=_Part_4195_13504646.1389946609652
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



W dniu czwartek, 16 stycznia 2014 23:24:14 UTC+1 u=C5=BCytkownik Casey Cart=
er=20
napisa=C5=82:
>
> On Thursday, January 16, 2014 3:11:54 AM UTC-6, Andrzej Krzemie=C5=84ski =
wrote:
>>
>> After the discussion in QString and QVariant's nullness, I'd like a=20
>>> clarification for std::optional containing another std::optional. Given=
=20
>>>
>>>         std::optional<std::optional<int>> opt;=20
>>>
>>> Can the outer optional be engaged and contain a disengaged inner value?=
=20
>>>
>>
>> Yes, the shortest way to do this would be:
>>   optional<optional<int>> opt {in_place}; // or
>>   optional<optional<int>> opt {in_place, nullopt};
>>
>
> My first thought was that {{}} would be the shortest initializer to=20
> accomplish this. My implementation accepts it:
>
> optional<optional<int>> opt{{}};
> assert(!!opt);
> assert(!*opt);
>
> Did I screw something up?
>

Well, I am not quite sure it should work. Your notation is equivalent to=20
typing:
   optional<optional<int>> opt{ X{} };


Where X needs to be unambiguously deduced. Because nullopt_t does not have=
=20
a default constructor, there are two candidates for X: optional<int>&& and=
=20
in_place_t. This could result in ambiguity, because in_place_t is also=20
default-constructible, but I am not quite sure about the rules here.

Even if this works, I would not really recommend using it, as you create a=
=20
temporary, which needs to be later moved from when initializing a contained=
=20
value (I do not think copy elision can fix this). Instead, with tag=20
in_place you explicitly demand that the contained value is=20
value-initialized.

Regards,
&rzej

--=20

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

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

<div dir=3D"ltr"><br><br>W dniu czwartek, 16 stycznia 2014 23:24:14 UTC+1 u=
=C5=BCytkownik Casey Carter napisa=C5=82:<blockquote class=3D"gmail_quote" =
style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-l=
eft: 1ex;"><div dir=3D"ltr">On Thursday, January 16, 2014 3:11:54 AM UTC-6,=
 Andrzej Krzemie=C5=84ski wrote:<blockquote class=3D"gmail_quote" style=3D"=
margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><di=
v dir=3D"ltr"><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-le=
ft:0.8ex;border-left:1px #ccc solid;padding-left:1ex">After the discussion =
in QString and QVariant's nullness, I'd like a=20
<br>clarification for std::optional containing another std::optional. Given
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::optional&lt;std::<=
wbr>optional&lt;int&gt;&gt; opt;
<br>
<br>Can the outer optional be engaged and contain a disengaged inner value?
<br></blockquote><div><br>Yes, the shortest way to do this would be:<br>&nb=
sp; optional&lt;optional&lt;int&gt;&gt; opt {in_place}; // or<br>&nbsp; opt=
ional&lt;optional&lt;int&gt;&gt; opt {in_place, nullopt};<br></div></div></=
blockquote><div><br></div><div>My first thought was that {{}} would be the =
shortest initializer to accomplish this. My implementation accepts it:</div=
><div><br></div><div><div style=3D"background-color:rgb(250,250,250);border=
:1px solid rgb(187,187,187);word-wrap:break-word"><code><div><span style=3D=
"color:#000">optional</span><span style=3D"color:#660">&lt;</span><span sty=
le=3D"color:#000">optional</span><span style=3D"color:#080">&lt;int&gt;</sp=
an><span style=3D"color:#660">&gt;</span><span style=3D"color:#000"> opt</s=
pan><span style=3D"color:#660">{{}};</span><span style=3D"color:#000"><br><=
/span><span style=3D"color:#008">assert</span><span style=3D"color:#660">(!=
!</span><span style=3D"color:#000">opt</span><span style=3D"color:#660">);<=
/span><span style=3D"color:#000"><br></span><span style=3D"color:#008">asse=
rt</span><span style=3D"color:#660">(!*</span><span style=3D"color:#000">op=
t</span><span style=3D"color:#660">);</span><span style=3D"color:#000"><br>=
</span></div></code></div><br></div><div><span style=3D"font-size:13px">Did=
 I screw something up?</span><br></div></div></blockquote><div><br>Well, I =
am not quite sure it should work. Your notation is equivalent to typing:<br=
>&nbsp;&nbsp; <code><span style=3D"color:#000">optional</span><span style=
=3D"color:#660">&lt;</span><span style=3D"color:#000">optional</span><span =
style=3D"color:#080">&lt;int&gt;</span><span style=3D"color:#660">&gt;</spa=
n><span style=3D"color:#000"> opt</span><span style=3D"color:#660">{ X{} };=
<br></span></code><br><br>Where X needs to be unambiguously deduced. Becaus=
e nullopt_t does not have a default constructor, there are two candidates f=
or X: optional&lt;int&gt;&amp;&amp; and in_place_t. This could result in am=
biguity, because in_place_t is also default-constructible, but I am not qui=
te sure about the rules here.<br><br>Even if this works, I would not really=
 recommend using it, as you create a temporary, which needs to be later mov=
ed from when initializing a contained value (I do not think copy elision ca=
n fix this). Instead, with tag in_place you explicitly demand that the cont=
ained value is value-initialized.<br><br>Regards,<br>&amp;rzej<br></div></d=
iv>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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_4195_13504646.1389946609652--

.


Author: jgottman6@gmail.com
Date: Sat, 18 Jan 2014 12:20:22 -0800 (PST)
Raw View
------=_Part_238_32645018.1390076422655
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



On Friday, January 17, 2014 3:16:49 AM UTC-5, Andrzej Krzemie=C5=84ski wrot=
e:
>
>
>
> W dniu czwartek, 16 stycznia 2014 23:24:14 UTC+1 u=C5=BCytkownik Casey Ca=
rter=20
> napisa=C5=82:
>>
>> On Thursday, January 16, 2014 3:11:54 AM UTC-6, Andrzej Krzemie=C5=84ski=
 wrote:
>>>
>>>
>>>
>> My first thought was that {{}} would be the shortest initializer to=20
>> accomplish this. My implementation accepts it:
>>
>> optional<optional<int>> opt{{}};
>> assert(!!opt);
>> assert(!*opt);
>>
>> Did I screw something up?
>>
>
> Well, I am not quite sure it should work. Your notation is equivalent to=
=20
> typing:
>    optional<optional<int>> opt{ X{} };
>
>
> Where X needs to be unambiguously deduced. Because nullopt_t does not hav=
e=20
> a default constructor, there are two candidates for X: optional<int>&& an=
d=20
> in_place_t. This could result in ambiguity, because in_place_t is also=20
> default-constructible, but I am not quite sure about the rules here.
>
>
>     Since the constructor that takes in_place_t is explicit, it is not=20
considered in this context.  That's why nullopt_t had to be defined to not=
=20
be default-constructable and in_place_t did not.  Otherwise,=20
  =20
optional<int> foo =3D {};

  would also be ambiguous.

--=20

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

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

<div dir=3D"ltr"><br><br>On Friday, January 17, 2014 3:16:49 AM UTC-5, Andr=
zej Krzemie=C5=84ski wrote:<blockquote class=3D"gmail_quote" style=3D"margi=
n: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><di=
v dir=3D"ltr"><br><br>W dniu czwartek, 16 stycznia 2014 23:24:14 UTC+1 u=C5=
=BCytkownik Casey Carter napisa=C5=82:<blockquote class=3D"gmail_quote" sty=
le=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1e=
x"><div dir=3D"ltr">On Thursday, January 16, 2014 3:11:54 AM UTC-6, Andrzej=
 Krzemie=C5=84ski 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"><br></div></blockquote><div><br></div><div>My first thought was that =
{{}} would be the shortest initializer to accomplish this. My implementatio=
n accepts it:</div><div><br></div><div><div style=3D"background-color:rgb(2=
50,250,250);border:1px solid rgb(187,187,187);word-wrap:break-word"><code><=
div><span style=3D"color:#000">optional</span><span style=3D"color:#660">&l=
t;</span><span style=3D"color:#000">optional</span><span style=3D"color:#08=
0">&lt;int&gt;</span><span style=3D"color:#660">&gt;</span><span style=3D"c=
olor:#000"> opt</span><span style=3D"color:#660">{{}};</span><span style=3D=
"color:#000"><br></span><span style=3D"color:#008">assert</span><span style=
=3D"color:#660">(!!</span><span style=3D"color:#000">opt</span><span style=
=3D"color:#660">);</span><span style=3D"color:#000"><br></span><span style=
=3D"color:#008">assert</span><span style=3D"color:#660">(!*</span><span sty=
le=3D"color:#000">opt</span><span style=3D"color:#660">);</span><span style=
=3D"color:#000"><br></span></div></code></div><br></div><div><span style=3D=
"font-size:13px">Did I screw something up?</span><br></div></div></blockquo=
te><div><br>Well, I am not quite sure it should work. Your notation is equi=
valent to typing:<br>&nbsp;&nbsp; <code><span style=3D"color:#000">optional=
</span><span style=3D"color:#660">&lt;</span><span style=3D"color:#000">opt=
ional</span><span style=3D"color:#080">&lt;int&gt;</span><span style=3D"col=
or:#660">&gt;</span><span style=3D"color:#000"> opt</span><span style=3D"co=
lor:#660">{ X{} };<br></span></code><br><br>Where X needs to be unambiguous=
ly deduced. Because nullopt_t does not have a default constructor, there ar=
e two candidates for X: optional&lt;int&gt;&amp;&amp; and in_place_t. This =
could result in ambiguity, because in_place_t is also default-constructible=
, but I am not quite sure about the rules here.<br><br><br></div></div></bl=
ockquote><div>&nbsp; &nbsp; Since the constructor that takes in_place_t is =
explicit, it is not considered in this context.&nbsp; That's why nullopt_t =
had to be defined to not be default-constructable and in_place_t did not.&n=
bsp; Otherwise, <br>&nbsp; &nbsp;<div class=3D"prettyprint" style=3D"backgr=
ound-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-st=
yle: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"prett=
yprint"><div class=3D"subprettyprint"><span style=3D"color: #000;" class=3D=
"styled-by-prettify">optional</span><span style=3D"color: #080;" class=3D"s=
tyled-by-prettify">&lt;int&gt;</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> foo </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{=
};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></sp=
an></div></code></div><br> &nbsp; would also be ambiguous.<br></div></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<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_238_32645018.1390076422655--

.