Topic: More converting constructors for Optional?


Author: =?UTF-8?Q?Andrzej_Krzemie=C5=84ski?= <akrzemi1@gmail.com>
Date: Fri, 20 Jun 2014 03:22:42 -0700 (PDT)
Raw View
------=_Part_266_30680707.1403259762356
Content-Type: text/plain; charset=UTF-8

Hi Everyone,
I am considering adding more converting constructors to
std::experimental::optional. The following lines currently do not work, but
they would with my addition:

optional<const int> oi = optional<int>(2); // const T != T
optional<unique_ptr<Base>> op = optional<unique_ptr<Derived>>();

There are similar and even more issues with mixed assignment and
comparison. However, there is one problem with this addition that I am not
sure how to solve elegantly. I need your advice here.
What should be the expected result in the following 2 cases:

// case 1
struct Tool
{
 Tool(optional<int>);
};

optional<int> oi = 1;
optional<Tool> ot = oi;

Error or call optional<T>(U const&) ?

// case 2
struct Tool
{
 Tool(int); // ctor 1
 Tool(optional<int>); // ctor 2
};

optional<int> oi = 1;
optional<Tool> ot = oi;
Error, or use ctor 1, or use ctor 2?

The most elegant solution I was able to find so far is this:

template <typename T>
class optional
{
  optional(T const&);
  optional(T &&);

  template <typename U>
  optional(optional<U> &&) requires !is_convertible<optional<U>, T>::value;

  template <typename U>
  optional(optional<U> const&) requires !is_convertible<optional<U>, T>::
value;
};

This makes case 1 work intuitively and makes case 2 a compiler error.
Any opinions are welcome.

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_266_30680707.1403259762356
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div><div><div><div>Hi Everyone,<br>I am considering =
adding more converting=20
constructors to std::experimental::optional. The following lines=20
currently do not work, but they would with my addition:<br><br></div><div c=
lass=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-=
color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wra=
p: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><=
span style=3D"color: #000;" class=3D"styled-by-prettify">optional</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">const</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">int</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> oi </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> optional</span><span style=3D"color: #080;" class=3D"styled-by-=
prettify">&lt;int&gt;</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">(</span><span style=3D"color: #066;" class=3D"styled-by-prettify=
">2</span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #800;" class=3D"styled-by-prettify">// const T !=3D T</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br>optional</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">unique_ptr</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span styl=
e=3D"color: #606;" class=3D"styled-by-prettify">Base</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">&gt;&gt;</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> op </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> optional</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify">unique_ptr</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">&lt;</span><span style=3D"color: #606;" class=3D"styled=
-by-prettify">Derived</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">&gt;&gt;();</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br></span></div></code></div><div style=3D"margin-left: 40px;"=
><br></div>There are similar and even more issues with mixed assignment and=
=20
comparison. However, there is one problem with this addition that I am=20
not sure how to solve elegantly. I need your advice here.<br>What should be=
 the expected result in the following 2 cases:</div><br></div><div class=3D=
"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-color: =
rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: brea=
k-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span st=
yle=3D"color: #800;" class=3D"styled-by-prettify">// case 1</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">struct</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;"=
 class=3D"styled-by-prettify">Tool</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br>&nbsp;</span><span style=3D"color: #606;" class=3D"styled-by-p=
rettify">Tool</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">option=
al</span><span style=3D"color: #080;" class=3D"styled-by-prettify">&lt;int&=
gt;</span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br><br>optional</span><span=
 style=3D"color: #080;" class=3D"styled-by-prettify">&lt;int&gt;</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> oi </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066=
;" class=3D"styled-by-prettify">1</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>optional</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">&lt;</span><span style=3D"color: #606;" class=3D"styled-by=
-prettify">Tool</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
ot </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> oi</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></code></di=
v></div></div><pre><code><code><span style=3D"font-family: arial,helvetica,=
sans-serif;">Error or call optional&lt;T&gt;(U const&amp;) ?</span></code><=
br><br></code></pre><div class=3D"prettyprint" style=3D"background-color: r=
gb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; b=
order-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div =
class=3D"subprettyprint"><span style=3D"color: #800;" class=3D"styled-by-pr=
ettify">// case 2</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>struct</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #606;" class=3D"styled-by-prettify">Tool</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br>&nbsp;</span><span style=3D"c=
olor: #606;" class=3D"styled-by-prettify">Tool</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">int</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-prettif=
y">// ctor 1</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br>&nbsp;</span><span style=3D"color: #606;" class=3D"styled-by-prettify=
">Tool</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">optional</spa=
n><span style=3D"color: #080;" class=3D"styled-by-prettify">&lt;int&gt;</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #800;" class=3D"styled-by-prettify">// ctor 2</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">};</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br><br>optional</span><span style=3D"color: #=
080;" class=3D"styled-by-prettify">&lt;int&gt;</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> oi </span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"style=
d-by-prettify">1</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>optional</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
lt;</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Tool</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> ot </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> oi</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br></span></div></code></div><div>Error, or use=
 ctor 1, or use ctor 2?<br><br></div><div>The most elegant solution I was a=
ble to find so far is this:<br><br></div><div class=3D"prettyprint" style=
=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187);=
 border-style: solid; border-width: 1px; word-wrap: break-word;"><code clas=
s=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;=
" class=3D"styled-by-prettify">template</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">typename</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r></span><span style=3D"color: #008;" class=3D"styled-by-prettify">class</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> optional<br>=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; optional=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">T </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">const</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">&amp;);</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br>&nbsp; optional</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">T </span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&amp;&amp;);</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br><br>&nbsp; </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">template</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> U</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br>&nbsp; optional</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">optional</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
">U</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">&amp;&amp;)</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> requires </span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">!</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">is_convertible</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=
=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">U</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&gt;,</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">&gt;::</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">value</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br><br>&nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">template</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;<=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">typename</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> U</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; optional</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><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">U</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">const</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">&amp;)</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> requires </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">!</span><span style=3D"color: #000;" class=3D"styled-by-prettify">i=
s_convertible</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">opt=
ional</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify">U</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&gt;,</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">&gt;::</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">value</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br></span></div></code></div><div><br>This makes case 1 work int=
uitively and makes case 2 a compiler error.<br>Any opinions are welcome.<br=
><br>Regards,<br>&amp;rzej<br></div><div><div>&nbsp;<br></div></div></div>

<p></p>

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

------=_Part_266_30680707.1403259762356--

.


Author: Roman Perepelitsa <roman.perepelitsa@gmail.com>
Date: Fri, 20 Jun 2014 13:20:47 +0200
Raw View
--047d7b3432369ab3df04fc42b0a1
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

2014-06-20 12:22 GMT+02:00 Andrzej Krzemie=C5=84ski <akrzemi1@gmail.com>:

> Hi Everyone,
> I am considering adding more converting constructors to
> std::experimental::optional. The following lines currently do not work, b=
ut
> they would with my addition:
>
> optional<const int> oi =3D optional<int>(2); // const T !=3D T
> optional<unique_ptr<Base>> op =3D optional<unique_ptr<Derived>>();
>
> There are similar and even more issues with mixed assignment and
> comparison. However, there is one problem with this addition that I am no=
t
> sure how to solve elegantly. I need your advice here.
> What should be the expected result in the following 2 cases:
>
> // case 1
> struct Tool
> {
>  Tool(optional<int>);
> };
>
> optional<int> oi =3D 1;
> optional<Tool> ot =3D oi;
>
> Error or call optional<T>(U const&) ?
>
> // case 2
> struct Tool
> {
>  Tool(int); // ctor 1
>  Tool(optional<int>); // ctor 2
> };
>
> optional<int> oi =3D 1;
> optional<Tool> ot =3D oi;
> Error, or use ctor 1, or use ctor 2?
>
> The most elegant solution I was able to find so far is this:
>
> template <typename T>
> class optional
> {
>   optional(T const&);
>   optional(T &&);
>
>   template <typename U>
>   optional(optional<U> &&) requires !is_convertible<optional<U>, T>::valu=
e
> ;
>
>   template <typename U>
>   optional(optional<U> const&) requires !is_convertible<optional<U>, T>::
> value;
> };
>
> This makes case 1 work intuitively and makes case 2 a compiler error.
> Any opinions are welcome.
>

I like it. I believe the 'requires' clause on the second overload should
read !is_convertible<*const optional<U>&*, T>::value.

What about the following example?
struct Tool
{
 *explicit* Tool(int);
};

optional<int> oi =3D 1;
optional<Tool> ot(oi);

Error or call optional<T>(optional<U>&&)?

Roman Perepelitsa.

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

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

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">2014=
-06-20 12:22 GMT+02:00 Andrzej Krzemie=C5=84ski <span dir=3D"ltr">&lt;<a hr=
ef=3D"mailto:akrzemi1@gmail.com" target=3D"_blank">akrzemi1@gmail.com</a>&g=
t;</span>:<br>

<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
adding-left:1ex"><div dir=3D"ltr"><div><div><div><div><div>Hi Everyone,<br>=
I am considering adding more converting=20
constructors to std::experimental::optional. The following lines=20
currently do not work, but they would with my addition:<br><br></div><div s=
tyle=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;background-c=
olor:rgb(250,250,250)"><code><div><span style=3D"color:rgb(0,0,0)">optional=
</span><span style=3D"color:rgb(102,102,0)">&lt;</span><span style=3D"color=
:rgb(0,0,136)">const</span><span style=3D"color:rgb(0,0,0)"> </span><span s=
tyle=3D"color:rgb(0,0,136)">int</span><span style=3D"color:rgb(102,102,0)">=
&gt;</span><span style=3D"color:rgb(0,0,0)"> oi </span><span style=3D"color=
:rgb(102,102,0)">=3D</span><span style=3D"color:rgb(0,0,0)"> optional</span=
><span style=3D"color:rgb(0,136,0)">&lt;int&gt;</span><span style=3D"color:=
rgb(102,102,0)">(</span><span style=3D"color:rgb(0,102,102)">2</span><span =
style=3D"color:rgb(102,102,0)">);</span><span style=3D"color:rgb(0,0,0)"> <=
/span><span style=3D"color:rgb(136,0,0)">// const T !=3D T</span><span styl=
e=3D"color:rgb(0,0,0)"><br>

optional</span><span style=3D"color:rgb(102,102,0)">&lt;</span><span style=
=3D"color:rgb(0,0,0)">unique_ptr</span><span style=3D"color:rgb(102,102,0)"=
>&lt;</span><span style=3D"color:rgb(102,0,102)">Base</span><span style=3D"=
color:rgb(102,102,0)">&gt;&gt;</span><span style=3D"color:rgb(0,0,0)"> op <=
/span><span style=3D"color:rgb(102,102,0)">=3D</span><span style=3D"color:r=
gb(0,0,0)"> optional</span><span style=3D"color:rgb(102,102,0)">&lt;</span>=
<span style=3D"color:rgb(0,0,0)">unique_ptr</span><span style=3D"color:rgb(=
102,102,0)">&lt;</span><span style=3D"color:rgb(102,0,102)">Derived</span><=
span style=3D"color:rgb(102,102,0)">&gt;&gt;();</span><span style=3D"color:=
rgb(0,0,0)"><br>

</span></div></code></div><div style=3D"margin-left:40px"><br></div>There a=
re similar and even more issues with mixed assignment and=20
comparison. However, there is one problem with this addition that I am=20
not sure how to solve elegantly. I need your advice here.<br>What should be=
 the expected result in the following 2 cases:</div><br></div><div style=3D=
"border:1px solid rgb(187,187,187);word-wrap:break-word;background-color:rg=
b(250,250,250)">

<code><div><span style=3D"color:rgb(136,0,0)">// case 1</span><span style=
=3D"color:rgb(0,0,0)"><br></span><span style=3D"color:rgb(0,0,136)">struct<=
/span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102=
,0,102)">Tool</span><span style=3D"color:rgb(0,0,0)"><br>

</span><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rg=
b(0,0,0)"><br>=C2=A0</span><span style=3D"color:rgb(102,0,102)">Tool</span>=
<span style=3D"color:rgb(102,102,0)">(</span><span style=3D"color:rgb(0,0,0=
)">optional</span><span style=3D"color:rgb(0,136,0)">&lt;int&gt;</span><spa=
n style=3D"color:rgb(102,102,0)">);</span><span style=3D"color:rgb(0,0,0)">=
<br>

</span><span style=3D"color:rgb(102,102,0)">};</span><span style=3D"color:r=
gb(0,0,0)"><br><br>optional</span><span style=3D"color:rgb(0,136,0)">&lt;in=
t&gt;</span><span style=3D"color:rgb(0,0,0)"> oi </span><span style=3D"colo=
r:rgb(102,102,0)">=3D</span><span style=3D"color:rgb(0,0,0)"> </span><span =
style=3D"color:rgb(0,102,102)">1</span><span style=3D"color:rgb(102,102,0)"=
>;</span><span style=3D"color:rgb(0,0,0)"><br>

optional</span><span style=3D"color:rgb(102,102,0)">&lt;</span><span style=
=3D"color:rgb(102,0,102)">Tool</span><span style=3D"color:rgb(102,102,0)">&=
gt;</span><span style=3D"color:rgb(0,0,0)"> ot </span><span style=3D"color:=
rgb(102,102,0)">=3D</span><span style=3D"color:rgb(0,0,0)"> oi</span><span =
style=3D"color:rgb(102,102,0)">;</span><span style=3D"color:rgb(0,0,0)"><br=
>

</span></div></code></div></div></div><pre><code><code><span style=3D"font-=
family:arial,helvetica,sans-serif">Error or call optional&lt;T&gt;(U const&=
amp;) ?</span></code><br><br></code></pre><div style=3D"border:1px solid rg=
b(187,187,187);word-wrap:break-word;background-color:rgb(250,250,250)">

<code><div><span style=3D"color:rgb(136,0,0)">// case 2</span><span style=
=3D"color:rgb(0,0,0)"><br></span><span style=3D"color:rgb(0,0,136)">struct<=
/span><span style=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102=
,0,102)">Tool</span><span style=3D"color:rgb(0,0,0)"><br>

</span><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rg=
b(0,0,0)"><br>=C2=A0</span><span style=3D"color:rgb(102,0,102)">Tool</span>=
<span style=3D"color:rgb(102,102,0)">(</span><span style=3D"color:rgb(0,0,1=
36)">int</span><span style=3D"color:rgb(102,102,0)">);</span><span style=3D=
"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(136,0,0)">// ctor 1</sp=
an><span style=3D"color:rgb(0,0,0)"><br>

=C2=A0</span><span style=3D"color:rgb(102,0,102)">Tool</span><span style=3D=
"color:rgb(102,102,0)">(</span><span style=3D"color:rgb(0,0,0)">optional</s=
pan><span style=3D"color:rgb(0,136,0)">&lt;int&gt;</span><span style=3D"col=
or:rgb(102,102,0)">);</span><span style=3D"color:rgb(0,0,0)"> </span><span =
style=3D"color:rgb(136,0,0)">// ctor 2</span><span style=3D"color:rgb(0,0,0=
)"><br>

</span><span style=3D"color:rgb(102,102,0)">};</span><span style=3D"color:r=
gb(0,0,0)"><br><br>optional</span><span style=3D"color:rgb(0,136,0)">&lt;in=
t&gt;</span><span style=3D"color:rgb(0,0,0)"> oi </span><span style=3D"colo=
r:rgb(102,102,0)">=3D</span><span style=3D"color:rgb(0,0,0)"> </span><span =
style=3D"color:rgb(0,102,102)">1</span><span style=3D"color:rgb(102,102,0)"=
>;</span><span style=3D"color:rgb(0,0,0)"><br>

optional</span><span style=3D"color:rgb(102,102,0)">&lt;</span><span style=
=3D"color:rgb(102,0,102)">Tool</span><span style=3D"color:rgb(102,102,0)">&=
gt;</span><span style=3D"color:rgb(0,0,0)"> ot </span><span style=3D"color:=
rgb(102,102,0)">=3D</span><span style=3D"color:rgb(0,0,0)"> oi</span><span =
style=3D"color:rgb(102,102,0)">;</span><span style=3D"color:rgb(0,0,0)"><br=
>

</span></div></code></div><div>Error, or use ctor 1, or use ctor 2?<br><br>=
</div><div>The most elegant solution I was able to find so far is this:<br>=
<br></div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-w=
ord;background-color:rgb(250,250,250)">

<code><div><span style=3D"color:rgb(0,0,136)">template</span><span style=3D=
"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">&lt;</span>=
<span style=3D"color:rgb(0,0,136)">typename</span><span style=3D"color:rgb(=
0,0,0)"> T</span><span style=3D"color:rgb(102,102,0)">&gt;</span><span styl=
e=3D"color:rgb(0,0,0)"><br>

</span><span style=3D"color:rgb(0,0,136)">class</span><span style=3D"color:=
rgb(0,0,0)"> optional<br></span><span style=3D"color:rgb(102,102,0)">{</spa=
n><span style=3D"color:rgb(0,0,0)"><br>=C2=A0 optional</span><span style=3D=
"color:rgb(102,102,0)">(</span><span style=3D"color:rgb(0,0,0)">T </span><s=
pan style=3D"color:rgb(0,0,136)">const</span><span style=3D"color:rgb(102,1=
02,0)">&amp;);</span><span style=3D"color:rgb(0,0,0)"><br>

=C2=A0 optional</span><span style=3D"color:rgb(102,102,0)">(</span><span st=
yle=3D"color:rgb(0,0,0)">T </span><span style=3D"color:rgb(102,102,0)">&amp=
;&amp;);</span><span style=3D"color:rgb(0,0,0)"><br><br>=C2=A0 </span><span=
 style=3D"color:rgb(0,0,136)">template</span><span style=3D"color:rgb(0,0,0=
)"> </span><span style=3D"color:rgb(102,102,0)">&lt;</span><span style=3D"c=
olor:rgb(0,0,136)">typename</span><span style=3D"color:rgb(0,0,0)"> U</span=
><span style=3D"color:rgb(102,102,0)">&gt;</span><span style=3D"color:rgb(0=
,0,0)"><br>

=C2=A0 optional</span><span style=3D"color:rgb(102,102,0)">(</span><span st=
yle=3D"color:rgb(0,0,0)">optional</span><span style=3D"color:rgb(102,102,0)=
">&lt;</span><span style=3D"color:rgb(0,0,0)">U</span><span style=3D"color:=
rgb(102,102,0)">&gt;</span><span style=3D"color:rgb(0,0,0)"> </span><span s=
tyle=3D"color:rgb(102,102,0)">&amp;&amp;)</span><span style=3D"color:rgb(0,=
0,0)"> requires </span><span style=3D"color:rgb(102,102,0)">!</span><span s=
tyle=3D"color:rgb(0,0,0)">is_convertible</span><span style=3D"color:rgb(102=
,102,0)">&lt;</span><span style=3D"color:rgb(0,0,0)">optional</span><span s=
tyle=3D"color:rgb(102,102,0)">&lt;</span><span style=3D"color:rgb(0,0,0)">U=
</span><span style=3D"color:rgb(102,102,0)">&gt;,</span><span style=3D"colo=
r:rgb(0,0,0)"> T</span><span style=3D"color:rgb(102,102,0)">&gt;::</span><s=
pan style=3D"color:rgb(0,0,0)">value</span><span style=3D"color:rgb(102,102=
,0)">;</span><span style=3D"color:rgb(0,0,0)"><br>

<br>=C2=A0 </span><span style=3D"color:rgb(0,0,136)">template</span><span s=
tyle=3D"color:rgb(0,0,0)"> </span><span style=3D"color:rgb(102,102,0)">&lt;=
</span><span style=3D"color:rgb(0,0,136)">typename</span><span style=3D"col=
or:rgb(0,0,0)"> U</span><span style=3D"color:rgb(102,102,0)">&gt;</span><sp=
an style=3D"color:rgb(0,0,0)"><br>

=C2=A0 optional</span><span style=3D"color:rgb(102,102,0)">(</span><span st=
yle=3D"color:rgb(0,0,0)">optional</span><span style=3D"color:rgb(102,102,0)=
">&lt;</span><span style=3D"color:rgb(0,0,0)">U</span><span style=3D"color:=
rgb(102,102,0)">&gt;</span><span style=3D"color:rgb(0,0,0)"> </span><span s=
tyle=3D"color:rgb(0,0,136)">const</span><span style=3D"color:rgb(102,102,0)=
">&amp;)</span><span style=3D"color:rgb(0,0,0)"> requires </span><span styl=
e=3D"color:rgb(102,102,0)">!</span><span style=3D"color:rgb(0,0,0)">is_conv=
ertible</span><span style=3D"color:rgb(102,102,0)">&lt;</span><span style=
=3D"color:rgb(0,0,0)">optional</span><span style=3D"color:rgb(102,102,0)">&=
lt;</span><span style=3D"color:rgb(0,0,0)">U</span><span style=3D"color:rgb=
(102,102,0)">&gt;,</span><span style=3D"color:rgb(0,0,0)"> T</span><span st=
yle=3D"color:rgb(102,102,0)">&gt;::</span><span style=3D"color:rgb(0,0,0)">=
value</span><span style=3D"color:rgb(102,102,0)">;</span><span style=3D"col=
or:rgb(0,0,0)"><br>

</span><span style=3D"color:rgb(102,102,0)">};</span><span style=3D"color:r=
gb(0,0,0)"><br></span></div></code></div><div><br>This makes case 1 work in=
tuitively and makes case 2 a compiler error.<br>Any opinions are welcome.<b=
r>

</div></div></blockquote><div><br></div><div>I like it. I believe the &#39;=
requires&#39; clause on the second overload should read=C2=A0!is_convertibl=
e&lt;<b>const optional&lt;U&gt;&amp;</b>, T&gt;::value.</div><div><br></div=
>

<div>What about the following example?</div><div><div><div style=3D"border:=
1px solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,25=
0,250)"><code><span style=3D"color:rgb(0,0,136)">struct</span><span style=
=3D"color:rgb(0,0,0)">=C2=A0</span><span style=3D"color:rgb(102,0,102)">Too=
l</span><span style=3D"color:rgb(0,0,0)"><br>

</span><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rg=
b(0,0,0)"><br>=C2=A0<b>explicit</b>=C2=A0</span><span style=3D"color:rgb(10=
2,0,102)">Tool</span><span style=3D"color:rgb(102,102,0)">(</span><span sty=
le=3D"color:rgb(0,136,0)">int</span><span style=3D"color:rgb(102,102,0)">);=
</span><span style=3D"color:rgb(0,0,0)"><br>

</span><span style=3D"color:rgb(102,102,0)">};</span><span style=3D"color:r=
gb(0,0,0)"><br><br></span><span style=3D"color:rgb(0,0,0)">optional</span><=
span style=3D"color:rgb(0,136,0)">&lt;int&gt;</span><span style=3D"color:rg=
b(0,0,0)">=C2=A0oi=C2=A0</span><span style=3D"color:rgb(102,102,0)">=3D</sp=
an><span style=3D"color:rgb(0,0,0)">=C2=A0</span><span style=3D"color:rgb(0=
,102,102)">1</span><span style=3D"color:rgb(102,102,0)">;</span><span style=
=3D"color:rgb(0,0,0)"><br>

</span><span style=3D"color:rgb(0,0,0)">optional</span><span style=3D"color=
:rgb(102,102,0)">&lt;</span><span style=3D"color:rgb(102,0,102)">Tool</span=
><span style=3D"color:rgb(102,102,0)">&gt;</span><span style=3D"color:rgb(0=
,0,0)">=C2=A0ot(oi</span><span style=3D"color:rgb(0,0,0)">)</span><span sty=
le=3D"color:rgb(102,102,0)">;</span><span style=3D"color:rgb(0,0,0)"><br>

</span></code></div></div><pre><code><code><span style=3D"font-family:arial=
,helvetica,sans-serif">Error or call optional&lt;T&gt;(optional&lt;U&gt;&am=
p;&amp;)?</span></code></code></pre></div><div>Roman Perepelitsa.</div></di=
v>

</div></div>

<p></p>

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

--047d7b3432369ab3df04fc42b0a1--

.


Author: Andrzej Krzemienski <akrzemi1@gmail.com>
Date: Fri, 20 Jun 2014 14:18:29 +0200
Raw View
--f46d04138cb1c3f93204fc437d48
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

2014-06-20 13:20 GMT+02:00 Roman Perepelitsa <roman.perepelitsa@gmail.com>:
>
>
> What about the following example?
> struct Tool
> {
>  *explicit* Tool(int);
>
> };
>
> optional<int> oi =3D 1;
> optional<Tool> ot(oi);
>
> Error or call optional<T>(optional<U>&&)?
>
> I am not worried about this problem. It is orthogonal to the one I
described above, and it can be solved with a "conditionally explicit
constructor" as described by Daniel Kr=C3=BCgler in:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3680.html


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

--f46d04138cb1c3f93204fc437d48
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">2014-06-20 13:20 GMT+02:00 Roman Perepelitsa <span dir=3D"ltr">&lt;=
<a href=3D"mailto:roman.perepelitsa@gmail.com" target=3D"_blank">roman.pere=
pelitsa@gmail.com</a>&gt;</span>:<blockquote class=3D"gmail_quote" style=3D=
"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-le=
ft:1ex">
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote"><div=
><br></div>

<div>What about the following example?</div><div><div><div style=3D"border:=
1px solid rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,25=
0,250)"><code><span style=3D"color:rgb(0,0,136)">struct</span><span style=
=3D"color:rgb(0,0,0)">=C2=A0</span><span style=3D"color:rgb(102,0,102)">Too=
l</span><span style=3D"color:rgb(0,0,0)"><br>


</span><span style=3D"color:rgb(102,102,0)">{</span><span style=3D"color:rg=
b(0,0,0)"><br>=C2=A0<b>explicit</b>=C2=A0</span><span style=3D"color:rgb(10=
2,0,102)">Tool</span><span style=3D"color:rgb(102,102,0)">(</span><span sty=
le=3D"color:rgb(0,136,0)">int</span><span style=3D"color:rgb(102,102,0)">);=
</span><div class=3D"">
<span style=3D"color:rgb(0,0,0)"><br>

</span><span style=3D"color:rgb(102,102,0)">};</span><span style=3D"color:r=
gb(0,0,0)"><br><br></span><span style=3D"color:rgb(0,0,0)">optional</span><=
span style=3D"color:rgb(0,136,0)">&lt;int&gt;</span><span style=3D"color:rg=
b(0,0,0)">=C2=A0oi=C2=A0</span><span style=3D"color:rgb(102,102,0)">=3D</sp=
an><span style=3D"color:rgb(0,0,0)">=C2=A0</span><span style=3D"color:rgb(0=
,102,102)">1</span><span style=3D"color:rgb(102,102,0)">;</span><span style=
=3D"color:rgb(0,0,0)"><br>


</span></div><span style=3D"color:rgb(0,0,0)">optional</span><span style=3D=
"color:rgb(102,102,0)">&lt;</span><span style=3D"color:rgb(102,0,102)">Tool=
</span><span style=3D"color:rgb(102,102,0)">&gt;</span><span style=3D"color=
:rgb(0,0,0)">=C2=A0ot(oi</span><span style=3D"color:rgb(0,0,0)">)</span><sp=
an style=3D"color:rgb(102,102,0)">;</span><span style=3D"color:rgb(0,0,0)">=
<br>


</span></code></div></div><pre><code><code><span style=3D"font-family:arial=
,helvetica,sans-serif">Error or call optional&lt;T&gt;(optional&lt;U&gt;&am=
p;&amp;)?</span></code></code></pre></div></div></div></div></blockquote>
<div>I am not worried about this problem. It is orthogonal to the one I des=
cribed above, and it can be solved with a &quot;conditionally explicit cons=
tructor&quot; as described by Daniel Kr=C3=BCgler in: <a href=3D"http://www=
..open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3680.html">http://www.open-s=
td.org/jtc1/sc22/wg21/docs/papers/2013/n3680.html</a><br>
<br><br></div><div>Regards,<br></div><div>&amp;rzej<br></div></div></div></=
div>

<p></p>

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

--f46d04138cb1c3f93204fc437d48--

.


Author: tomaszkam@gmail.com
Date: Sat, 21 Jun 2014 01:08:51 -0700 (PDT)
Raw View
------=_Part_1194_17051930.1403338132021
Content-Type: text/plain; charset=UTF-8

At the first thought I support the compilation error, because I do not have
any intuition on which of the constructor should be preferred, but maybe
that is only matter of being familiar with the new optional design, so I
will try to analyze the situation from objective view.

We have two constructors:
unboxing: optional<T> from optional<U>, that constructs T from U if
optional is initialized
forwarding: optional<T> from V, that constructs T from U
The problem is that if T can be constructed both from U and optional<U> we
have ambiguity, now we can select one of 3:
1) Compilation error and let the programmer decide
2) Preffer unbonxing constructor
3) Preffer forwarding constructor

1. Let analyze all options basing on the ability of the programmer to
select specified constructor if other is prefferd (on non of them). Let
assume that optional<U> ou
1) to use unboxing: in the current state of proposal we do not have any
make_if function, so the only way is to use if.
  optional<T> ot = ou ? optional<T>{in_place, *ou} : optional<T>{};
2) to use forwarding:
  optional<T> ot{ in_place, ou }
This suggest that unboxing constructor should be preffered, because we
provide an elegant way to force us of forwarding constructor. But this
argument want apply if we provide a make_if function/constructor.

2. If we choose one of the preference path, then we may introduce a hard to
find error cause by silent code behavior change if the constructor is added
to overload set. Let assume we have following:
  class Test { Test(optional<int>); }
  optional<Test> ot = optional<int>{};
  //In this example the ot will be always initialized with optional<int>
because the forwarding constructor is only match.
But if we add another constructor to the class Test and assume preference
of unboxing:
  class Test { Test(double); Test(optional<int>); }
  optional<Test> ot = optional<int>{};
  //In this example the ot will not be initialized, because unboxing is
preffered.
This silent code changes may cause very subtle and hard to find errors that
will be introduced silently. This argument suggest that we should go with
compilation error path.

3. We the current design the meaning of construction of optional<T> from
optional<U> depends of set of constructors that is available for type T.
The problem is that this set is not clearly visible for the programmer at
the point of doing such construction and may change from the point when
code was written and introduce errors.
This suggest our jest another solutions -> optional will always do
unboxing, despite the available constructors of T.
unboxing: optional<T> from optional<U>, requires that U is constructible
from T
forwarding: optional<T> from V, requires that V is not optional and T is
constructible from V
That will combine benefits from both point 1 and 2.

In case of your examples:
//case 1
optional<int> oi = 1;
optional<Tool> ot = oi; //error, Tool is not construtible from int
optional<Tool> ot{in_place, oi}; //ok
optional<Tool> ot = make_optional(oi); //ok, optional<optional<int>> is
unboxed

//case 2
optional<int> oi = 1;
optional<Tool> ot = oi; //ok, selects Tool(int) because of unboxing
optional<Tool> ot{in_place, oi}; //ok, selets Tool(optional<int>)
optional<Tool> ot = make_optional(oi); //ok, optional<optional<int>> is
unboxed

--

---
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_1194_17051930.1403338132021
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">At the first thought I support the compilation error, beca=
use I do not have any intuition on which of the constructor should be prefe=
rred, but maybe that is only matter of being familiar with the new optional=
 design, so I will try to analyze the situation from objective view.<br><br=
>We have two constructors:<br>unboxing: optional&lt;T&gt; from optional&lt;=
U&gt;, that constructs T from U if optional is initialized<br>forwarding: o=
ptional&lt;T&gt; from V, that constructs T from U<br>The problem is that if=
 T can be constructed both from U and optional&lt;U&gt; we have ambiguity, =
now we can select one of 3:<br>1) Compilation error and let the programmer =
decide<br>2) Preffer unbonxing constructor<br>3) Preffer forwarding constru=
ctor<br><br>1. Let analyze all options basing on the ability of the program=
mer to select specified constructor if other is prefferd (on non of them). =
Let assume that optional&lt;U&gt; ou<br>1) to use unboxing: in the current =
state of proposal we do not have any make_if function, so the only way is t=
o use if.<br><span style=3D"font-family: courier new,monospace;">&nbsp; opt=
ional&lt;T&gt; ot =3D ou ? optional&lt;T&gt;{in_place, *ou} : optional&lt;T=
&gt;{};</span><br>2) to use forwarding:<br><span style=3D"font-family: cour=
ier new,monospace;">&nbsp; optional&lt;T&gt; ot{ in_place, ou }</span><br>T=
his suggest that unboxing constructor should be preffered, because we provi=
de an elegant way to force us of forwarding constructor. But this argument =
want apply if we provide a make_if function/constructor.<br><br>2. If we ch=
oose one of the preference path, then we may introduce a hard to find error=
 cause by silent code behavior change if the constructor is added to overlo=
ad set. Let assume we have following:<br><span style=3D"font-family: courie=
r new,monospace;">&nbsp; class Test { Test(optional&lt;int&gt;); }<br>&nbsp=
; optional&lt;Test&gt; ot =3D optional&lt;int&gt;{}; <br>&nbsp; //In this e=
xample the ot will be always initialized with optional&lt;int&gt; because t=
he forwarding constructor is only match.</span><br>But if we add another co=
nstructor to the class Test and assume preference of unboxing:<br><span sty=
le=3D"font-family: courier new,monospace;">&nbsp; class Test { Test(double)=
; Test(optional&lt;int&gt;); }<br>&nbsp; optional&lt;Test&gt; ot =3D option=
al&lt;int&gt;{}; <br>&nbsp; //In this example the ot will not be initialize=
d, because unboxing is preffered.</span><br>This silent code changes may ca=
use very subtle and hard to find errors that will be introduced silently. T=
his argument suggest that we should go with compilation error path.<br><br>=
3. We the current design the meaning of construction of optional&lt;T&gt; f=
rom optional&lt;U&gt; depends of set of constructors that is available for =
type T.<br>The problem is that this set is not clearly visible for the prog=
rammer at the point of doing such construction and may change from the poin=
t when code was written and introduce errors.<br>This suggest our jest anot=
her solutions -&gt; optional will always do unboxing, despite the available=
 constructors of T.<br>unboxing: optional&lt;T&gt; from optional&lt;U&gt;, =
requires that U is constructible from T<br>forwarding: optional&lt;T&gt; fr=
om V, requires that V is not optional and T is constructible from V<br>That=
 will combine benefits from both point 1 and 2.<br><br>In case of your exam=
ples:<br><span style=3D"font-family: courier new,monospace;">//case 1<br>op=
tional&lt;int&gt; oi =3D 1;<br>optional&lt;Tool&gt; ot =3D oi; //error, Too=
l is not construtible from int<br>optional&lt;Tool&gt; ot{in_place, oi}; //=
ok<br>optional&lt;Tool&gt; ot<code><span style=3D"color:#660"></span></code=
> =3D make_optional(oi); //ok, optional&lt;optional&lt;int&gt;&gt; is unbox=
ed</span><br><br><span style=3D"font-family: courier new,monospace;">//case=
 2<br>optional&lt;int&gt; oi =3D 1;<br>optional&lt;Tool&gt; ot =3D oi; //ok=
, selects Tool(int) because of unboxing<br>optional&lt;Tool&gt; ot{in_place=
, oi}; //ok, selets Tool(optional&lt;int&gt;)<br>optional&lt;Tool&gt; ot<co=
de><span style=3D"color:#660"></span></code> =3D make_optional(oi); //ok, o=
ptional&lt;optional&lt;int&gt;&gt; is unboxed</span><br><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&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_1194_17051930.1403338132021--

.


Author: tomaszkam@gmail.com
Date: Mon, 23 Jun 2014 08:31:45 -0700 (PDT)
Raw View
------=_Part_813_5471258.1403537505453
Content-Type: text/plain; charset=UTF-8

I want to also mention one thing, if the optional will have following set
of constructors:
template <typename T>
class optional
{
  //from-T
  optional(T const&);
  optional(T &&);

  //unboxing
  template <typename U>
  optional(optional<U> &&) requires is_construtible<T, U>::value;

  template <typename U>
  optional(optional<U> const&) requires is_construtible<T, U>::value;

  //forwarding
  template <typename U>
  optional(U&&) requires is_construtible<T, U&&>::value &&
!is_optional<U>::value;
};

The from-T constructor seems to be an extesion to forwarding constructor,
but they existence may cause the always unboxing rule to not be actually
aplied (they wont be applied with optional<optional<T>>). For example if we
have:
  optional<double> const os{};
  optional<optional<double>> od = os; //The from-T constructor will apply
and od will be initialized with uninitialized optional as value.
But if we have very similar code:
  optional<int> const os{};
  optional<optional<double>> od = os; //The unboxing constructor will apply
and od will not be initialized.
If the os is intialized the behaviour of both constructors will be the same
- od will be intialized with intialized optional as value.

To fix the problem I propose to remove the from-T constructor and leave
only unboxing and forwarding constructor, because the forwarding
constructor can replace from-T constructors. Also default generated move
and copy constructor for optional, behaves exactly like unboxing ones, so
there are no problem with them.

--

---
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_813_5471258.1403537505453
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I want to also mention one thing, if the optional will hav=
e following set of constructors:<br><div style=3D"background-color:rgb(250,=
250,250);border-color:rgb(187,187,187);border-style:solid;border-width:1px;=
word-wrap:break-word"><code><div><span style=3D"color:#008">template</span>=
<span style=3D"color:#000"> </span><span style=3D"color:#660">&lt;</span><s=
pan style=3D"color:#008">typename</span><span style=3D"color:#000"> T</span=
><span style=3D"color:#660">&gt;</span><span style=3D"color:#000"><br></spa=
n><span style=3D"color:#008">class</span><span style=3D"color:#000"> option=
al<br></span><span style=3D"color:#660">{</span><span style=3D"color:#000">=
<br>&nbsp; //from-T<br>&nbsp; optional</span><span style=3D"color:#660">(</=
span><span style=3D"color:#000">T </span><span style=3D"color:#008">const</=
span><span style=3D"color:#660">&amp;);</span><span style=3D"color:#000"><b=
r>&nbsp; optional</span><span style=3D"color:#660">(</span><span style=3D"c=
olor:#000">T </span><span style=3D"color:#660">&amp;&amp;);</span><span sty=
le=3D"color:#000"><br><br>&nbsp; //unboxing<br>&nbsp; </span><span style=3D=
"color:#008">template</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">&lt;</span><span style=3D"color:#008">typename</span><span =
style=3D"color:#000"> U</span><span style=3D"color:#660">&gt;</span><span s=
tyle=3D"color:#000"><br>&nbsp; optional</span><span style=3D"color:#660">(<=
/span><span style=3D"color:#000">optional</span><span style=3D"color:#660">=
&lt;</span><span style=3D"color:#000">U</span><span style=3D"color:#660">&g=
t;</span><span style=3D"color:#000"> </span><span style=3D"color:#660">&amp=
;&amp;)</span><span style=3D"color:#000"> requires&nbsp;</span><span style=
=3D"color:#660"></span><span style=3D"color:#000">is_construtible</span><sp=
an style=3D"color:#660">&lt;</span><span style=3D"color:#000"></span><span =
style=3D"color:#660"></span><span style=3D"color:#000"></span><span style=
=3D"color:#660">T,</span><span style=3D"color:#000"> U</span><span style=3D=
"color:#660">&gt;::</span><span style=3D"color:#000">value</span><span styl=
e=3D"color:#660">;</span><span style=3D"color:#000"><br><br>&nbsp; </span><=
span style=3D"color:#008">template</span><span style=3D"color:#000"> </span=
><span style=3D"color:#660">&lt;</span><span style=3D"color:#008">typename<=
/span><span style=3D"color:#000"> U</span><span style=3D"color:#660">&gt;</=
span><span style=3D"color:#000"><br>&nbsp; optional</span><span style=3D"co=
lor:#660">(</span><span style=3D"color:#000">optional</span><span style=3D"=
color:#660">&lt;</span><span style=3D"color:#000">U</span><span style=3D"co=
lor:#660">&gt;</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#008">const</span><span style=3D"color:#660">&amp;)</span><span style=3D"=
color:#000"> requires </span><span style=3D"color:#660"></span><code><span =
style=3D"color:#000">is_construtible</span><span style=3D"color:#660">&lt;<=
/span><span style=3D"color:#000"></span><span style=3D"color:#660"></span><=
span style=3D"color:#000"></span><span style=3D"color:#660">T,</span><span =
style=3D"color:#000"> U</span><span style=3D"color:#660">&gt;::</span><span=
 style=3D"color:#000">value</span></code><span style=3D"color:#000"></span>=
<span style=3D"color:#660">;</span><span style=3D"color:#000"><br><br>&nbsp=
; //forwarding<br>&nbsp; </span><code><span style=3D"color:#008">template</=
span><span style=3D"color:#000"> </span><span style=3D"color:#660">&lt;</sp=
an><span style=3D"color:#008">typename</span><span style=3D"color:#000"> U<=
/span><span style=3D"color:#660">&gt;</span><span style=3D"color:#000"><br>=
&nbsp; optional(U&amp;&amp;) requires </span></code><code><code><span style=
=3D"color:#000">is_construtible</span><span style=3D"color:#660">&lt;</span=
><span style=3D"color:#000"></span><span style=3D"color:#660"></span><span =
style=3D"color:#000"></span><span style=3D"color:#660">T,</span><span style=
=3D"color:#000"> U</span><span style=3D"color:#660">&amp;&amp;&gt;::</span>=
<span style=3D"color:#000">value</span></code><span style=3D"color:#000"></=
span><span style=3D"color:#660"> &amp;&amp; !is_optional&lt;U&gt;::value;</=
span></code><code><span style=3D"color:#000"><br></span></code><span style=
=3D"color:#660">};</span><span style=3D"color:#000"><br></span></div></code=
></div><br><div dir=3D"ltr">The from-T constructor seems to be an extesion =
to forwarding constructor, but they existence may cause the always unboxing=
 rule to not be actually aplied (they wont be applied with optional&lt;opti=
onal&lt;T&gt;&gt;). For example if we have:<br><span style=3D"font-family: =
courier new,monospace;">&nbsp; optional&lt;double&gt; const os{};<br>&nbsp;=
 optional&lt;optional&lt;double&gt;&gt; od =3D os; //The from-T constructor=
 will apply and od will be initialized with uninitialized optional as value=
..</span><br>But if we have very similar code:<br><span style=3D"font-family=
: courier new,monospace;">&nbsp; optional&lt;int&gt; const os{};<br>&nbsp;
 optional&lt;optional&lt;double&gt;&gt; od =3D os; //The unboxing construct=
or will apply and od will not be initialized.</span> <br>If the os is intia=
lized the behaviour of both constructors will be the same - od will be inti=
alized with intialized optional as value. <br><br>To fix the problem I prop=
ose to remove the from-T constructor and leave only unboxing and forwarding=
 constructor, because the forwarding constructor can replace from-T constru=
ctors. Also default generated move and copy constructor for optional, behav=
es exactly like unboxing ones, so there are no problem with them.<br> </div=
></div>

<p></p>

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

------=_Part_813_5471258.1403537505453--

.


Author: =?UTF-8?Q?Andrzej_Krzemie=C5=84ski?= <akrzemi1@gmail.com>
Date: Mon, 7 Jul 2014 07:24:00 -0700 (PDT)
Raw View
------=_Part_36_32393936.1404743041124
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



W dniu poniedzia=C5=82ek, 23 czerwca 2014 17:31:45 UTC+2 u=C5=BCytkownik=20
toma...@gmail.com napisa=C5=82:
>
> I want to also mention one thing, if the optional will have following set=
=20
> of constructors:
> template <typename T>
> class optional
> {
>   //from-T
>   optional(T const&);
>   optional(T &&);
>
>   //unboxing
>   template <typename U>
>   optional(optional<U> &&) requires is_construtible<T, U>::value;
>
>   template <typename U>
>   optional(optional<U> const&) requires is_construtible<T, U>::value;
>
>   //forwarding
>   template <typename U>
>   optional(U&&) requires is_construtible<T, U&&>::value &&=20
> !is_optional<U>::value;
> };
>
> The from-T constructor seems to be an extesion to forwarding constructor,=
=20
> but they existence may cause the always unboxing rule to not be actually=
=20
> aplied (they wont be applied with optional<optional<T>>). For example if =
we=20
> have:
>   optional<double> const os{};
>   optional<optional<double>> od =3D os; //The from-T constructor will app=
ly=20
> and od will be initialized with uninitialized optional as value.
> But if we have very similar code:
>   optional<int> const os{};
>   optional<optional<double>> od =3D os; //The unboxing constructor will=
=20
> apply and od will not be initialized.=20
> If the os is intialized the behaviour of both constructors will be the=20
> same - od will be intialized with intialized optional as value.=20
>
> To fix the problem I propose to remove the from-T constructor and leave=
=20
> only unboxing and forwarding constructor, because the forwarding=20
> constructor can replace from-T constructors. Also default generated move=
=20
> and copy constructor for optional, behaves exactly like unboxing ones, so=
=20
> there are no problem with them.
>

One problem with having such "from any convertible U" constructor has been=
=20
discussed in the past. See this post and the subsequent discussion:

https://groups.google.com/a/isocpp.org/d/msg/std-proposals/uK1HfW4YTEU/u_wZ=
Wh-2KzMJ

In short, having this constructor can introduce a number of overload=20
resolution ambiguities:

void fun(optional<T> const& v);
void fun(T const& v);

U u;
fun(u);

U is convertible to T, so both candidates are viable.

=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_36_32393936.1404743041124
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>W dniu poniedzia=C5=82ek, 23 czerwca 2014 17:31:45=
 UTC+2 u=C5=BCytkownik toma...@gmail.com napisa=C5=82:<blockquote class=3D"=
gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc so=
lid;padding-left: 1ex;"><div dir=3D"ltr">I want to also mention one thing, =
if the optional will have following set of constructors:<br><div style=3D"b=
ackground-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style=
:solid;border-width:1px;word-wrap:break-word"><code><div><span style=3D"col=
or:#008">template</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#660">&lt;</span><span style=3D"color:#008">typename</span><span style=
=3D"color:#000"> T</span><span style=3D"color:#660">&gt;</span><span style=
=3D"color:#000"><br></span><span style=3D"color:#008">class</span><span sty=
le=3D"color:#000"> optional<br></span><span style=3D"color:#660">{</span><s=
pan style=3D"color:#000"><br>&nbsp; //from-T<br>&nbsp; optional</span><span=
 style=3D"color:#660">(</span><span style=3D"color:#000">T </span><span sty=
le=3D"color:#008">const</span><span style=3D"color:#660">&amp;);</span><spa=
n style=3D"color:#000"><br>&nbsp; optional</span><span style=3D"color:#660"=
>(</span><span style=3D"color:#000">T </span><span style=3D"color:#660">&am=
p;&amp;);</span><span style=3D"color:#000"><br><br>&nbsp; //unboxing<br>&nb=
sp; </span><span style=3D"color:#008">template</span><span style=3D"color:#=
000"> </span><span style=3D"color:#660">&lt;</span><span style=3D"color:#00=
8">typename</span><span style=3D"color:#000"> U</span><span style=3D"color:=
#660">&gt;</span><span style=3D"color:#000"><br>&nbsp; optional</span><span=
 style=3D"color:#660">(</span><span style=3D"color:#000">optional</span><sp=
an style=3D"color:#660">&lt;</span><span style=3D"color:#000">U</span><span=
 style=3D"color:#660">&gt;</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#660">&amp;&amp;)</span><span style=3D"color:#000"> requires&=
nbsp;</span><span style=3D"color:#660"></span><span style=3D"color:#000">is=
_construtible</span><span style=3D"color:#660">&lt;</span><span style=3D"co=
lor:#000"></span><span style=3D"color:#660"></span><span style=3D"color:#00=
0"></span><span style=3D"color:#660">T,</span><span style=3D"color:#000"> U=
</span><span style=3D"color:#660">&gt;::</span><span style=3D"color:#000">v=
alue</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><b=
r><br>&nbsp; </span><span style=3D"color:#008">template</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">&lt;</span><span style=
=3D"color:#008">typename</span><span style=3D"color:#000"> U</span><span st=
yle=3D"color:#660">&gt;</span><span style=3D"color:#000"><br>&nbsp; optiona=
l</span><span style=3D"color:#660">(</span><span style=3D"color:#000">optio=
nal</span><span style=3D"color:#660">&lt;</span><span style=3D"color:#000">=
U</span><span style=3D"color:#660">&gt;</span><span style=3D"color:#000"> <=
/span><span style=3D"color:#008">const</span><span style=3D"color:#660">&am=
p;)</span><span style=3D"color:#000"> requires </span><span style=3D"color:=
#660"></span><code><span style=3D"color:#000">is_construtible</span><span s=
tyle=3D"color:#660">&lt;</span><span style=3D"color:#000"></span><span styl=
e=3D"color:#660"></span><span style=3D"color:#000"></span><span style=3D"co=
lor:#660">T,</span><span style=3D"color:#000"> U</span><span style=3D"color=
:#660">&gt;::</span><span style=3D"color:#000">value</span></code><span sty=
le=3D"color:#000"></span><span style=3D"color:#660">;</span><span style=3D"=
color:#000"><br><br>&nbsp; //forwarding<br>&nbsp; </span><code><span style=
=3D"color:#008">template</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">&lt;</span><span style=3D"color:#008">typename</span><spa=
n style=3D"color:#000"> U</span><span style=3D"color:#660">&gt;</span><span=
 style=3D"color:#000"><br>&nbsp; optional(U&amp;&amp;) requires </span></co=
de><code><code><span style=3D"color:#000">is_construtible</span><span style=
=3D"color:#660">&lt;</span><span style=3D"color:#000"></span><span style=3D=
"color:#660"></span><span style=3D"color:#000"></span><span style=3D"color:=
#660">T,</span><span style=3D"color:#000"> U</span><span style=3D"color:#66=
0">&amp;&amp;&gt;::</span><span style=3D"color:#000">value</span></code><sp=
an style=3D"color:#000"></span><span style=3D"color:#660"> &amp;&amp; !is_o=
ptional&lt;U&gt;::value;</span></code><code><span style=3D"color:#000"><br>=
</span></code><span style=3D"color:#660">};</span><span style=3D"color:#000=
"><br></span></div></code></div><br><div dir=3D"ltr">The from-T constructor=
 seems to be an extesion to forwarding constructor, but they existence may =
cause the always unboxing rule to not be actually aplied (they wont be appl=
ied with optional&lt;optional&lt;T&gt;&gt;). For example if we have:<br><sp=
an style=3D"font-family:courier new,monospace">&nbsp; optional&lt;double&gt=
; const os{};<br>&nbsp; optional&lt;optional&lt;double&gt;&gt; od =3D os; /=
/The from-T constructor will apply and od will be initialized with uninitia=
lized optional as value.</span><br>But if we have very similar code:<br><sp=
an style=3D"font-family:courier new,monospace">&nbsp; optional&lt;int&gt; c=
onst os{};<br>&nbsp;
 optional&lt;optional&lt;double&gt;&gt; od =3D os; //The unboxing construct=
or will apply and od will not be initialized.</span> <br>If the os is intia=
lized the behaviour of both constructors will be the same - od will be inti=
alized with intialized optional as value. <br><br>To fix the problem I prop=
ose to remove the from-T constructor and leave only unboxing and forwarding=
 constructor, because the forwarding constructor can replace from-T constru=
ctors. Also default generated move and copy constructor for optional, behav=
es exactly like unboxing ones, so there are no problem with them.<br></div>=
</div></blockquote><div><br>One problem with having such "from any converti=
ble U" constructor has been discussed in the past. See this post and the su=
bsequent discussion:<br><br>https://groups.google.com/a/isocpp.org/d/msg/st=
d-proposals/uK1HfW4YTEU/u_wZWh-2KzMJ<br><br>In short, having this construct=
or can introduce a number of overload resolution ambiguities:<br><br><div c=
lass=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-=
color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wra=
p: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><=
span style=3D"color: #008;" class=3D"styled-by-prettify">void</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> fun</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=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"color: #000;"=
 class=3D"styled-by-prettify">T</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">const</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>&amp;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> v</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">void</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> fun</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">T </span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">const</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&amp;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> v</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><b=
r>U u</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>fun</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">u</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span></div></code></div><br>U is conv=
ertible to T, so both candidates are viable.<br><br>&nbsp;<br></div></div>

<p></p>

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

------=_Part_36_32393936.1404743041124--

.


Author: tomaszkam@gmail.com
Date: Mon, 7 Jul 2014 08:33:09 -0700 (PDT)
Raw View
------=_Part_344_1296373.1404747189646
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

W dniu poniedzia=C5=82ek, 7 lipca 2014 16:24:01 UTC+2 u=C5=BCytkownik Andrz=
ej=20
Krzemie=C5=84ski napisa=C5=82:
>
>
> One problem with having such "from any convertible U" constructor has bee=
n=20
> discussed in the past. See this post and the subsequent discussion:
>
>
> https://groups.google.com/a/isocpp.org/d/msg/std-proposals/uK1HfW4YTEU/u_=
wZWh-2KzMJ
>
> In short, having this constructor can introduce a number of overload=20
> resolution ambiguities:
>
> void fun(optional<T> const& v);
> void fun(T const& v);
>
> U u;
> fun(u);
>
> U is convertible to T, so both candidates are viable.
>

This ambiguity problem may be fixed by making the the function that takes a=
=20
T an template:
namespace detail
{
  void fun(T const&)
}

template<typename U>
  requires is_construtible<T, U&&>::value && !is_optional<U>::value
inline void fun(U&& u)
{
  return f(std::forward<U>(u));
}

void fun(optional<T> const& t);

To avoid difference in observerable behaviour between code that define only=
=20
optional<T> overload and the one that has T overload implemented as a=20
template, the template overload should be has the same restrictions as=20
forwarding optional constructor (to preserve preference of unboxing rule).

--=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_344_1296373.1404747189646
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">W dniu poniedzia=C5=82ek, 7 lipca 2014 16:24:01 UTC+2 u=C5=
=BCytkownik Andrzej Krzemie=C5=84ski napisa=C5=82:<blockquote class=3D"gmai=
l_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;=
padding-left: 1ex;"><div dir=3D"ltr"><div><br>One problem with having such =
"from any convertible U" constructor has been discussed in the past. See th=
is post and the subsequent discussion:<br><br><a href=3D"https://groups.goo=
gle.com/a/isocpp.org/d/msg/std-proposals/uK1HfW4YTEU/u_wZWh-2KzMJ" target=
=3D"_blank" onmousedown=3D"this.href=3D'https://groups.google.com/a/isocpp.=
org/d/msg/std-proposals/uK1HfW4YTEU/u_wZWh-2KzMJ';return true;" onclick=3D"=
this.href=3D'https://groups.google.com/a/isocpp.org/d/msg/std-proposals/uK1=
HfW4YTEU/u_wZWh-2KzMJ';return true;">https://groups.google.com/a/<wbr>isocp=
p.org/d/msg/std-<wbr>proposals/uK1HfW4YTEU/u_wZWh-<wbr>2KzMJ</a><br><br>In =
short, having this constructor can introduce a number of overload resolutio=
n ambiguities:<br><br><div style=3D"background-color:rgb(250,250,250);borde=
r-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:brea=
k-word"><code><div><span style=3D"color:#008">void</span><span style=3D"col=
or:#000"> fun</span><span style=3D"color:#660">(</span><span style=3D"color=
:#000">optional</span><span style=3D"color:#660">&lt;</span><span style=3D"=
color:#000">T</span><span style=3D"color:#660">&gt;</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#008">const</span><span style=3D"col=
or:#660">&amp;</span><span style=3D"color:#000"> v</span><span style=3D"col=
or:#660">);</span><span style=3D"color:#000"><br></span><span style=3D"colo=
r:#008">void</span><span style=3D"color:#000"> fun</span><span style=3D"col=
or:#660">(</span><span style=3D"color:#000">T </span><span style=3D"color:#=
008">const</span><span style=3D"color:#660">&amp;</span><span style=3D"colo=
r:#000"> v</span><span style=3D"color:#660">);</span><span style=3D"color:#=
000"><br><br>U u</span><span style=3D"color:#660">;</span><span style=3D"co=
lor:#000"><br>fun</span><span style=3D"color:#660">(</span><span style=3D"c=
olor:#000">u</span><span style=3D"color:#660">);</span><span style=3D"color=
:#000"><br></span></div></code></div><br>U is convertible to T, so both can=
didates are viable.<br></div></div></blockquote><div><br><code>This ambigui=
ty problem may be fixed by making the the function that takes a T an templa=
te:<br>namespace detail<br>{<br>&nbsp; void fun(T const&amp;)<br>}<br><br>t=
emplate&lt;typename U&gt;<br>&nbsp; requires is_construtible&lt;T, U&amp;&a=
mp;&gt;::value &amp;&amp; !is_optional&lt;U&gt;::value<br>inline void fun(U=
&amp;&amp; u)<br>{<br>&nbsp; return f(std::forward&lt;U&gt;(u));<br>}<br><b=
r>void fun(optional&lt;T&gt; const&amp; t);<br><br>To avoid difference in o=
bserverable behaviour between code that define only optional&lt;T&gt; overl=
oad and the one that has T overload implemented as a template, the template=
 overload should be has the same restrictions as forwarding optional constr=
uctor (to preserve preference of unboxing rule).<code><br><span style=3D"co=
lor:#660"></span></code><code><span style=3D"color:#000"></span></code></co=
de></div></div>

<p></p>

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

------=_Part_344_1296373.1404747189646--

.


Author: tomaszkam@gmail.com
Date: Mon, 7 Jul 2014 08:51:03 -0700 (PDT)
Raw View
------=_Part_283_9947354.1404748263466
Content-Type: text/plain; charset=UTF-8

Actually I think I would recommend following as "pattern" aproach to such
overloaded functions.
namespace impl
{
  void fun(T const&);
  void fun(nullopt_t);
}

//is_optional<nullopt_t>::value should be true
template<typename U>
  requires is_construtible<T, U&&>::value && !is_optional<U>::value
inline void fun(U&& u)
{
  return impl::fun(std::forward<U>(u));
}

void fun(optional<T> const& t)
{
   return t ? impl::fun(*t) : impl::fun(nullopt);
}
This quarantines that both overloads has the same behaviour if t is present.

--

---
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_283_9947354.1404748263466
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Actually I think I would recommend following as "pattern" =
aproach to such overloaded functions.<br><code>namespace impl<br>{<br>&nbsp=
; void fun(T const&amp;);<br>&nbsp; void fun(nullopt_t); <br>}<br><br>//is_=
optional&lt;nullopt_t&gt;::value should be true<br>template&lt;typename U&g=
t;<br>&nbsp; requires is_construtible&lt;T, U&amp;&amp;&gt;::value &amp;&am=
p; !is_optional&lt;U&gt;::value<br>inline void fun(U&amp;&amp; u)<br>{<br>&=
nbsp; return </code><code><code>impl::</code>fun(std::forward&lt;U&gt;(u));=
<br>}<br><br>void fun(optional&lt;T&gt; const&amp; t)<br>{<br>&nbsp;&nbsp; =
return t ? impl::fun(*t) : impl::fun(nullopt);<br>}<br></code>This quaranti=
nes that both overloads has the same behaviour if t is present.<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&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_283_9947354.1404748263466--

.


Author: tomaszkam@gmail.com
Date: Tue, 8 Jul 2014 09:22:36 -0700 (PDT)
Raw View
------=_Part_42_30353594.1404836556636
Content-Type: text/plain; charset=UTF-8

I think that library can provide a helper class named tentatively named
handle_value_or_optional that will accepts value of type convertible with
the and two functors: one accepting the actual value and with no argument
for handling no value. In addition it should provide is_value_or_optional_compatible_with
functor.  That will make implementation of such functors easier from user
presepective:
namespace impl
{
  void fun(T const&);
  void fun(nullopt_t);
}

template<typename U>
  requires is_value_or_optional_compatible_with<U&&, T const&>
inline void fun(U&& u)
{
  return handle_value_or_optional<T const&>(
           std::forward<U>(u),
           [](T const& t) { return impl::fun(t); },
           [] { return impl::fun(nullopt); }
}

The example implementation of handle_value_or_optional:
template<typename T, typename U, typename FV, typename FN>
inline decltype(auto) handle_value_or_optional_impl(U&& u, FV&& fv, FN&&)
  requires !is_optional_v<decay_t<U>> && is_convertible_v<U&&, T>
{ return std::forward<FV>(fv)(std::forward<U>(u)); }

/* Avoid constucting optional<T> from optional<U> and use prefect
forwarding */
template<typename T, typename U, typename FV, typename FN>
inline decltype(auto) handle_value_or_optional_impl(optional<U>&& u, FV&&
fv, FN&& fn)
  requires is_optional_v<decay_t<U>> && is_convertible_v<U&&, T>
{
  return u ? std::forward<FV>(fv)(std::move(*u)) : std::forward<FN>(fn)();
}

template<typename T, typename U, typename FV, typename FN>
inline decltype(auto) handle_value_or_optional_impl(optional<U> const& u,
FV&& fv, FN&& fn)
  requires is_optional_v<decay_t<U>> && is_convertible_v<U const&, T>
{
  return u ? std::forward<FV>(fv)(*u) : std::forward<FN>(fn)();
}

template<typename T, typename U, typename FV, typename FN>
inline decltype(auto) handle_value_or_optional_impl(optional<U>& u, FV&&
fv, FN&& fn)
  requires is_optional_v<decay_t<U>> && is_convertible_v<U&, T>
{
  return u ? std::forward<FV>(fv)(*u) : std::forward<FN>(fn)();
}

/* Avoid if for fun(nullopt) case */
template<typename T, typename FV, typename FN>
inline decltype(auto) handle_value_or_optional_impl(nullopt_t, FV&&, FN&&
fn)
{
  return std::forward<FN>(fn)();
}

template<typename T, typename U, typename FV, typename FN>
inline decltype(auto) handle_value_or_optional(U&& u, FV&& fv, FN&& fn)
  requires is_value_or_optional_compatible_with_v<U&&, T>
{
  return handle_value_or_optional_impl<T>(std::forward<U>(u),
std::forward<FV>(fv), std::forward<FN>(fn));
}

--

---
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_42_30353594.1404836556636
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I think that library can provide a helper class named<span=
 id=3D"result_box" class=3D"short_text" lang=3D"en"><span class=3D"hps"> te=
ntatively</span> <span class=3D"hps">named handle_value_or_optional that wi=
ll accepts value of type convertible with the and two functors: one accepti=
ng the actual value and with no argument for handling no value. In addition=
 it should provide </span></span><span id=3D"result_box" class=3D"short_tex=
t" lang=3D"en"><span class=3D"hps"><code>is_value_or_optional_compatible_wi=
th functor.</code>&nbsp; That will make implementation of such functors eas=
ier from user presepective:<br></span></span><span id=3D"result_box" class=
=3D"short_text" lang=3D"en"><span class=3D"hps"><code>namespace impl<br>{<b=
r>&nbsp; void fun(T const&amp;);<br>&nbsp; void fun(nullopt_t); <br>}</code=
><br></span></span><br><code><div class=3D"GFO--0QGHB">template&lt;typename=
 U&gt;<br>&nbsp; requires is_value_or_optional_compatible_with&lt;U&amp;&am=
p;, T const&amp;&gt;<br>inline void fun(U&amp;&amp; u)<br>{<br></div>&nbsp;=
 return </code><code><code><span id=3D"result_box" class=3D"short_text" lan=
g=3D"en"><span class=3D"hps">handle_value_or_optional&lt;T const&amp;&gt;(<=
br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::forwar=
d&lt;U&gt;(u),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp; [](T const&amp; t) { return impl::fun(t); },<br>&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [] { return impl::fun(nullopt); }<br>=
</span></span></code><div class=3D"GFO--0QGHB">}<br><br>The example impleme=
ntation of handle_value_or_optional:<br>template&lt;typename T, typename U,=
 typename FV, typename FN&gt;<br>inline decltype(auto) handle_value_or_opti=
onal_impl(U&amp;&amp; u, FV&amp;&amp; fv, FN&amp;&amp;) <br>&nbsp; requires=
 !is_optional_v&lt;decay_t&lt;U&gt;&gt; &amp;&amp; is_convertible_v&lt;U&am=
p;&amp;, T&gt; <br>{ return std::forward&lt;FV&gt;(fv)(std::forward&lt;U&gt=
;(u)); }<br><br>/* Avoid constucting optional&lt;T&gt; from optional&lt;U&g=
t; and use prefect forwarding */<br>template&lt;typename T, typename U, typ=
ename FV, typename FN&gt;<br>inline decltype(auto) handle_value_or_optional=
_impl(optional&lt;U&gt;&amp;&amp; u, FV&amp;&amp; fv, FN&amp;&amp; fn) <br>=
&nbsp; requires is_optional_v&lt;decay_t&lt;U&gt;&gt; &amp;&amp; is_convert=
ible_v&lt;U&amp;&amp;, T&gt; <br>{<br>&nbsp; return u ? std::forward&lt;FV&=
gt;(fv)(std::move(*u)) : std::forward&lt;FN&gt;(fn)();<br>}<br><br>template=
&lt;typename T, typename U, typename FV, typename FN&gt;<br>inline decltype=
(auto) handle_value_or_optional_impl(optional&lt;U&gt; const&amp; u, FV&amp=
;&amp; fv, FN&amp;&amp; fn) <br>&nbsp; requires is_optional_v&lt;decay_t&lt=
;U&gt;&gt; &amp;&amp; is_convertible_v&lt;U const&amp;, T&gt; <br>{<br>&nbs=
p; return u ? std::forward&lt;FV&gt;(fv)(*u) : std::forward&lt;FN&gt;(fn)()=
;<br>}<br><br>template&lt;typename T, typename U, typename FV, typename FN&=
gt;<br>inline decltype(auto) handle_value_or_optional_impl(optional&lt;U&gt=
;&amp; u, FV&amp;&amp; fv, FN&amp;&amp; fn) <br>&nbsp; requires is_optional=
_v&lt;decay_t&lt;U&gt;&gt; &amp;&amp; is_convertible_v&lt;U&amp;, T&gt; <br=
>{<br>&nbsp; return u ? std::forward&lt;FV&gt;(fv)(*u) : std::forward&lt;FN=
&gt;(fn)();<br>}<br><br>/* Avoid if for fun(nullopt) case */<br>template&lt=
;typename T, typename FV, typename FN&gt;<br>inline decltype(auto) handle_v=
alue_or_optional_impl(nullopt_t, FV&amp;&amp;, FN&amp;&amp; fn) <br>{<br>&n=
bsp; return std::forward&lt;FN&gt;(fn)();<br>}<br><br>template&lt;typename =
T, typename U, typename FV, typename FN&gt;<br>inline decltype(auto) handle=
_value_or_optional(U&amp;&amp; u, FV&amp;&amp; fv, FN&amp;&amp; fn)<br>&nbs=
p; requires is_value_or_optional_compatible_with_v&lt;U&amp;&amp;, T&gt;<br=
>{<br>&nbsp; return handle_value_or_optional_impl&lt;T&gt;(std::forward&lt;=
U&gt;(u), std::forward&lt;FV&gt;(fv), std::forward&lt;FN&gt;(fn));<br>}<br>=
</div></code></div>

<p></p>

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

------=_Part_42_30353594.1404836556636--

.


Author: =?UTF-8?Q?Micha=C5=82_Dominiak?= <griwes@griwes.info>
Date: Tue, 8 Jul 2014 18:30:53 +0200
Raw View
--001a113643188b208204fdb11dd2
Content-Type: text/plain; charset=UTF-8

Since you have already mostly reinvented them (and so did future's .then),
can we get convenient syntax for monadic bind already?
On 8 Jul 2014 18:22, <tomaszkam@gmail.com> wrote:

> I think that library can provide a helper class named tentatively named
> handle_value_or_optional that will accepts value of type convertible with
> the and two functors: one accepting the actual value and with no argument
> for handling no value. In addition it should provide is_value_or_optional_compatible_with
> functor.  That will make implementation of such functors easier from user
> presepective:
> namespace impl
> {
>   void fun(T const&);
>   void fun(nullopt_t);
> }
>
> template<typename U>
>   requires is_value_or_optional_compatible_with<U&&, T const&>
> inline void fun(U&& u)
> {
>   return handle_value_or_optional<T const&>(
>            std::forward<U>(u),
>            [](T const& t) { return impl::fun(t); },
>            [] { return impl::fun(nullopt); }
> }
>
> The example implementation of handle_value_or_optional:
> template<typename T, typename U, typename FV, typename FN>
> inline decltype(auto) handle_value_or_optional_impl(U&& u, FV&& fv, FN&&)
>   requires !is_optional_v<decay_t<U>> && is_convertible_v<U&&, T>
> { return std::forward<FV>(fv)(std::forward<U>(u)); }
>
> /* Avoid constucting optional<T> from optional<U> and use prefect
> forwarding */
> template<typename T, typename U, typename FV, typename FN>
> inline decltype(auto) handle_value_or_optional_impl(optional<U>&& u, FV&&
> fv, FN&& fn)
>   requires is_optional_v<decay_t<U>> && is_convertible_v<U&&, T>
> {
>   return u ? std::forward<FV>(fv)(std::move(*u)) : std::forward<FN>(fn)();
> }
>
> template<typename T, typename U, typename FV, typename FN>
> inline decltype(auto) handle_value_or_optional_impl(optional<U> const& u,
> FV&& fv, FN&& fn)
>   requires is_optional_v<decay_t<U>> && is_convertible_v<U const&, T>
> {
>   return u ? std::forward<FV>(fv)(*u) : std::forward<FN>(fn)();
> }
>
> template<typename T, typename U, typename FV, typename FN>
> inline decltype(auto) handle_value_or_optional_impl(optional<U>& u, FV&&
> fv, FN&& fn)
>   requires is_optional_v<decay_t<U>> && is_convertible_v<U&, T>
> {
>   return u ? std::forward<FV>(fv)(*u) : std::forward<FN>(fn)();
> }
>
> /* Avoid if for fun(nullopt) case */
> template<typename T, typename FV, typename FN>
> inline decltype(auto) handle_value_or_optional_impl(nullopt_t, FV&&, FN&&
> fn)
> {
>   return std::forward<FN>(fn)();
> }
>
> template<typename T, typename U, typename FV, typename FN>
> inline decltype(auto) handle_value_or_optional(U&& u, FV&& fv, FN&& fn)
>   requires is_value_or_optional_compatible_with_v<U&&, T>
> {
>   return handle_value_or_optional_impl<T>(std::forward<U>(u),
> std::forward<FV>(fv), std::forward<FN>(fn));
> }
>
> --
>
> ---
> 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/.

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

<p dir=3D"ltr">Since you have already mostly reinvented them (and so did fu=
ture&#39;s .then), can we get convenient syntax for monadic bind already?</=
p>
<div class=3D"gmail_quote">On 8 Jul 2014 18:22,  &lt;<a href=3D"mailto:toma=
szkam@gmail.com">tomaszkam@gmail.com</a>&gt; wrote:<br type=3D"attribution"=
><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1=
px #ccc solid;padding-left:1ex">
<div dir=3D"ltr">I think that library can provide a helper class named<span=
 lang=3D"en"><span> tentatively</span> <span>named handle_value_or_optional=
 that will accepts value of type convertible with the and two functors: one=
 accepting the actual value and with no argument for handling no value. In =
addition it should provide </span></span><span lang=3D"en"><span><code>is_v=
alue_or_optional_compatible_with functor.</code>=C2=A0 That will make imple=
mentation of such functors easier from user presepective:<br>
</span></span><span lang=3D"en"><span><code>namespace impl<br>{<br>=C2=A0 v=
oid fun(T const&amp;);<br>=C2=A0 void fun(nullopt_t); <br>}</code><br></spa=
n></span><br><code><div>template&lt;typename U&gt;<br>=C2=A0 requires is_va=
lue_or_optional_compatible_with&lt;U&amp;&amp;, T const&amp;&gt;<br>
inline void fun(U&amp;&amp; u)<br>{<br></div>=C2=A0 return </code><code><co=
de><span lang=3D"en"><span>handle_value_or_optional&lt;T const&amp;&gt;(<br=
>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::forward&=
lt;U&gt;(u),<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0 [](T const&amp; t) { return impl::fun(t); },<br>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 [] { return im=
pl::fun(nullopt); }<br></span></span></code><div>}<br><br>The example imple=
mentation of handle_value_or_optional:<br>template&lt;typename T, typename =
U, typename FV, typename FN&gt;<br>inline decltype(auto) handle_value_or_op=
tional_impl(U&amp;&amp; u, FV&amp;&amp; fv, FN&amp;&amp;) <br>
=C2=A0 requires !is_optional_v&lt;decay_t&lt;U&gt;&gt; &amp;&amp; is_conver=
tible_v&lt;U&amp;&amp;, T&gt; <br>{ return std::forward&lt;FV&gt;(fv)(std::=
forward&lt;U&gt;(u)); }<br><br>/* Avoid constucting optional&lt;T&gt; from =
optional&lt;U&gt; and use prefect forwarding */<br>
template&lt;typename T, typename U, typename FV, typename FN&gt;<br>inline =
decltype(auto) handle_value_or_optional_impl(optional&lt;U&gt;&amp;&amp; u,=
 FV&amp;&amp; fv, FN&amp;&amp; fn) <br>=C2=A0 requires is_optional_v&lt;dec=
ay_t&lt;U&gt;&gt; &amp;&amp; is_convertible_v&lt;U&amp;&amp;, T&gt; <br>
{<br>=C2=A0 return u ? std::forward&lt;FV&gt;(fv)(std::move(*u)) : std::for=
ward&lt;FN&gt;(fn)();<br>}<br><br>template&lt;typename T, typename U, typen=
ame FV, typename FN&gt;<br>inline decltype(auto) handle_value_or_optional_i=
mpl(optional&lt;U&gt; const&amp; u, FV&amp;&amp; fv, FN&amp;&amp; fn) <br>
=C2=A0 requires is_optional_v&lt;decay_t&lt;U&gt;&gt; &amp;&amp; is_convert=
ible_v&lt;U const&amp;, T&gt; <br>{<br>=C2=A0 return u ? std::forward&lt;FV=
&gt;(fv)(*u) : std::forward&lt;FN&gt;(fn)();<br>}<br><br>template&lt;typena=
me T, typename U, typename FV, typename FN&gt;<br>
inline decltype(auto) handle_value_or_optional_impl(optional&lt;U&gt;&amp; =
u, FV&amp;&amp; fv, FN&amp;&amp; fn) <br>=C2=A0 requires is_optional_v&lt;d=
ecay_t&lt;U&gt;&gt; &amp;&amp; is_convertible_v&lt;U&amp;, T&gt; <br>{<br>=
=C2=A0 return u ? std::forward&lt;FV&gt;(fv)(*u) : std::forward&lt;FN&gt;(f=
n)();<br>
}<br><br>/* Avoid if for fun(nullopt) case */<br>template&lt;typename T, ty=
pename FV, typename FN&gt;<br>inline decltype(auto) handle_value_or_optiona=
l_impl(nullopt_t, FV&amp;&amp;, FN&amp;&amp; fn) <br>{<br>=C2=A0 return std=
::forward&lt;FN&gt;(fn)();<br>
}<br><br>template&lt;typename T, typename U, typename FV, typename FN&gt;<b=
r>inline decltype(auto) handle_value_or_optional(U&amp;&amp; u, FV&amp;&amp=
; fv, FN&amp;&amp; fn)<br>=C2=A0 requires is_value_or_optional_compatible_w=
ith_v&lt;U&amp;&amp;, T&gt;<br>
{<br>=C2=A0 return handle_value_or_optional_impl&lt;T&gt;(std::forward&lt;U=
&gt;(u), std::forward&lt;FV&gt;(fv), std::forward&lt;FN&gt;(fn));<br>}<br><=
/div></code></div>

<p></p>

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

<p></p>

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

--001a113643188b208204fdb11dd2--

.


Author: tomaszkam@gmail.com
Date: Tue, 8 Jul 2014 09:41:41 -0700 (PDT)
Raw View
------=_Part_267_5515869.1404837701775
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

W dniu wtorek, 8 lipca 2014 18:30:57 UTC+2 u=C5=BCytkownik Micha=C5=82 Domi=
niak=20
napisa=C5=82:
>
> Since you have already mostly reinvented them (and so did future's .then)=
,=20
> can we get convenient syntax for monadic bind already?
>
Could you please elaborate a bit how this solution can be mapped to monadic=
=20
bind? And to .then? I am not familiar with this concept. Most preferably if=
=20
you have links to same papers, articles or presentation on this topic.

Also jsut after posting I found that T argument is not necessary for=20
handle_value_or_optional, because I placed the checking on function that=20
uses it. So it can look like:
namespace impl
{
  void fun(T const&);
  void fun(nullopt_t);=20
}

template<typename U>
  requires is_value_or_optional_compatible_with<U&&, T const&>
inline void fun(U&& u)
{
  return handle_value_or_optional(
           std::forward<U>(u),
           [](T const& t) { return impl::fun(t); },
           [] { return impl::fun(nullopt); });
}

--=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_267_5515869.1404837701775
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">W dniu wtorek, 8 lipca 2014 18:30:57 UTC+2 u=C5=BCytkownik=
 Micha=C5=82 Dominiak napisa=C5=82:<blockquote class=3D"gmail_quote" style=
=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: =
1ex;"><p dir=3D"ltr">Since you have already mostly reinvented them (and so =
did future's .then), can we get convenient syntax for monadic bind already?=
</p>
<div class=3D"gmail_quote"></div></blockquote><div>Could you please elabora=
te a bit how this solution can be mapped to monadic bind? And to .then? I a=
m not familiar with this concept. Most preferably if you have links to same=
 papers, articles or presentation on this topic.<br><br>Also jsut after pos=
ting I found that T argument is not necessary for handle_value_or_optional,=
 because I placed the checking on function that uses it. So it can look lik=
e:<br><span lang=3D"en"><span><code>namespace impl<br>{<br>&nbsp; void fun(=
T const&amp;);<br>&nbsp; void fun(nullopt_t); <br>}</code><br></span></span=
><br><code><div>template&lt;typename U&gt;<br>&nbsp; requires is_value_or_o=
ptional_<wbr>compatible_with&lt;U&amp;&amp;, T const&amp;&gt;<br>
inline void fun(U&amp;&amp; u)<br>{<br></div>&nbsp; return </code><code><co=
de><span lang=3D"en"><span>handle_value_or_optional(<br>&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::forward&lt;U&gt;(u),<br>&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [](T const&amp; t)=
 { return impl::fun(t); },<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [] { return im=
pl::fun(nullopt); });<br></span></span></code><div>}</div></code><br></div>=
</div>

<p></p>

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

------=_Part_267_5515869.1404837701775--

.


Author: Bjorn Reese <breese@mail1.stofanet.dk>
Date: Tue, 08 Jul 2014 19:30:51 +0200
Raw View
On 07/08/2014 06:30 PM, Micha=C5=82 Dominiak wrote:
> Since you have already mostly reinvented them (and so did future's
> .then), can we get convenient syntax for monadic bind already?

N4015

--=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: =?UTF-8?Q?Micha=C5=82_Dominiak?= <griwes@griwes.info>
Date: Tue, 8 Jul 2014 19:46:02 +0200
Raw View
--047d7b6dd08446cc5504fdb22aa3
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

You should look for the Haskell tutorial on monads.

My point was, if `optional` gets something similar to what you are talking
about, it basically mostly becomes a monad. Similarly, when `future` gets
..then(), it becomes a monad, since .then() is pretty much a monadic bind on
it.

As for N4015, yes, that's another monad, which only makes it more obvious
we need something akin to Haskell's >>=3D (heck, we could even get exactly
>>=3D for this); otherwise, we will keep inventing new and new names for
different realizations of the same construct, and the code will get harder
and harder to read, while with special syntax for monadic bind, the code is
pretty much obvious, even if you don't know the particular monad that is
used by it.

On 8 July 2014 18:41, <tomaszkam@gmail.com> wrote:

> W dniu wtorek, 8 lipca 2014 18:30:57 UTC+2 u=C5=BCytkownik Micha=C5=82 Do=
miniak
> napisa=C5=82:
>
>> Since you have already mostly reinvented them (and so did future's
>> .then), can we get convenient syntax for monadic bind already?
>>
> Could you please elaborate a bit how this solution can be mapped to
> monadic bind? And to .then? I am not familiar with this concept. Most
> preferably if you have links to same papers, articles or presentation on
> this topic.
>
> Also jsut after posting I found that T argument is not necessary for
> handle_value_or_optional, because I placed the checking on function that
> uses it. So it can look like:
>
> namespace impl
> {
>   void fun(T const&);
>   void fun(nullopt_t);
> }
>
> template<typename U>
>   requires is_value_or_optional_compatible_with<U&&, T const&>
> inline void fun(U&& u)
> {
>   return handle_value_or_optional(
>
>            std::forward<U>(u),
>            [](T const& t) { return impl::fun(t); },
>            [] { return impl::fun(nullopt); });
> }
>
>  --
>
> ---
> 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/.
>

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

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

<div dir=3D"ltr">You should look for the Haskell tutorial on monads.<div><b=
r></div><div>My point was, if `optional` gets something similar to what you=
 are talking about, it basically mostly becomes a monad. Similarly, when `f=
uture` gets .then(), it becomes a monad, since .then() is pretty much a mon=
adic bind on it.<br>
<div class=3D"gmail_extra"><br></div><div class=3D"gmail_extra">As for N401=
5, yes, that&#39;s another monad, which only makes it more obvious we need =
something akin to Haskell&#39;s &gt;&gt;=3D (heck, we could even get exactl=
y &gt;&gt;=3D for this); otherwise, we will keep inventing new and new name=
s for different realizations of the same construct, and the code will get h=
arder and harder to read, while with special syntax for monadic bind, the c=
ode is pretty much obvious, even if you don&#39;t know the particular monad=
 that is used by it.<br>
<br><div class=3D"gmail_quote">On 8 July 2014 18:41,  <span dir=3D"ltr">&lt=
;<a href=3D"mailto:tomaszkam@gmail.com" target=3D"_blank">tomaszkam@gmail.c=
om</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"marg=
in:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir=3D"ltr">W dniu wtorek, 8 lipca 2014 18:30:57 UTC+2 u=C5=BCytkownik=
 Micha=C5=82 Dominiak napisa=C5=82:<div class=3D""><blockquote class=3D"gma=
il_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;pa=
dding-left:1ex"><p dir=3D"ltr">
Since you have already mostly reinvented them (and so did future&#39;s .the=
n), can we get convenient syntax for monadic bind already?</p>
<div class=3D"gmail_quote"></div></blockquote></div><div>Could you please e=
laborate a bit how this solution can be mapped to monadic bind? And to .the=
n? I am not familiar with this concept. Most preferably if you have links t=
o same papers, articles or presentation on this topic.<br>
<br>Also jsut after posting I found that T argument is not necessary for ha=
ndle_value_or_optional, because I placed the checking on function that uses=
 it. So it can look like:<div class=3D""><br><span lang=3D"en"><span><code>=
namespace impl<br>
{<br>=C2=A0 void fun(T const&amp;);<br>=C2=A0 void fun(nullopt_t); <br>}</c=
ode><br></span></span><br></div><code><div class=3D""><div>template&lt;type=
name U&gt;<br>=C2=A0 requires is_value_or_optional_<u></u>compatible_with&l=
t;U&amp;&amp;, T const&amp;&gt;<br>

inline void fun(U&amp;&amp; u)<br>{<br></div></div>=C2=A0 return </code><co=
de><code><span lang=3D"en"><span>handle_value_or_optional(<div class=3D""><=
br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::forwar=
d&lt;U&gt;(u),<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0 [](T const&amp; t) { return impl::fun(t); },<br>
</div>
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 [] { return im=
pl::fun(nullopt); });<br></span></span></code><div>}</div></code><br></div>=
</div><div class=3D"HOEnZb"><div class=3D"h5">

<p></p>

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

<p></p>

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

--047d7b6dd08446cc5504fdb22aa3--

.