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> <b>optional<string> os =3D "str";<b=
r> optional<unique_ptr<Base>> op =3D unique_ptr<Derive=
d>{};</b><br><br></div><div>and probably also this should work:<br><br><=
/div> <b>optional<unique_ptr<Base>> op =3D optional<un=
ique_ptr<Derived>>{};</b><br><br></div>At the same time the follow=
ing should not be allowed:<br><br></div> <b>optional<unique_ptr<=
;Base>> 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> template <class U><br></b></div><div><b> optiona=
l::optional(U&& u);<br><br></b></div><div><b> template <cl=
ass U><br></b></div><div><b> optional::optional(optional<U> =
const& ou);</b><br></div><div><br></div><div>Suppose you have the follo=
wing class:<br><br></div><div> <b> struct Port<br> {<br></b></di=
v><div><b> Port (optional<int> oi);<br> };&nb=
sp; <br></b></div><div><b><br></b></div><div><b> optional<int> =
oi;<br></b></div><b> optional<Port> 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>&rzej<br>=
</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 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"=
><<a href=3D"mailto:akrzemi1@gmail.com" target=3D"_blank">akrzemi1@gmail=
..com</a>></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>=C2=A0 template <class U><br></b></div><div><b>=C2=A0 optiona=
l::optional(U&& u);<br><br></b></div><div><b>=C2=A0 template <cl=
ass U><br>
</b></div><div><b>=C2=A0 optional::optional(optional<U> const& 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<int> oi);<br>
=C2=A0 };=C2=A0 <br></b></div><div><b><br></b></div><div><b>=C2=A0 optional=
<int> oi;<br></b></div><b>=C2=A0 optional<Port> 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=
.. Perhaps you could SFINAE it out in case the incoming<br>
</div><div>type is optional<U>? <br></div></div><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" 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"><<a href=
=3D"mailto:zy@miator.net" target=3D"_blank">zy@miator.net</a>></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 <=
;<a href=3D"mailto:akrzemi1@gmail.com">akrzemi1@gmail.com</a>> wrote:<br=
>
> Hi Everyone,<br>
> It was suggested by LEWG that the following converting constructor sho=
uld be<br>
> added to optional:<br>
><br>
> =A0 optional<string> os =3D "str";<br>
> =A0 optional<unique_ptr<Base>> op =3D unique_ptr<Derive=
d>{};<br>
><br>
> and probably also this should work:<br>
><br>
> =A0 optional<unique_ptr<Base>> op =3D optional<unique_p=
tr<Derived>>{};<br>
<br>
</div>I don't expect these to work. =A0Within the optional<br>
domain, we know T -> optional<T> 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 />
<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 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"><<a href=3D"java=
script:" target=3D"_blank" gdf-obfuscated-mailto=3D"cWZrB0ywbIUJ">akrz...@g=
mail.com</a>></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> template <class U><br></b></div><div><b> optiona=
l::optional(U&& u);<br><br></b></div><div><b> template <cl=
ass U><br>
</b></div><div><b> optional::optional(optional<U> const& ou=
);</b><br></div><div><br></div><div>Suppose you have the following class:<b=
r><br></div><div> <b> struct Port<br> {<br></b></div><div><b>&nb=
sp; Port (optional<int> oi);<br>
}; <br></b></div><div><b><br></b></div><div><b> optional=
<int> oi;<br></b></div><b> optional<Port> 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<U>? <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> struct Port<br> {<br></b><div><b> Po=
rt (optional<int> oi);<br> Port (int);<br>
}; <br></b></div><br>And now the code that uses it:<br><br><b> =
optional<int> oi;<br></b><b> optional<Port> 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 />
<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 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"=
><<a href=3D"mailto:akrzemi1@gmail.com" target=3D"_blank">akrzemi1@gmail=
..com</a>></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<int> 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<int> oi;<br></b><b>=C2=A0 optional<Por=
t> 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<=
;int>, since optional doesn't automatically convert to an int. If yo=
u<br></div><div>have<br></div><div>int i;<br>optional<Port> op =3D i;=
<br>
</div><div>then I expect Port(int) to be used.<br></div></div><br></div></d=
iv>
<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 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"><<a href=
=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"M5YxrHarD3MJ">a=
krz...@gmail.com</a>></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> struct Port<br> {<br></b><div><b> Por=
t (optional<int> oi);<br> Port (int);<br>
}; <br></b></div><br>And now the code that uses it:<div><br><br><b>&=
nbsp; optional<int> oi;<br></b><b> optional<Port> 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<=
;int>, since optional doesn't automatically convert to an int. If you<br=
></div><div>have<br></div><div>int i;<br>optional<Port> 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> template <class U> optional<T>::optional( op=
tional<U> const& o );</b><br><br>does:<br><br><b> if (o) { =
*(*this) =3D *o; }</b><br><br>in which case <b>Port(int)</b> would be used.=
<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" 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>></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"><<a>akrz...@gmail.com</a>></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<=
int> 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<int> oi;<br></b><b>=A0 optional<Port> 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<=
;int>, since optional doesn't automatically convert to an int. If yo=
u<br></div><div>have<br></div><div>int i;<br>optional<Port> 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 <class U> optional<T>::opt=
ional( optional<U> const& 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 />
<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 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--
.