Topic: More converting constructors for Optional


Author: =?UTF-8?Q?Andrzej_Krzemie=C5=84ski?= <akrzemi1@gmail.com>
Date: Sat, 5 Oct 2013 10:14:05 -0700 (PDT)
Raw View
------=_Part_217_24093347.1380993245420
Content-Type: text/plain; charset=ISO-8859-1

Hi Everyone,
It was suggested by LEWG that the following converting constructor should
be added to optional:

  *optional<string> os = "str";
  optional<unique_ptr<Base>> op = unique_ptr<Derived>{};*

and probably also this should work:

  *optional<unique_ptr<Base>> op = optional<unique_ptr<Derived>>{};*

At the same time the following should not be allowed:

  *optional<unique_ptr<Base>> or = new Base{};*

(because this would turn an explicit conversion into an implicit one). Such
"conditionally explicit" converting constructor is doable, but I run on
another problem. The additional constructors would look like:

*  template <class U>
*
*  optional::optional(U&& u);

*
*  template <class U>
*
*  optional::optional(optional<U> const& ou);*

Suppose you have the following class:

 * struct Port
  {
*
*    Port (optional<int> oi);
  };
*
*
*
*  optional<int> oi;
*
*  optional<Port> op = oi;*

which of the two constructors would the user expect to be called? I guess
the former, but he would be surprised. I do not know how to solve this
problem. Perhaps someone on the list does.

Regards,
&rzej

--

---
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_217_24093347.1380993245420
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div><div><div><div><div><div>Hi Everyone,<br>It was =
suggested by LEWG that the following converting constructor should be added=
 to optional:<br><br></div>&nbsp; <b>optional&lt;string&gt; os =3D "str";<b=
r>&nbsp; optional&lt;unique_ptr&lt;Base&gt;&gt; op =3D unique_ptr&lt;Derive=
d&gt;{};</b><br><br></div><div>and probably also this should work:<br><br><=
/div>&nbsp; <b>optional&lt;unique_ptr&lt;Base&gt;&gt; op =3D optional&lt;un=
ique_ptr&lt;Derived&gt;&gt;{};</b><br><br></div>At the same time the follow=
ing should not be allowed:<br><br></div>&nbsp; <b>optional&lt;unique_ptr&lt=
;Base&gt;&gt; or =3D new Base{};</b><br><br></div>(because
 this would turn an explicit conversion into an implicit one). Such=20
"conditionally explicit" converting constructor is doable, but I run on=20
another problem. The additional constructors would look like:<br><br></div>=
<div><b>&nbsp; template &lt;class U&gt;<br></b></div><div><b>&nbsp; optiona=
l::optional(U&amp;&amp; u);<br><br></b></div><div><b>&nbsp; template &lt;cl=
ass U&gt;<br></b></div><div><b>&nbsp; optional::optional(optional&lt;U&gt; =
const&amp; ou);</b><br></div><div><br></div><div>Suppose you have the follo=
wing class:<br><br></div><div>&nbsp;<b> struct Port<br>&nbsp; {<br></b></di=
v><div><b>&nbsp;&nbsp;&nbsp; Port (optional&lt;int&gt; oi);<br>&nbsp; };&nb=
sp; <br></b></div><div><b><br></b></div><div><b>&nbsp; optional&lt;int&gt; =
oi;<br></b></div><b>&nbsp; optional&lt;Port&gt; op =3D oi;</b><br><br></div=
>which
 of the two constructors would the user expect to be called? I guess the
 former, but he would be surprised. I do not know how to solve this=20
problem. Perhaps someone on the list does.<br><br>Regards,<br>&amp;rzej<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 />

------=_Part_217_24093347.1380993245420--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sat, 5 Oct 2013 20:33:01 +0300
Raw View
--001a11c379ec89752804e801cfef
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On 5 October 2013 20:14, Andrzej Krzemie=C5=84ski <akrzemi1@gmail.com> wrot=
e:

>
> (because this would turn an explicit conversion into an implicit one).
> Such "conditionally explicit" converting constructor is doable, but I run
> on another problem. The additional constructors would look like:
>
> *  template <class U>
> *
> *  optional::optional(U&& u);
>
> *
> *  template <class U>
> *
> *  optional::optional(optional<U> const& ou);*
>
> Suppose you have the following class:
>
>  * struct Port
>   {
> *
> *    Port (optional<int> oi);
>   };
> *
> *
> *
> *  optional<int> oi;
> *
> *  optional<Port> op =3D oi;*
>
> which of the two constructors would the user expect to be called? I guess
> the former, but he would be surprised. I do not know how to solve this
> problem. Perhaps someone on the list does.
>
>
Depends on the user. Advanced users will know that the universal-reference
ctor is a better
match since there's no const involved. Perhaps you could SFINAE it out in
case the incoming
type is optional<U>?

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

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

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><br><div class=3D"gmail=
_quote">On 5 October 2013 20:14, Andrzej Krzemie=C5=84ski <span dir=3D"ltr"=
>&lt;<a href=3D"mailto:akrzemi1@gmail.com" target=3D"_blank">akrzemi1@gmail=
..com</a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div><div><br></div>(b=
ecause
 this would turn an explicit conversion into an implicit one). Such=20
&quot;conditionally explicit&quot; converting constructor is doable, but I =
run on=20
another problem. The additional constructors would look like:<br><br></div>=
<div><b>=C2=A0 template &lt;class U&gt;<br></b></div><div><b>=C2=A0 optiona=
l::optional(U&amp;&amp; u);<br><br></b></div><div><b>=C2=A0 template &lt;cl=
ass U&gt;<br>
</b></div><div><b>=C2=A0 optional::optional(optional&lt;U&gt; const&amp; ou=
);</b><br></div><div><br></div><div>Suppose you have the following class:<b=
r><br></div><div>=C2=A0<b> struct Port<br>=C2=A0 {<br></b></div><div><b>=C2=
=A0=C2=A0=C2=A0 Port (optional&lt;int&gt; oi);<br>
=C2=A0 };=C2=A0 <br></b></div><div><b><br></b></div><div><b>=C2=A0 optional=
&lt;int&gt; oi;<br></b></div><b>=C2=A0 optional&lt;Port&gt; op =3D oi;</b><=
br><br></div>which
 of the two constructors would the user expect to be called? I guess the
 former, but he would be surprised. I do not know how to solve this=20
problem. Perhaps someone on the list does.<br><br></div></blockquote><div><=
br></div><div>Depends on the user. Advanced users will know that the univer=
sal-reference ctor is a better<br>match since there&#39;s no const involved=
.. Perhaps you could SFINAE it out in case the incoming<br>
</div><div>type is optional&lt;U&gt;? <br></div></div><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 />

--001a11c379ec89752804e801cfef--

.


Author: Zhihao Yuan <zy@miator.net>
Date: Sat, 5 Oct 2013 14:55:47 -0400
Raw View
On Sat, Oct 5, 2013 at 1:14 PM, Andrzej Krzemie=C5=84ski <akrzemi1@gmail.co=
m> wrote:
> Hi Everyone,
> It was suggested by LEWG that the following converting constructor should=
 be
> added to optional:
>
>   optional<string> os =3D "str";
>   optional<unique_ptr<Base>> op =3D unique_ptr<Derived>{};
>
> and probably also this should work:
>
>   optional<unique_ptr<Base>> op =3D optional<unique_ptr<Derived>>{};

I don't expect these to work.  Within the optional
domain, we know T -> optional<T> is safe; but
outside this domain, it does not seem to be a good
idea to judge which kind of conversion is safe with
optional instead of just take the decision of C++.

--=20
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://4bsd.biz/

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

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sat, 5 Oct 2013 21:57:50 +0300
Raw View
--001a11c227e8e0f9c204e802fed7
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On 5 October 2013 21:55, Zhihao Yuan <zy@miator.net> wrote:

> On Sat, Oct 5, 2013 at 1:14 PM, Andrzej Krzemie=C5=84ski <akrzemi1@gmail.=
com>
> wrote:
> > Hi Everyone,
> > It was suggested by LEWG that the following converting constructor
> should be
> > added to optional:
> >
> >   optional<string> os =3D "str";
> >   optional<unique_ptr<Base>> op =3D unique_ptr<Derived>{};
> >
> > and probably also this should work:
> >
> >   optional<unique_ptr<Base>> op =3D optional<unique_ptr<Derived>>{};
>
> I don't expect these to work.  Within the optional
> domain, we know T -> optional<T> is safe; but
> outside this domain, it does not seem to be a good
> idea to judge which kind of conversion is safe with
> optional instead of just take the decision of C++.
>
>
>
Well, the LEWG guidance to explore these conversions was clear.

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

--001a11c227e8e0f9c204e802fed7
Content-Type: text/html; charset=ISO-8859-2
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><br><div class=3D"gmail=
_quote">On 5 October 2013 21:55, Zhihao Yuan <span dir=3D"ltr">&lt;<a href=
=3D"mailto:zy@miator.net" target=3D"_blank">zy@miator.net</a>&gt;</span> wr=
ote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border=
-left:1px #ccc solid;padding-left:1ex">
<div class=3D"im">On Sat, Oct 5, 2013 at 1:14 PM, Andrzej Krzemie=F1ski &lt=
;<a href=3D"mailto:akrzemi1@gmail.com">akrzemi1@gmail.com</a>&gt; wrote:<br=
>
&gt; Hi Everyone,<br>
&gt; It was suggested by LEWG that the following converting constructor sho=
uld be<br>
&gt; added to optional:<br>
&gt;<br>
&gt; =A0 optional&lt;string&gt; os =3D &quot;str&quot;;<br>
&gt; =A0 optional&lt;unique_ptr&lt;Base&gt;&gt; op =3D unique_ptr&lt;Derive=
d&gt;{};<br>
&gt;<br>
&gt; and probably also this should work:<br>
&gt;<br>
&gt; =A0 optional&lt;unique_ptr&lt;Base&gt;&gt; op =3D optional&lt;unique_p=
tr&lt;Derived&gt;&gt;{};<br>
<br>
</div>I don&#39;t expect these to work. =A0Within the optional<br>
domain, we know T -&gt; optional&lt;T&gt; is safe; but<br>
outside this domain, it does not seem to be a good<br>
idea to judge which kind of conversion is safe with<br>
optional instead of just take the decision of C++.<br>
<span class=3D"HOEnZb"><font color=3D"#888888"><br><br></font></span></bloc=
kquote><div><br></div><div>Well, the LEWG guidance to explore these convers=
ions was clear. <br></div></div><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 />

--001a11c227e8e0f9c204e802fed7--

.


Author: Zhihao Yuan <zy@miator.net>
Date: Sat, 5 Oct 2013 15:04:03 -0400
Raw View
On Sat, Oct 5, 2013 at 2:57 PM, Ville Voutilainen
<ville.voutilainen@gmail.com> wrote:
> Well, the LEWG guidance to explore these conversions was clear.

 Add templated comparison operators?

    SF    WF    WA    SA
    4    9    6    0

Find a way to enable mixed-type assigments

    SF    WF    WA    SA
    7    6    6    1

Around 2:1.  Be careful about "driven by straw polls"
or "design by committee".

--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://4bsd.biz/

--

---
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: =?UTF-8?Q?Andrzej_Krzemie=C5=84ski?= <akrzemi1@gmail.com>
Date: Sat, 5 Oct 2013 12:05:42 -0700 (PDT)
Raw View
------=_Part_261_11738981.1380999942602
Content-Type: text/plain; charset=ISO-8859-2
Content-Transfer-Encoding: quoted-printable



W dniu sobota, 5 pa=BCdziernika 2013 19:33:01 UTC+2 u=BFytkownik Ville=20
Voutilainen napisa=B3:
>
>
> On 5 October 2013 20:14, Andrzej Krzemie=F1ski <akrz...@gmail.com<javascr=
ipt:>
> > wrote:
>
>>
>> (because this would turn an explicit conversion into an implicit one).=
=20
>> Such "conditionally explicit" converting constructor is doable, but I ru=
n=20
>> on another problem. The additional constructors would look like:
>>
>> *  template <class U>
>> *
>> *  optional::optional(U&& u);
>>
>> *
>> *  template <class U>
>> *
>> *  optional::optional(optional<U> const& ou);*
>>
>> Suppose you have the following class:
>>
>>  * struct Port
>>   {
>> *
>> *    Port (optional<int> oi);
>>   }; =20
>> *
>> *
>> *
>> *  optional<int> oi;
>> *
>> *  optional<Port> op =3D oi;*
>>
>> which of the two constructors would the user expect to be called? I gues=
s=20
>> the former, but he would be surprised. I do not know how to solve this=
=20
>> problem. Perhaps someone on the list does.
>>
>>
> Depends on the user. Advanced users will know that the universal-referenc=
e=20
> ctor is a better
> match since there's no const involved. Perhaps you could SFINAE it out in=
=20
> case the incoming
> type is optional<U>?=20
>

Oh, you spotted a different problem than I did. Mine was that (even if I=20
fixed yours) it is not clear how to handle a case where *T* has a=20
constructor taking another optional. Consider a more tricky type:

*  struct Port
  {
*
*    Port (optional<int> oi);
    Port (int);
  };=20
*

And now the code that uses it:

*  optional<int> oi;
**  optional<Port> op =3D oi;*

Now, forget how optional is or might be implemented. As a user, which=20
constructor of *Port *would you expect to be called?



--=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_261_11738981.1380999942602
Content-Type: text/html; charset=ISO-8859-2
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>W dniu sobota, 5 pa=BCdziernika 2013 19:33:01 UTC+=
2 u=BFytkownik Ville Voutilainen napisa=B3:<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><div class=3D"gmail_quote">On 5 Octo=
ber 2013 20:14, Andrzej Krzemie=F1ski <span dir=3D"ltr">&lt;<a href=3D"java=
script:" target=3D"_blank" gdf-obfuscated-mailto=3D"cWZrB0ywbIUJ">akrz...@g=
mail.com</a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div><div><br></div>(b=
ecause
 this would turn an explicit conversion into an implicit one). Such=20
"conditionally explicit" converting constructor is doable, but I run on=20
another problem. The additional constructors would look like:<br><br></div>=
<div><b>&nbsp; template &lt;class U&gt;<br></b></div><div><b>&nbsp; optiona=
l::optional(U&amp;&amp; u);<br><br></b></div><div><b>&nbsp; template &lt;cl=
ass U&gt;<br>
</b></div><div><b>&nbsp; optional::optional(optional&lt;U&gt; const&amp; ou=
);</b><br></div><div><br></div><div>Suppose you have the following class:<b=
r><br></div><div>&nbsp;<b> struct Port<br>&nbsp; {<br></b></div><div><b>&nb=
sp;&nbsp;&nbsp; Port (optional&lt;int&gt; oi);<br>
&nbsp; };&nbsp; <br></b></div><div><b><br></b></div><div><b>&nbsp; optional=
&lt;int&gt; oi;<br></b></div><b>&nbsp; optional&lt;Port&gt; op =3D oi;</b><=
br><br></div>which
 of the two constructors would the user expect to be called? I guess the
 former, but he would be surprised. I do not know how to solve this=20
problem. Perhaps someone on the list does.<br><br></div></blockquote><div><=
br></div><div>Depends on the user. Advanced users will know that the univer=
sal-reference ctor is a better<br>match since there's no const involved. Pe=
rhaps you could SFINAE it out in case the incoming<br>
</div><div>type is optional&lt;U&gt;? <br></div></div></div></div></blockqu=
ote><div><br>Oh, you spotted a different problem than I did. Mine was that =
(even if I fixed yours) it is not clear how to handle a case where <b>T</b>=
 has a constructor taking another optional. Consider a more tricky type:<br=
><br><b>&nbsp; struct Port<br>&nbsp; {<br></b><div><b>&nbsp;&nbsp;&nbsp; Po=
rt (optional&lt;int&gt; oi);<br>&nbsp;&nbsp;&nbsp; Port (int);<br>
&nbsp; }; <br></b></div><br>And now the code that uses it:<br><br><b>&nbsp;=
 optional&lt;int&gt; oi;<br></b><b>&nbsp; optional&lt;Port&gt; op =3D oi;</=
b><br><br>Now, forget how optional is or might be implemented. As a user, w=
hich constructor of <b>Port </b>would you expect to be called?<br><br><br><=
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_261_11738981.1380999942602--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sat, 5 Oct 2013 22:30:10 +0300
Raw View
--001a11c25b4881dde504e8037292
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On 5 October 2013 22:05, Andrzej Krzemie=C5=84ski <akrzemi1@gmail.com> wrot=
e:

>
> Oh, you spotted a different problem than I did. Mine was that (even if I
> fixed yours) it is not clear how to handle a case where *T* has a
> constructor taking another optional. Consider a more tricky type:
>
> *  struct Port
>   {
> *
> *    Port (optional<int> oi);
>     Port (int);
>   };
> *
>
> And now the code that uses it:
>
>
> *  optional<int> oi;
> **  optional<Port> op =3D oi;*
>
> Now, forget how optional is or might be implemented. As a user, which
> constructor of *Port *would you expect to be called?
>
>
The one taking optional<int>, since optional doesn't automatically convert
to an int. If you
have
int i;
optional<Port> op =3D i;
then I expect Port(int) to be used.

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

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

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><br><div class=3D"gmail=
_quote">On 5 October 2013 22:05, Andrzej Krzemie=C5=84ski <span dir=3D"ltr"=
>&lt;<a href=3D"mailto:akrzemi1@gmail.com" target=3D"_blank">akrzemi1@gmail=
..com</a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr"><br><div>Oh, you spotted a =
different problem than I did. Mine was that (even if I fixed yours) it is n=
ot clear how to handle a case where <b>T</b> has a constructor taking anoth=
er optional. Consider a more tricky type:<br>
<br><b>=C2=A0 struct Port<br>=C2=A0 {<br></b><div><b>=C2=A0=C2=A0=C2=A0 Por=
t (optional&lt;int&gt; oi);<br>=C2=A0=C2=A0=C2=A0 Port (int);<br>
=C2=A0 }; <br></b></div><br>And now the code that uses it:<div class=3D"im"=
><br><br><b>=C2=A0 optional&lt;int&gt; oi;<br></b><b>=C2=A0 optional&lt;Por=
t&gt; op =3D oi;</b><br><br></div>Now, forget how optional is or might be i=
mplemented. As a user, which constructor of <b>Port </b>would you expect to=
 be called?<br>
<br></div></div></blockquote><div><br></div><div>The one taking optional&lt=
;int&gt;, since optional doesn&#39;t automatically convert to an int. If yo=
u<br></div><div>have<br></div><div>int i;<br>optional&lt;Port&gt; op =3D i;=
<br>
</div><div>then I expect Port(int) to be used.<br></div></div><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 />

--001a11c25b4881dde504e8037292--

.


Author: =?UTF-8?Q?Andrzej_Krzemie=C5=84ski?= <akrzemi1@gmail.com>
Date: Sat, 5 Oct 2013 12:38:50 -0700 (PDT)
Raw View
------=_Part_1164_632210.1381001930658
Content-Type: text/plain; charset=ISO-8859-2
Content-Transfer-Encoding: quoted-printable



W dniu sobota, 5 pa=BCdziernika 2013 21:30:10 UTC+2 u=BFytkownik Ville=20
Voutilainen napisa=B3:
>
>
>
>
> On 5 October 2013 22:05, Andrzej Krzemie=F1ski <akrz...@gmail.com<javascr=
ipt:>
> > wrote:
>
>>
>> Oh, you spotted a different problem than I did. Mine was that (even if I=
=20
>> fixed yours) it is not clear how to handle a case where *T* has a=20
>> constructor taking another optional. Consider a more tricky type:
>>
>> *  struct Port
>>   {
>> *
>> *    Port (optional<int> oi);
>>     Port (int);
>>   };=20
>> *
>>
>> And now the code that uses it:
>>
>>
>> *  optional<int> oi;
>> **  optional<Port> op =3D oi;*
>>
>> Now, forget how optional is or might be implemented. As a user, which=20
>> constructor of *Port *would you expect to be called?
>>
>>
> The one taking optional<int>, since optional doesn't automatically conver=
t=20
> to an int. If you
> have
> int i;
> optional<Port> op =3D i;
> then I expect Port(int) to be used.
>

Another (valid) expectation would be that constructor:=20

*  template <class U> optional<T>::optional( optional<U> const& o );*

does:

*  if (o) { *(*this) =3D *o; }*

in which case *Port(int)* would be used.
=20

--=20

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

------=_Part_1164_632210.1381001930658
Content-Type: text/html; charset=ISO-8859-2
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>W dniu sobota, 5 pa=BCdziernika 2013 21:30:10 UTC+=
2 u=BFytkownik Ville Voutilainen napisa=B3:<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><br><br><div class=3D"gmail_quote">O=
n 5 October 2013 22:05, Andrzej Krzemie=F1ski <span dir=3D"ltr">&lt;<a href=
=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"M5YxrHarD3MJ">a=
krz...@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr"><br><div>Oh, you spotted a =
different problem than I did. Mine was that (even if I fixed yours) it is n=
ot clear how to handle a case where <b>T</b> has a constructor taking anoth=
er optional. Consider a more tricky type:<br>
<br><b>&nbsp; struct Port<br>&nbsp; {<br></b><div><b>&nbsp;&nbsp;&nbsp; Por=
t (optional&lt;int&gt; oi);<br>&nbsp;&nbsp;&nbsp; Port (int);<br>
&nbsp; }; <br></b></div><br>And now the code that uses it:<div><br><br><b>&=
nbsp; optional&lt;int&gt; oi;<br></b><b>&nbsp; optional&lt;Port&gt; op =3D =
oi;</b><br><br></div>Now, forget how optional is or might be implemented. A=
s a user, which constructor of <b>Port </b>would you expect to be called?<b=
r>
<br></div></div></blockquote><div><br></div><div>The one taking optional&lt=
;int&gt;, since optional doesn't automatically convert to an int. If you<br=
></div><div>have<br></div><div>int i;<br>optional&lt;Port&gt; op =3D i;<br>
</div><div>then I expect Port(int) to be used.<br></div></div></div></div><=
/blockquote><div><br>Another (valid) expectation would be that constructor:=
 <br><br><b>&nbsp; template &lt;class U&gt; optional&lt;T&gt;::optional( op=
tional&lt;U&gt; const&amp; o );</b><br><br>does:<br><br><b>&nbsp; if (o) { =
*(*this) =3D *o; }</b><br><br>in which case <b>Port(int)</b> would be used.=
<br>&nbsp;<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_1164_632210.1381001930658--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sat, 5 Oct 2013 23:39:12 +0300
Raw View
--f46d043d6557654f7d04e8046973
Content-Type: text/plain; charset=ISO-8859-2
Content-Transfer-Encoding: quoted-printable

On 5 October 2013 22:38, Andrzej Krzemie=F1ski <akrzemi1@gmail.com> wrote:

> On 5 October 2013 22:05, Andrzej Krzemie=F1ski <akrz...@gmail.com> wrote:
>
>>
>>> Oh, you spotted a different problem than I did. Mine was that (even if =
I
>>> fixed yours) it is not clear how to handle a case where *T* has a
>>> constructor taking another optional. Consider a more tricky type:
>>>
>>> *  struct Port
>>>   {
>>> *
>>> *    Port (optional<int> oi);
>>>     Port (int);
>>>   };
>>> *
>>>
>>> And now the code that uses it:
>>>
>>>
>>> *  optional<int> oi;
>>> **  optional<Port> op =3D oi;*
>>>
>>> Now, forget how optional is or might be implemented. As a user, which
>>> constructor of *Port *would you expect to be called?
>>>
>>>
>> The one taking optional<int>, since optional doesn't automatically
>> convert to an int. If you
>> have
>> int i;
>> optional<Port> op =3D i;
>> then I expect Port(int) to be used.
>>
>
> Another (valid) expectation would be that constructor:
>
> *  template <class U> optional<T>::optional( optional<U> const& o );*
>
> does:
>
> *  if (o) { *(*this) =3D *o; }*
>
> in which case *Port(int)* would be used.
>
>

Yes, good point, the optional part is indeed consumed by the converting
constructor
of optional itself.

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

--f46d043d6557654f7d04e8046973
Content-Type: text/html; charset=ISO-8859-2
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><br><div class=3D"gmail=
_quote">On 5 October 2013 22:38, Andrzej Krzemie=F1ski <span dir=3D"ltr">&l=
t;<a href=3D"mailto:akrzemi1@gmail.com" target=3D"_blank">akrzemi1@gmail.co=
m</a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div dir=3D"ltr">On 5 October 2013 22:05, An=
drzej Krzemie=F1ski <span dir=3D"ltr">&lt;<a>akrz...@gmail.com</a>&gt;</spa=
n> wrote:<br>

<div><div class=3D"h5"><blockquote class=3D"gmail_quote" style=3D"margin:0;=
margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"=
ltr"><div><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir=3D"ltr"><br><div>Oh, you spotted a different problem than I did. M=
ine was that (even if I fixed yours) it is not clear how to handle a case w=
here <b>T</b> has a constructor taking another optional. Consider a more tr=
icky type:<br>

<br><b>=A0 struct Port<br>=A0 {<br></b><div><b>=A0=A0=A0 Port (optional&lt;=
int&gt; oi);<br>=A0=A0=A0 Port (int);<br>
=A0 }; <br></b></div><br>And now the code that uses it:<div><br><br><b>=A0 =
optional&lt;int&gt; oi;<br></b><b>=A0 optional&lt;Port&gt; op =3D oi;</b><b=
r><br></div>Now, forget how optional is or might be implemented. As a user,=
 which constructor of <b>Port </b>would you expect to be called?<br>

<br></div></div></blockquote><div><br></div><div>The one taking optional&lt=
;int&gt;, since optional doesn&#39;t automatically convert to an int. If yo=
u<br></div><div>have<br></div><div>int i;<br>optional&lt;Port&gt; op =3D i;=
<br>

</div><div>then I expect Port(int) to be used.<br></div></div></div></div><=
/blockquote></div></div><div><br>Another (valid) expectation would be that =
constructor: <br><br><b>=A0 template &lt;class U&gt; optional&lt;T&gt;::opt=
ional( optional&lt;U&gt; const&amp; o );</b><br>
<br>does:<br><br><b>=A0 if (o) { *(*this) =3D *o; }</b><br><br>in which cas=
e <b>Port(int)</b> would be used.<br><br></div></div></blockquote><div><br>=
</div><div>=A0<br></div></div>Yes, good point, the optional part is indeed =
consumed by the converting constructor<br>
of optional itself.<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 />

--f46d043d6557654f7d04e8046973--

.