Topic: Standin cast: A way to hide behind another object


Author: martin.molzer@gmx.de
Date: Wed, 29 Jul 2015 20:32:51 -0700 (PDT)
Raw View
------=_Part_3875_664483259.1438227171524
Content-Type: multipart/alternative;
 boundary="----=_Part_3876_540957450.1438227171525"

------=_Part_3876_540957450.1438227171525
Content-Type: text/plain; charset=UTF-8

Consider the upcoming optional<T>. In this particular case it will be
rather annoying and painful to always access the object behind the optional.

class Foo {
  int call();
  Foo& operator+(int);
};

// ...
optional<Foo> optFoo;
optFoo.get().call(); // Why not optFoo.call()?

There are two ideas that come to mind:

1. Add a way to make any expression relying on a Foo to be there, also
available for an optional<Foo>. You'd have to find a syntax for that and
also an implementation for the optional for example

optFoo.call(); // Returns optional<int>. When optFoo holds a Foo, calls
call() on it and stores the result
               // in an optional. Else, returns an empty optional

optFoo + 3; // Returns optional<Foo&>. Same as above.

The problem with this approach is that there currently exists no syntax
that says "if it doesn't work with an optional, try with the Foo it holds,
IF it holds any Foo".

We'd need a way to allow the optional to intercept the statement it is used
in (to return an empty optional) but also execute the statement it is a
standin for if there is a value it holds.

2. Assume the coder knows what he's doing and call get() instead. We have
to consider that *the only purpose of an optional is to hold or not hold
one specific value.* This leads me to the thought that maybe an optional
should be implicitly castable.

struct Bar{};
struct Foo {
  Foo(const Bar&); // implicit constructor
};
void example(Bar&);
void counterExample(Foo);
// ...
optional<Bar> optBar;
example(optBar); // Would work fine, implicitly castable
counterExample(optBar); // Wouldn't work

The question is why the call to counterExample shouldn't work. The only
purpose of optional<T> is to be a standin for a T, nothing else.


--

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

<div dir=3D"ltr">Consider the upcoming optional&lt;T&gt;. In this particula=
r case it will be rather annoying and painful to always access the object b=
ehind the optional.<br><br><div class=3D"prettyprint" style=3D"background-c=
olor: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: s=
olid; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint=
"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"style=
d-by-prettify">class</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify"=
>Foo</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> call</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">();</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span style=3D"color: =
#606;" class=3D"styled-by-prettify">Foo</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">operator</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">+(</span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">int</span><span style=3D"color: #660;" 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"styled-by-prettify">};</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span><span sty=
le=3D"color: #800;" class=3D"styled-by-prettify">// ...</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>optional</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"=
color: #606;" class=3D"styled-by-prettify">Foo</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> optFoo</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br>optFoo</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">.</span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">get</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">().</span><span style=3D"color: #000;" class=3D"styled-by-prettify">call<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">();</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #800;" class=3D"styled-by-prettify">// Why not optFoo.call()?</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><=
/div></code></div><br>There are two ideas that come to mind:<br><br>1. Add =
a way to make any expression relying on a Foo to be there, also available f=
or an optional&lt;Foo&gt;. You&#39;d have to find a syntax for that and als=
o an implementation for the optional for example<br><br><div class=3D"prett=
yprint" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(18=
7, 187, 187); border-style: solid; border-width: 1px; word-wrap: break-word=
;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D=
"color: #000;" class=3D"styled-by-prettify">optFoo</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">call</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">();</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-p=
rettify">// Returns optional&lt;int&gt;. When optFoo holds a Foo, calls cal=
l() on it and stores the result</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0</span><span style=3D"color: #800;" class=3D"styled-by-prettify">// i=
n an optional. Else, returns an empty optional</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"><br><br>optFoo </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">+</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=
=3D"styled-by-prettify">3</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">// =
Returns optional&lt;Foo&amp;&gt;. Same as above.</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><br>The=
 problem with this approach is that there currently exists no syntax that s=
ays &quot;if it doesn&#39;t work with an optional, try with the Foo it hold=
s, IF it holds any Foo&quot;.<br><br>We&#39;d need a way to allow the optio=
nal to intercept the statement it is used in (to return an empty optional) =
but also execute the statement it is a standin for if there is a value it h=
olds.<br><br>2. Assume the coder knows what he&#39;s doing and call get() i=
nstead. We have to consider that <b>the only purpose of an optional is to h=
old or not hold one specific value.</b> This leads me to the thought that m=
aybe an optional should be implicitly castable.<br><br><div class=3D"pretty=
print" 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 class=3D"prettyprint"><div class=3D"subprettyprint"><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">Bar</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{};</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">struct</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Fo=
o</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 </span><span sty=
le=3D"color: #606;" class=3D"styled-by-prettify">Foo</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">const</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"s=
tyled-by-prettify">Bar</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">&amp;);</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">=
// implicit constructor</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">void</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> example</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span s=
tyle=3D"color: #606;" class=3D"styled-by-prettify">Bar</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">&amp;);</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">void</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> counterExample</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">(</span><span style=3D"color: #606;" clas=
s=3D"styled-by-prettify">Foo</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><span style=3D"color: #800;" class=3D"styled-by-pretti=
fy">// ...</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">Bar<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> optBar</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>example</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">optBar</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=3D"st=
yled-by-prettify">// Would work fine, implicitly castable</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>counterExample</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">optBar</span><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;" cla=
ss=3D"styled-by-prettify">// Wouldn&#39;t work</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"><br></span></div></code></div><br>The q=
uestion is why the call to counterExample shouldn&#39;t work. The only purp=
ose of optional&lt;T&gt; is to be a standin for a T, nothing else.<br><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_3876_540957450.1438227171525--
------=_Part_3875_664483259.1438227171524--

.


Author: Nevin Liber <nevin@eviloverlord.com>
Date: Wed, 29 Jul 2015 23:05:04 -0500
Raw View
--001a11414af441fa5f051c0fd1b9
Content-Type: text/plain; charset=UTF-8

On 29 July 2015 at 22:32, <martin.molzer@gmx.de> wrote:

> optional<Foo> optFoo;
> optFoo.get().call(); // Why not optFoo.call()?
>

Why not optFoo->call(), which already works with
std::experimental::optional?
--
 Nevin ":-)" Liber  <mailto:nevin@eviloverlord.com>  (847) 691-1404

--

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

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

<div dir=3D"ltr">On 29 July 2015 at 22:32,  <span dir=3D"ltr">&lt;<a href=
=3D"mailto:martin.molzer@gmx.de" target=3D"_blank">martin.molzer@gmx.de</a>=
&gt;</span> wrote:<br><div class=3D"gmail_extra"><div class=3D"gmail_quote"=
><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"><div style=3D"background-c=
olor:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;bord=
er-width:1px;word-wrap:break-word"><code><div><span style=3D"color:#000">op=
tional</span><span style=3D"color:#660">&lt;</span><span style=3D"color:#60=
6">Foo</span><span style=3D"color:#660">&gt;</span><span style=3D"color:#00=
0"> optFoo</span><span style=3D"color:#660">;</span><span style=3D"color:#0=
00"><br>optFoo</span><span style=3D"color:#660">.</span><span style=3D"colo=
r:#008">get</span><span style=3D"color:#660">().</span><span style=3D"color=
:#000">call</span><span style=3D"color:#660">();</span><span style=3D"color=
:#000"> </span><span style=3D"color:#800">// Why not optFoo.call()?</span><=
span style=3D"color:#000"><br></span></div></code></div></div></blockquote>=
<div><br></div><div>Why not optFoo-&gt;call(), which already works with std=
::experimental::optional?</div></div>-- <br><div class=3D"gmail_signature">=
=C2=A0Nevin &quot;:-)&quot; Liber=C2=A0 &lt;mailto:<a href=3D"mailto:nevin@=
eviloverlord.com" target=3D"_blank">nevin@eviloverlord.com</a>&gt;=C2=A0 (8=
47) 691-1404</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 />

--001a11414af441fa5f051c0fd1b9--

.


Author: David Krauss <potswa@gmail.com>
Date: Thu, 30 Jul 2015 15:02:33 +0800
Raw View
--Apple-Mail=_10D68CB6-9C83-4BBB-A66F-F2B49FE13D03
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


> On 2015=E2=80=9307=E2=80=9330, at 11:32 AM, martin.molzer@gmx.de wrote:
>=20
> optFoo.get().call(); // Why not optFoo.call()?

Because the optional might be disengaged, there=E2=80=99s an interface desi=
gn decision that optional is not a proxy. It has no implicit conversion ope=
rator.

Things that can fail should not be implicit.

> There are two ideas that come to mind:
>=20
> 1. Add a way to make any expression relying on a Foo to be there, also av=
ailable for an optional<Foo>. You'd have to find a syntax for that and also=
 an implementation for the optional for example

This is the sum of =E2=80=9Coperator dot=E2=80=9D and implicit conversion o=
perators. See the recent discussion in this forum, "Does unified call synta=
x make operator.() unnecessary?=E2=80=9D

The concept you describe is commonly called =E2=80=9Cproxy objects.=E2=80=
=9D

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

--Apple-Mail=_10D68CB6-9C83-4BBB-A66F-F2B49FE13D03
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9307=
=E2=80=9330, at 11:32 AM, <a href=3D"mailto:martin.molzer@gmx.de" class=3D"=
">martin.molzer@gmx.de</a> wrote:</div><br class=3D"Apple-interchange-newli=
ne"><div class=3D""><div class=3D"prettyprint" style=3D"font-family: Helvet=
ica; font-size: 12px; font-style: normal; font-variant: normal; font-weight=
: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-=
align: start; text-indent: 0px; text-transform: none; white-space: normal; =
widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background=
-color: rgb(250, 250, 250); border: 1px solid rgb(187, 187, 187); word-wrap=
: break-word;"><code class=3D"prettyprint">optFoo<span class=3D"styled-by-p=
rettify" style=3D"color: rgb(102, 102, 0);">.</span><span class=3D"styled-b=
y-prettify" style=3D"color: rgb(0, 0, 136);">get</span><span class=3D"style=
d-by-prettify" style=3D"color: rgb(102, 102, 0);">().</span>call<span class=
=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">();</span>&nbsp;=
<span class=3D"styled-by-prettify" style=3D"color: rgb(136, 0, 0);">// Why =
not optFoo.call()?</span><br class=3D""></code></div></div></blockquote><di=
v><br class=3D""></div><div>Because the <font face=3D"Courier" class=3D"">o=
ptional</font> might be disengaged, there=E2=80=99s an interface design dec=
ision that <font face=3D"Courier" class=3D"">optional</font> is not a proxy=
.. It has no implicit conversion operator.</div><div><br class=3D""></div><d=
iv>Things that can fail should not be implicit.</div><br class=3D""><blockq=
uote type=3D"cite" class=3D""><div class=3D""><span style=3D"font-family: H=
elvetica; font-size: 12px; font-style: normal; font-variant: normal; font-w=
eight: normal; letter-spacing: normal; line-height: normal; orphans: auto; =
text-align: start; text-indent: 0px; text-transform: none; white-space: nor=
mal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float=
: none; display: inline !important;" class=3D"">There are two ideas that co=
me to mind:</span><br style=3D"font-family: Helvetica; font-size: 12px; fon=
t-style: normal; font-variant: normal; font-weight: normal; letter-spacing:=
 normal; line-height: normal; orphans: auto; text-align: start; text-indent=
: 0px; text-transform: none; white-space: normal; widows: auto; word-spacin=
g: 0px; -webkit-text-stroke-width: 0px;" class=3D""><br style=3D"font-famil=
y: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; fo=
nt-weight: normal; letter-spacing: normal; line-height: normal; orphans: au=
to; text-align: start; text-indent: 0px; text-transform: none; white-space:=
 normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" =
class=3D""><span style=3D"font-family: Helvetica; font-size: 12px; font-sty=
le: normal; font-variant: normal; font-weight: normal; letter-spacing: norm=
al; line-height: normal; orphans: auto; text-align: start; text-indent: 0px=
; text-transform: none; white-space: normal; widows: auto; word-spacing: 0p=
x; -webkit-text-stroke-width: 0px; float: none; display: inline !important;=
" class=3D"">1. Add a way to make any expression relying on a Foo to be the=
re, also available for an optional&lt;Foo&gt;. You'd have to find a syntax =
for that and also an implementation for the optional for example</span><br =
style=3D"font-family: Helvetica; font-size: 12px; font-style: normal; font-=
variant: normal; font-weight: normal; letter-spacing: normal; line-height: =
normal; orphans: auto; text-align: start; text-indent: 0px; text-transform:=
 none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-s=
troke-width: 0px;" class=3D""></div></blockquote></div><br class=3D""><div =
class=3D"">This is the sum of =E2=80=9Coperator dot=E2=80=9D and implicit c=
onversion operators. See the recent discussion in this forum, "<font face=
=3D"Helvetica Neue" class=3D"">Does unified call syntax make operator.() un=
necessary?=E2=80=9D</font></div><div class=3D""><br class=3D""></div><div c=
lass=3D"">The concept you describe is commonly called =E2=80=9Cproxy object=
s.=E2=80=9D</div><div class=3D""><br class=3D""></div></body></html>

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

--Apple-Mail=_10D68CB6-9C83-4BBB-A66F-F2B49FE13D03--

.


Author: Giovanni Piero Deretta <gpderetta@gmail.com>
Date: Thu, 30 Jul 2015 02:33:36 -0700 (PDT)
Raw View
------=_Part_188_1441816497.1438248816660
Content-Type: multipart/alternative;
 boundary="----=_Part_189_1241351950.1438248816660"

------=_Part_189_1241351950.1438248816660
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Thursday, July 30, 2015 at 8:02:46 AM UTC+1, David Krauss wrote:
>
>
> On 2015=E2=80=9307=E2=80=9330, at 11:32 AM, martin...@gmx.de <javascript:=
> wrote:
>
> optFoo.get().call(); // Why not optFoo.call()?
>
>
> Because the optional might be disengaged, there=E2=80=99s an interface de=
sign=20
> decision that optional is not a proxy. It has no implicit conversion=20
> operator.
>
>
note that the OP proposes that int this should return optional<int>, i.e.=
=20
map any R T::<fun>(...) to optional<R> optional<T>::fun(...). Basically=20
operator. would act as a monadic bind or the proposed future::then.=20

 This is quite a nice idea and probably easily implementable if we get=20
operator. overloading. In addition, if we also get uniform call syntax, it=
=20
could be generalized to free functions in addition to just member=20
functions. In fact such a feature would work great for futures as well.

-- gpd


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

On Thursday, July 30, 2015 at 8:02:46 AM UTC+1, David Krauss wrote:<blockqu=
ote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left=
: 1px #ccc solid;padding-left: 1ex;"><div style=3D"word-wrap:break-word"><b=
r><div><blockquote type=3D"cite"><div>On 2015=E2=80=9307=E2=80=9330, at 11:=
32 AM, <a href=3D"javascript:" target=3D"_blank" rel=3D"nofollow" onmousedo=
wn=3D"this.href=3D&#39;javascript:&#39;;return true;" onclick=3D"this.href=
=3D&#39;javascript:&#39;;return true;">martin...@gmx.de</a> wrote:</div><br=
><div><div style=3D"font-family:Helvetica;font-size:12px;font-style:normal;=
font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:no=
rmal;text-align:start;text-indent:0px;text-transform:none;white-space:norma=
l;word-spacing:0px;background-color:rgb(250,250,250);border:1px solid rgb(1=
87,187,187);word-wrap:break-word"><code>optFoo<span style=3D"color:rgb(102,=
102,0)">.</span><span style=3D"color:rgb(0,0,136)">get</span><span style=3D=
"color:rgb(102,102,0)">().</span>call<span style=3D"color:rgb(102,102,0)">(=
);</span>=C2=A0<span style=3D"color:rgb(136,0,0)">// Why not optFoo.call()?=
</span><br></code></div></div></blockquote><div><br></div><div>Because the =
<font face=3D"Courier">optional</font> might be disengaged, there=E2=80=99s=
 an interface design decision that <font face=3D"Courier">optional</font> i=
s not a proxy. It has no implicit conversion operator.</div><div><br></div>=
</div></div></blockquote><div><br>note that the OP proposes that int this s=
hould return optional&lt;int&gt;, i.e. map any R T::&lt;fun&gt;(...) to opt=
ional&lt;R&gt; optional&lt;T&gt;::fun(...). Basically operator. would act a=
s a monadic bind or the proposed future::then. <br><br>=C2=A0This is quite =
a nice idea and probably easily implementable if we get operator. overloadi=
ng. In addition, if we also get uniform call syntax, it could be generalize=
d to free functions in addition to just member functions. In fact such a fe=
ature would work great for futures as well.<br><br>-- gpd<br></div><br><br>

<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_189_1241351950.1438248816660--
------=_Part_188_1441816497.1438248816660--

.


Author: David Krauss <potswa@gmail.com>
Date: Thu, 30 Jul 2015 18:03:47 +0800
Raw View
--Apple-Mail=_D150976C-18A8-4EAB-AE8C-55774DFE4F8A
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


> On 2015=E2=80=9307=E2=80=9330, at 5:33 PM, Giovanni Piero Deretta <gpdere=
tta@gmail.com> wrote:
>=20
> note that the OP proposes that int this should return optional<int>, i.e.=
 map any R T::<fun>(...) to optional<R> optional<T>::fun(...). Basically op=
erator. would act as a monadic bind or the proposed future::then.=20

That=E2=80=99s beyond the capabilities of the proposed operator dot. I neve=
r saw a proposal for a hook after member name lookup. It sounds like it wou=
ld be pretty complicated in practice =E2=80=94 a recipe for deeply nested o=
ptionals.

On the other hand, you can already do

optFoo? std::experimental::make_optional( optFoo->call() ) : std::experimen=
tal::nullopt

=E2=80=A6 if call() already returns an optional, do not make_optional.

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

--Apple-Mail=_D150976C-18A8-4EAB-AE8C-55774DFE4F8A
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9307=
=E2=80=9330, at 5:33 PM, Giovanni Piero Deretta &lt;<a href=3D"mailto:gpder=
etta@gmail.com" class=3D"">gpderetta@gmail.com</a>&gt; wrote:</div><br clas=
s=3D"Apple-interchange-newline"><div class=3D""><span style=3D"font-family:=
 Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font=
-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto=
; text-align: start; text-indent: 0px; text-transform: none; white-space: n=
ormal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; flo=
at: none; display: inline !important;" class=3D"">note that the OP proposes=
 that int this should return optional&lt;int&gt;, i.e. map any R T::&lt;fun=
&gt;(...) to optional&lt;R&gt; optional&lt;T&gt;::fun(...). Basically opera=
tor. would act as a monadic bind or the proposed future::then.<span class=
=3D"Apple-converted-space">&nbsp;</span></span><br style=3D"font-family: He=
lvetica; font-size: 12px; font-style: normal; font-variant: normal; font-we=
ight: normal; letter-spacing: normal; line-height: normal; orphans: auto; t=
ext-align: start; text-indent: 0px; text-transform: none; white-space: norm=
al; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=
=3D""></div></blockquote></div><br class=3D""><div class=3D"">That=E2=80=99=
s beyond the capabilities of the proposed operator dot. I never saw a propo=
sal for a hook <i class=3D"">after</i>&nbsp;member name lookup. It sounds l=
ike it would be pretty complicated in practice =E2=80=94 a recipe for deepl=
y nested optionals.</div><div class=3D""><br class=3D""></div><div class=3D=
"">On the other hand, you can already do</div><div class=3D""><br class=3D"=
"></div><div class=3D""><font face=3D"Courier" class=3D"">optFoo? std::expe=
rimental::make_optional( optFoo-&gt;call() ) : std::experimental::nullopt</=
font></div><div class=3D""><br class=3D""></div><div class=3D"">=E2=80=A6 i=
f <font face=3D"Courier" class=3D"">call()</font> already returns an option=
al, do not <font face=3D"Courier" class=3D"">make_optional</font>.</div><di=
v class=3D""><br class=3D""></div></body></html>

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

--Apple-Mail=_D150976C-18A8-4EAB-AE8C-55774DFE4F8A--

.


Author: Giovanni Piero Deretta <gpderetta@gmail.com>
Date: Thu, 30 Jul 2015 03:22:53 -0700 (PDT)
Raw View
------=_Part_6527_1473444694.1438251773251
Content-Type: multipart/alternative;
 boundary="----=_Part_6528_1698188510.1438251773251"

------=_Part_6528_1698188510.1438251773251
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable


On Thursday, July 30, 2015 at 11:03:55 AM UTC+1, David Krauss wrote:
>
>
> On 2015=E2=80=9307=E2=80=9330, at 5:33 PM, Giovanni Piero Deretta <gpde..=
..@gmail.com=20
> <javascript:>> wrote:
>
> note that the OP proposes that int this should return optional<int>, i.e.=
=20
> map any R T::<fun>(...) to optional<R> optional<T>::fun(...). Basically=
=20
> operator. would act as a monadic bind or the proposed future::then.=20
>
>
> That=E2=80=99s beyond the capabilities of the proposed operator dot. I ne=
ver saw a=20
> proposal for a hook *after* member name lookup.
>

n4477 does not have this capability. n4495 does. It seems a pretty basic=20
requirement for proxying remote objects (an explicit use case of operator.=
=20
overloading): you will likely want to map any method call to an=20
asynchronous operation returning a future.
=20

> It sounds like it would be pretty complicated in practice =E2=80=94 a rec=
ipe for=20
> deeply nested optionals.
>

the solution is optional collapsing, same as nested future collapsing.
=20

>
> On the other hand, you can already do
>
> optFoo? std::experimental::make_optional( optFoo->call() ) :=20
> std::experimental::nullopt
>
> =E2=80=A6 if call() already returns an optional, do not make_optional.
>

yes, of course it is syntactic sugar, it is just very convenient syntactic=
=20
sugar.

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

<br>On Thursday, July 30, 2015 at 11:03:55 AM UTC+1, David Krauss wrote:<bl=
ockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border=
-left: 1px #ccc solid;padding-left: 1ex;"><div style=3D"word-wrap:break-wor=
d"><br><div><blockquote type=3D"cite"><div>On 2015=E2=80=9307=E2=80=9330, a=
t 5:33 PM, Giovanni Piero Deretta &lt;<a href=3D"javascript:" target=3D"_bl=
ank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:&#39;;retu=
rn true;" onclick=3D"this.href=3D&#39;javascript:&#39;;return true;">gpde..=
..@gmail.com</a>&gt; wrote:</div><br><div><span style=3D"font-family:Helveti=
ca;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;=
letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;t=
ext-transform:none;white-space:normal;word-spacing:0px;float:none;display:i=
nline!important">note that the OP proposes that int this should return opti=
onal&lt;int&gt;, i.e. map any R T::&lt;fun&gt;(...) to optional&lt;R&gt; op=
tional&lt;T&gt;::fun(...). Basically operator. would act as a monadic bind =
or the proposed future::then.<span>=C2=A0</span></span><br style=3D"font-fa=
mily:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-we=
ight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-=
indent:0px;text-transform:none;white-space:normal;word-spacing:0px"></div><=
/blockquote></div><br><div>That=E2=80=99s beyond the capabilities of the pr=
oposed operator dot. I never saw a proposal for a hook <i>after</i>=C2=A0me=
mber name lookup.</div></div></blockquote><div><br>n4477 does not have this=
 capability. n4495 does. It seems a pretty basic requirement for proxying r=
emote objects (an explicit use case of operator. overloading): you will lik=
ely want to map any method call to an asynchronous operation returning a fu=
ture.<br>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div styl=
e=3D"word-wrap:break-word"><div> It sounds like it would be pretty complica=
ted in practice =E2=80=94 a recipe for deeply nested optionals.</div></div>=
</blockquote><div><br>the solution is optional collapsing, same as nested f=
uture collapsing.<br>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D=
"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex=
;"><div style=3D"word-wrap:break-word"><div><br></div><div>On the other han=
d, you can already do</div><div><br></div><div><font face=3D"Courier">optFo=
o? std::experimental::make_optional( optFoo-&gt;call() ) : std::experimenta=
l::nullopt</font></div><div><br></div><div>=E2=80=A6 if <font face=3D"Couri=
er">call()</font> already returns an optional, do not <font face=3D"Courier=
">make_optional</font>.</div></div></blockquote><div><br>yes, of course it =
is syntactic sugar, it is just very convenient syntactic sugar.<br><br>-- g=
pd<br>=C2=A0</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_6528_1698188510.1438251773251--
------=_Part_6527_1473444694.1438251773251--

.


Author: Tony V E <tvaneerd@gmail.com>
Date: Thu, 30 Jul 2015 09:39:44 -0400
Raw View
--089e0160bdaa101332051c17d637
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Thu, Jul 30, 2015 at 6:03 AM, David Krauss <potswa@gmail.com> wrote:

>
> On 2015=E2=80=9307=E2=80=9330, at 5:33 PM, Giovanni Piero Deretta <gpdere=
tta@gmail.com>
> wrote:
>
> note that the OP proposes that int this should return optional<int>, i.e.
> map any R T::<fun>(...) to optional<R> optional<T>::fun(...). Basically
> operator. would act as a monadic bind or the proposed future::then.
>
>
> That=E2=80=99s beyond the capabilities of the proposed operator dot. I ne=
ver saw a
> proposal for a hook *after* member name lookup. It sounds like it would
> be pretty complicated in practice =E2=80=94 a recipe for deeply nested op=
tionals.
>
> On the other hand, you can already do
>
> optFoo? std::experimental::make_optional( optFoo->call() ) :
> std::experimental::nullopt
>
> =E2=80=A6 if call() already returns an optional, do not make_optional.
>
>

People familiar with functional languages will probably be surprised
optional<> does NOT work that way.  Monadic bind just makes sense for
optional.  But I didn't want to push on optional more than I already have.
:-)

Tony

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

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

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><div class=3D"gmail_quo=
te">On Thu, Jul 30, 2015 at 6:03 AM, David Krauss <span dir=3D"ltr">&lt;<a =
href=3D"mailto:potswa@gmail.com" target=3D"_blank">potswa@gmail.com</a>&gt;=
</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .=
8ex;border-left:1px #ccc solid;padding-left:1ex"><div style=3D"word-wrap:br=
eak-word"><span class=3D""><br><div><blockquote type=3D"cite"><div>On 2015=
=E2=80=9307=E2=80=9330, at 5:33 PM, Giovanni Piero Deretta &lt;<a href=3D"m=
ailto:gpderetta@gmail.com" target=3D"_blank">gpderetta@gmail.com</a>&gt; wr=
ote:</div><br><div><span style=3D"font-family:Helvetica;font-size:12px;font=
-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;=
line-height:normal;text-align:start;text-indent:0px;text-transform:none;whi=
te-space:normal;word-spacing:0px;float:none;display:inline!important">note =
that the OP proposes that int this should return optional&lt;int&gt;, i.e. =
map any R T::&lt;fun&gt;(...) to optional&lt;R&gt; optional&lt;T&gt;::fun(.=
...). Basically operator. would act as a monadic bind or the proposed future=
::then.<span>=C2=A0</span></span><br style=3D"font-family:Helvetica;font-si=
ze:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spa=
cing:normal;line-height:normal;text-align:start;text-indent:0px;text-transf=
orm:none;white-space:normal;word-spacing:0px"></div></blockquote></div><br>=
</span><div>That=E2=80=99s beyond the capabilities of the proposed operator=
 dot. I never saw a proposal for a hook <i>after</i>=C2=A0member name looku=
p. It sounds like it would be pretty complicated in practice =E2=80=94 a re=
cipe for deeply nested optionals.</div><div><br></div><div>On the other han=
d, you can already do</div><div><br></div><div><font face=3D"Courier">optFo=
o? std::experimental::make_optional( optFoo-&gt;call() ) : std::experimenta=
l::nullopt</font></div><div><br></div><div>=E2=80=A6 if <font face=3D"Couri=
er">call()</font> already returns an optional, do not <font face=3D"Courier=
">make_optional</font>.</div><div><br></div></div></blockquote><div><br></d=
iv></div><br></div><div class=3D"gmail_extra">People familiar with function=
al languages will probably be surprised optional&lt;&gt; does NOT work that=
 way.=C2=A0 Monadic bind just makes sense for optional.=C2=A0 But I didn&#3=
9;t want to push on optional more than I already have. :-)<br><br></div><di=
v class=3D"gmail_extra">Tony<br><br></div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&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 />

--089e0160bdaa101332051c17d637--

.


Author: martin.molzer@gmx.de
Date: Thu, 30 Jul 2015 08:02:07 -0700 (PDT)
Raw View
------=_Part_6437_1510485176.1438268527560
Content-Type: multipart/alternative;
 boundary="----=_Part_6438_1028811024.1438268527561"

------=_Part_6438_1028811024.1438268527561
Content-Type: text/plain; charset=UTF-8

I can think of a third alternative. We can provide two more methods for the
optional: __member_access (name up to discussion) and operator ().

First, some utility:

template<typename T>
struct optional_collapse {
    typedef optional<T> type;
};

template<typename T>
struct optional_collapse<optional<T>> {
    typedef typename optional_collapse<T>::type type;
};

template<typename T>
using optional_collapse_t = typename optional_collapse<T>::type;

// Now, for the __member_access (incomplete implementation)

template<typename Q, typename T>
auto optional<T>::__member_access(Q T::*member)
-> optional_collapse_t<declval<T>.*member>
{
    typedef optional_collapse_t<declval<T>.*member> optional_ret;
    if(!*this) {
        return optional_ret{}; // An empty optional
    }
    return optional_ret{value().*member};
}
// Missing specialization for member functions

It should return an enagaged optional with a reference to the member if the
optional __member_access was called on was engaged, and an empty optional
otherwise. If the member is a function, an optional</* unspecified */>
should be returned, which is bind(mem_fn(member), value()).

Now, for some more utility, it makes sense to introduce an operator() to
the optional:

template<typename T, typename Args...>
auto optional<T>::operator ()(Args&&... args)
-> optional_collapse_t<result_of<T(forward<Args>(args)...)>>
{
    typedef optional_collapse_t<result_of<T(forward<Args>...)>> optional_ret
;
    if(!*this) {
        return optional_ret{};
    }
    return optional_ret{value()(forward<Args>(args)...)};
}

This makes things easier when coding with optionals, as you can almost code
as if you had the object, but it is safe not to have it, with the result
being an empty optional.

--

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

<div dir=3D"ltr">I can think of a third alternative. We can provide two mor=
e methods for the optional: __member_access (name up to discussion) and ope=
rator ().<br><br>First, some utility:<br><br><div class=3D"prettyprint" sty=
le=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187=
); border-style: solid; border-width: 1px; word-wrap: break-word;"><code cl=
ass=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">template</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> T</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></span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">struct</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 optional_collapse </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">typedef</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> optional</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&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"styled-by-prettify"> type</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> =C2=A0 =C2=A0<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></span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">template</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">typename</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"st=
yled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">struct</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> optional_collapse</span><span style=3D"color: #660;" class=3D"styl=
ed-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-pr=
ettify">&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;&gt=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">typedef</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> optional_collapse</span><span st=
yle=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"styled-by-prettify">type type</span><span style=3D"color: #660;"=
 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"style=
d-by-prettify">};</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br><br></span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">template</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">typ=
ename</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</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"><br></span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">using</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> optional_collapse_t </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> optional_collapse</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">&gt;::</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">type</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br><br></span><span style=3D"color: #800;" class=3D"styled-=
by-prettify">// Now, for the __member_access (incomplete implementation)</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">template</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 st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> Q</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> T</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></span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> o=
ptional</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"styled-by-prettify">__member_access</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">Q T</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">::*</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify">member</span><span style=3D"color: #660;=
" 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">-&gt;</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> optional_collapse_t</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">declval</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
&gt;.*</span><span style=3D"color: #000;" class=3D"styled-by-prettify">memb=
er</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">typedef</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> optional_collapse_t</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">declval</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: #0=
00;" class=3D"styled-by-prettify">member</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> optional_ret</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">if</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">(!*</span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">this</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>return</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> op=
tional_ret</span><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">// An empty opti=
onal</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">return</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 optional_ret</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">{</span><span style=3D"color: #000;" class=3D"styled-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">member</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><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #800;" cla=
ss=3D"styled-by-prettify">// Missing specialization for member functions</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></=
div></code></div><br>It should return an enagaged optional with a reference=
 to the member if the optional __member_access was called on was engaged, a=
nd an empty optional otherwise. If the member is a function, an optional&lt=
;/* unspecified */&gt; should be returned, which is bind(mem_fn(member), va=
lue()).<br><br>Now, for some more utility, it makes sense to introduce an o=
perator() to the optional:<br><div class=3D"prettyprint" style=3D"backgroun=
d-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style=
: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"prettypr=
int"><div class=3D"subprettyprint"><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">template</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">typename</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> T</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: #008;" class=3D"styled-by-prettify">typename</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #606;" class=3D"styled-by-prettify">Args</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">...&gt;</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> optional</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">T</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&gt;::</span><span style=3D"color: #008;" class=3D"styled-by-prettify">o=
perator</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">()(</span><s=
pan style=3D"color: #606;" class=3D"styled-by-prettify">Args</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">&amp;&amp;...</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> args</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">-&gt;</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> optional_collapse_t</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">result_of</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">T</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">forward</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&lt;</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Ar=
gs</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;(</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">args</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">)...)&gt;&gt;</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>=C2=A0 =C2=A0 </span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">typedef</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> optional_collapse_t</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify">result_of</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">(</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">forward</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">&lt;</span><span style=3D"color: #606;" class=3D"=
styled-by-prettify">Args</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">&gt;...)&gt;&gt;</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> optional_ret</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">if</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">(!*</span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">this</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0=
 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">re=
turn</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> optio=
nal_ret</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{};=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0=
 =C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">ret=
urn</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> option=
al_ret</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">value</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">()(</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">forward</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #606;" class=3D"styled-by-prettify">Args</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&gt;(</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify">args</span><span style=3D"color: #660;" 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"style=
d-by-prettify">}</span></div></code></div><br>This makes things easier when=
 coding with optionals, as you can almost code as if you had the object, bu=
t it is safe not to have it, with the result being an empty optional.<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_6438_1028811024.1438268527561--
------=_Part_6437_1510485176.1438268527560--

.