Topic: Convert a variant into an optional?


Author: tortoise741@gmail.com
Date: Tue, 15 May 2018 08:39:10 -0700 (PDT)
Raw View
------=_Part_31706_542821505.1526398750211
Content-Type: multipart/alternative;
 boundary="----=_Part_31707_2063493414.1526398750211"

------=_Part_31707_2063493414.1526398750211
Content-Type: text/plain; charset="UTF-8"

Hi,
    Apologies if this has been asked before. variant and optional are quite
common search terms.

    I'm wondering if there is, or should be a standard way to convert a
variant into an optional?
Or if its a bad idea why there shouldn't be.

Consider the following example. Imagine Foo is an object representing a
configuration.
One part of the configuration bar has two possible modes of operation one
requires one piece of configuration
and one requires the other but it is not valid to specify both.

#include <variant>
#include <optional>

class Foo
{
private:
    std::variant<int, std::string> bar;
public:
    Foo(int a): bar(a) {}
    Foo(const std::string& b): bar(b) {}

    std::optional<int> getInt() const
    {
        std::optional<int> ret;
        auto got = std::get_if<int>(&this->bar);
        if (got) ret = *got;
        return ret;
    }

    std::optional<std::string> getString() const
    {
        std::optional<std::string> ret;
        auto got = std::get_if<std::string>(&this->bar);
        if (got) ret = *got;
        return ret;
    }
};

There seems to be a lot of boilerplate to convert the variant into a
optional for the return.
There is an inefficiency here in that the type contained has to be checked
twice to use this.

There are other ways to do this. You can expose the variant member and use
a visitor
but using a visitor feels like overkill for this. Also the variant is an
internal implementation detail.
An equally valid implementation would have two different optional members
(but would not enforce their mutual exclusivity).

So do we need (or is there already) something kind of like:

    std::optional<std::string> getString() const
    {
        return make_optional<std::string>(this->bar);
    }

or bikeshedding:

    std::optional<std::string> getString() const
    {
        return to_optional<std::string>(this->bar);
    }


Regards,

Bruce.

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/1c089cc9-4f8a-4778-b92b-2d3b95b211e1%40isocpp.org.

------=_Part_31707_2063493414.1526398750211
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi,<br>=C2=A0=C2=A0=C2=A0 Apologies if this has been asked=
 before. variant and optional are quite common search terms.<br><br>=C2=A0=
=C2=A0=C2=A0 I&#39;m wondering if there is, or should be a standard way to =
convert a variant into an optional?<br>Or if its a bad idea why there shoul=
dn&#39;t be.<br><br>Consider the following example. Imagine Foo is an objec=
t representing a configuration.<br>One part of the configuration bar has tw=
o possible modes of operation one requires one piece of configuration<br>an=
d one requires the other but it is not valid to specify both.<br><br>#inclu=
de &lt;variant&gt;<br>#include &lt;optional&gt;<br><br>class Foo<br>{<br>pr=
ivate:<br>=C2=A0=C2=A0=C2=A0 std::variant&lt;int, std::string&gt; bar;<br>p=
ublic:<br>=C2=A0=C2=A0=C2=A0 Foo(int a): bar(a) {}<br>=C2=A0=C2=A0=C2=A0 Fo=
o(const std::string&amp; b): bar(b) {}<br><br>=C2=A0=C2=A0=C2=A0 std::optio=
nal&lt;int&gt; getInt() const<br>=C2=A0=C2=A0=C2=A0 {<br>=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0 std::optional&lt;int&gt; ret;<br>=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto got =3D std::get_if&lt;int&gt;(&amp;this-&=
gt;bar);<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (got) ret =3D *go=
t;<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return ret;<br>=C2=A0=C2=
=A0=C2=A0 }<br><br>=C2=A0=C2=A0=C2=A0 std::optional&lt;std::string&gt; getS=
tring() const<br>=C2=A0=C2=A0=C2=A0 {<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 std::optional&lt;std::string&gt; ret;<br>=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 auto got =3D std::get_if&lt;std::string&gt;(&amp;this-&g=
t;bar);<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (got) ret =3D *got=
;<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return ret;<br>=C2=A0=C2=A0=
=C2=A0 }<br>};<br><br>There seems to be a lot of boilerplate to convert the=
 variant into a optional for the return.<br>There is an inefficiency here i=
n that the type contained has to be checked twice to use this.<br><br>There=
 are other ways to do this. You can expose the variant member and use a vis=
itor<br>but using a visitor feels like overkill for this. Also the variant =
is an internal implementation detail.<br>An equally valid implementation wo=
uld have two different optional members (but would not enforce their mutual=
 exclusivity).<br><br>So do we need (or is there already) something kind of=
 like:<br><br>=C2=A0=C2=A0=C2=A0 std::optional&lt;std::string&gt; getString=
() const<br>=C2=A0=C2=A0=C2=A0 {<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0 return make_optional&lt;std::string&gt;(this-&gt;bar);<br>=C2=A0=C2=A0=
=C2=A0 }<br><br>or bikeshedding:<br><br>=C2=A0=C2=A0=C2=A0 std::optional&lt=
;std::string&gt; getString() const<br>=C2=A0=C2=A0=C2=A0 {<br>=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return to_optional&lt;std::string&gt;(this-&=
gt;bar);<br>=C2=A0=C2=A0=C2=A0 }<br><br><br>Regards,<br><br>Bruce.<br></div=
>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/1c089cc9-4f8a-4778-b92b-2d3b95b211e1%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/1c089cc9-4f8a-4778-b92b-2d3b95b211e1=
%40isocpp.org</a>.<br />

------=_Part_31707_2063493414.1526398750211--

------=_Part_31706_542821505.1526398750211--

.


Author: Barry Revzin <barry.revzin@gmail.com>
Date: Tue, 15 May 2018 08:57:50 -0700 (PDT)
Raw View
------=_Part_31752_640190503.1526399870280
Content-Type: multipart/alternative;
 boundary="----=_Part_31753_2038951799.1526399870281"

------=_Part_31753_2038951799.1526399870281
Content-Type: text/plain; charset="UTF-8"



On Tuesday, May 15, 2018 at 10:39:10 AM UTC-5, Bruce Adams wrote:
>
> Hi,
>     Apologies if this has been asked before. variant and optional are
> quite common search terms.
>
>     I'm wondering if there is, or should be a standard way to convert a
> variant into an optional?
> Or if its a bad idea why there shouldn't be.
>

Well, one problem is that you have to copy because there's no optional
reference. Some people would say the T* you get back from get_if() is
already kind of optional? But in any case, this is really straightforward
to implement yourself, so is it sufficiently common that everyone will
re-implement themselves?

template <typename T>
auto ptr_to_optional(T* ptr) {
    return ptr ? optional<remove_cv_t<T>>(*ptr) : nullopt;
}

template <typename T, typename ...Types>
constexpr auto variant_to_optional(variant<Types...> const& v) noexcept {
    return ptr_to_optional(get_if<T>(&v));
}

template <size_t I, typename ...Types>
constexpr auto variant_to_optional(variant<Types...> const& v) noexcept {
    return ptr_to_optional(get_if<I>(&v));
}

 +/- typos, naming choice, etc.

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/cd369c5c-cb53-4223-83cc-bb0497448e79%40isocpp.org.

------=_Part_31753_2038951799.1526399870281
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Tuesday, May 15, 2018 at 10:39:10 AM UTC-5, Bru=
ce Adams wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-=
left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr=
">Hi,<br>=C2=A0=C2=A0=C2=A0 Apologies if this has been asked before. varian=
t and optional are quite common search terms.<br><br>=C2=A0=C2=A0=C2=A0 I&#=
39;m wondering if there is, or should be a standard way to convert a varian=
t into an optional?<br>Or if its a bad idea why there shouldn&#39;t be.<br>=
</div></blockquote><div><br></div><div>Well, one problem is that you have t=
o copy because there&#39;s no optional reference. Some people would say the=
 T* you get back from get_if() is already kind of optional? But in any case=
, this is really straightforward to implement yourself, so is it sufficient=
ly common that everyone will re-implement themselves?</div><div><br></div><=
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 class=3D"prettyprint"><div class=3D"subpret=
typrint"><span style=3D"color: #008;" class=3D"styled-by-prettify">template=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">typename</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> ptr_to_optional</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">T</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">*</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> ptr</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n 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">return</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> ptr </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">remove_cv_t</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">T</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">&gt;&gt;(*</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">ptr</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: #660;" class=3D"styled-by-prettify">:</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> nullopt</span><s=
pan 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><br></span><span style=3D"color: #008;"=
 class=3D"styled-by-prettify">template</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"s=
tyled-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"> T</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: #008;" class=3D"styled-by-prettify">typename</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">...</span><span style=3D"c=
olor: #606;" class=3D"styled-by-prettify">Types</span><span style=3D"color:=
 #660;" 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">constexpr</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> variant_to_optional</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">variant</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">&lt;</span><span style=3D"color: #606;" class=3D"styled-by-prettify"=
>Types</span><span style=3D"color: #660;" class=3D"styled-by-prettify">...&=
gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> v</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> noexcept </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><font color=3D"#000088"><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">return</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span></font><span st=
yle=3D"color: rgb(0, 0, 0);"><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">ptr_to_optional</span></span><font color=3D"#000088"><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">(</span></font><span style=
=3D"color: #000;" class=3D"styled-by-prettify">get_if</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;" c=
lass=3D"styled-by-prettify">&gt;(&amp;</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">v</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">));</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">templ=
ate</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><font=
 color=3D"#000088"><span style=3D"color: #000;" class=3D"styled-by-prettify=
">size_t I</span></font><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">typename</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">...</span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Types</span><font color=3D"#=
666600"><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</spa=
n></font><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">constexpr</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> variant_to_optional</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">variant</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #606;" class=3D"styled-by-prettify">Types</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">...&gt;</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">const</span><span style=3D"color: #660;" class=3D"s=
tyled-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-pret=
tify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> no=
except </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><font color=3D"#000088"><span style=3D"color: #008;" class=3D=
"styled-by-prettify">return</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span></font><span style=3D"color: rgb(0, 0, 0);"><span =
style=3D"color: #000;" class=3D"styled-by-prettify">ptr_to_optional</span><=
/span><font color=3D"#000088"><span style=3D"color: #660;" class=3D"styled-=
by-prettify">(</span></font><span style=3D"color: #000;" class=3D"styled-by=
-prettify">get_if</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>I</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;(&am=
p;</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 s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">}</span><font color=3D"#0000=
00"><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></=
font></div></code></div><br>=C2=A0+/- typos, naming choice, etc.</div></div=
>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/cd369c5c-cb53-4223-83cc-bb0497448e79%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/cd369c5c-cb53-4223-83cc-bb0497448e79=
%40isocpp.org</a>.<br />

------=_Part_31753_2038951799.1526399870281--

------=_Part_31752_640190503.1526399870280--

.


Author: Richard Hodges <hodges.r@gmail.com>
Date: Tue, 15 May 2018 20:42:37 +0200
Raw View
--0000000000000e2af7056c42f872
Content-Type: text/plain; charset="UTF-8"

> Well, one problem is that you have to copy because there's no optional
reference

What on earth possessed the committee to come to the conclusion that this
was a good idea?

boost::optional of course has optional references. So once again, in
reality, boost will remain the standard - while the official standard
remains a useless artefact.

Another shameful failure.


On Tue, 15 May 2018 at 17:57, Barry Revzin <barry.revzin@gmail.com> wrote:

>
>
> On Tuesday, May 15, 2018 at 10:39:10 AM UTC-5, Bruce Adams wrote:
>>
>> Hi,
>>     Apologies if this has been asked before. variant and optional are
>> quite common search terms.
>>
>>     I'm wondering if there is, or should be a standard way to convert a
>> variant into an optional?
>> Or if its a bad idea why there shouldn't be.
>>
>
> Well, one problem is that you have to copy because there's no optional
> reference. Some people would say the T* you get back from get_if() is
> already kind of optional? But in any case, this is really straightforward
> to implement yourself, so is it sufficiently common that everyone will
> re-implement themselves?
>
> template <typename T>
> auto ptr_to_optional(T* ptr) {
>     return ptr ? optional<remove_cv_t<T>>(*ptr) : nullopt;
> }
>
> template <typename T, typename ...Types>
> constexpr auto variant_to_optional(variant<Types...> const& v) noexcept {
>     return ptr_to_optional(get_if<T>(&v));
> }
>
> template <size_t I, typename ...Types>
> constexpr auto variant_to_optional(variant<Types...> const& v) noexcept {
>     return ptr_to_optional(get_if<I>(&v));
> }
>
>  +/- typos, naming choice, etc.
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/cd369c5c-cb53-4223-83cc-bb0497448e79%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/cd369c5c-cb53-4223-83cc-bb0497448e79%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CALvx3hZHHJ4VyZUVNZ5_e1qbEO1UQUD8r4iA6tjUkKTeEvbAZA%40mail.gmail.com.

--0000000000000e2af7056c42f872
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">&gt;=C2=A0<span style=3D"color:rgb(34,34,34);font-family:s=
ans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;fo=
nt-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:sta=
rt;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;=
background-color:rgb(255,255,255);text-decoration-style:initial;text-decora=
tion-color:initial;float:none;display:inline">Well, one problem is that you=
 have to copy because there&#39;s no optional reference</span><div><span st=
yle=3D"color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style=
:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:=
400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:n=
one;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);t=
ext-decoration-style:initial;text-decoration-color:initial;float:none;displ=
ay:inline"><br></span></div><div><span style=3D"color:rgb(34,34,34);font-fa=
mily:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:nor=
mal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-ali=
gn:start;text-indent:0px;text-transform:none;white-space:normal;word-spacin=
g:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-=
decoration-color:initial;float:none;display:inline">What on earth possessed=
 the committee to come to the conclusion that this was a good idea?</span><=
/div><div><span style=3D"color:rgb(34,34,34);font-family:sans-serif;font-si=
ze:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:n=
ormal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0p=
x;text-transform:none;white-space:normal;word-spacing:0px;background-color:=
rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initia=
l;float:none;display:inline"><br></span></div><div><span style=3D"color:rgb=
(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-var=
iant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spaci=
ng:normal;text-align:start;text-indent:0px;text-transform:none;white-space:=
normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-s=
tyle:initial;text-decoration-color:initial;float:none;display:inline">boost=
::optional of course has optional references. So once again, in reality, bo=
ost will remain the standard - while the official standard remains a useles=
s artefact.</span></div><div><br></div><div>Another shameful failure.</div>=
<div><br></div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Tue=
, 15 May 2018 at 17:57, Barry Revzin &lt;<a href=3D"mailto:barry.revzin@gma=
il.com">barry.revzin@gmail.com</a>&gt; wrote:<br></div><blockquote class=3D=
"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding=
-left:1ex"><div dir=3D"ltr"><br><br>On Tuesday, May 15, 2018 at 10:39:10 AM=
 UTC-5, Bruce Adams wrote:<blockquote class=3D"gmail_quote" style=3D"margin=
:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=
=3D"ltr">Hi,<br>=C2=A0=C2=A0=C2=A0 Apologies if this has been asked before.=
 variant and optional are quite common search terms.<br><br>=C2=A0=C2=A0=C2=
=A0 I&#39;m wondering if there is, or should be a standard way to convert a=
 variant into an optional?<br>Or if its a bad idea why there shouldn&#39;t =
be.<br></div></blockquote><div><br></div><div>Well, one problem is that you=
 have to copy because there&#39;s no optional reference. Some people would =
say the T* you get back from get_if() is already kind of optional? But in a=
ny case, this is really straightforward to implement yourself, so is it suf=
ficiently common that everyone will re-implement themselves?</div><div><br>=
</div><div><div class=3D"m_7787654561999999832prettyprint" style=3D"backgro=
und-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid=
;border-width:1px;word-wrap:break-word"><code class=3D"m_778765456199999983=
2prettyprint"><div class=3D"m_7787654561999999832subprettyprint"><span styl=
e=3D"color:#008" class=3D"m_7787654561999999832styled-by-prettify">template=
</span><span style=3D"color:#000" class=3D"m_7787654561999999832styled-by-p=
rettify"> </span><span style=3D"color:#660" class=3D"m_7787654561999999832s=
tyled-by-prettify">&lt;</span><span style=3D"color:#008" class=3D"m_7787654=
561999999832styled-by-prettify">typename</span><span style=3D"color:#000" c=
lass=3D"m_7787654561999999832styled-by-prettify"> T</span><span style=3D"co=
lor:#660" class=3D"m_7787654561999999832styled-by-prettify">&gt;</span><spa=
n style=3D"color:#000" class=3D"m_7787654561999999832styled-by-prettify"><b=
r></span><span style=3D"color:#008" class=3D"m_7787654561999999832styled-by=
-prettify">auto</span><span style=3D"color:#000" class=3D"m_778765456199999=
9832styled-by-prettify"> ptr_to_optional</span><span style=3D"color:#660" c=
lass=3D"m_7787654561999999832styled-by-prettify">(</span><span style=3D"col=
or:#000" class=3D"m_7787654561999999832styled-by-prettify">T</span><span st=
yle=3D"color:#660" class=3D"m_7787654561999999832styled-by-prettify">*</spa=
n><span style=3D"color:#000" class=3D"m_7787654561999999832styled-by-pretti=
fy"> ptr</span><span style=3D"color:#660" class=3D"m_7787654561999999832sty=
led-by-prettify">)</span><span style=3D"color:#000" class=3D"m_778765456199=
9999832styled-by-prettify"> </span><span style=3D"color:#660" class=3D"m_77=
87654561999999832styled-by-prettify">{</span><span style=3D"color:#000" cla=
ss=3D"m_7787654561999999832styled-by-prettify"><br>=C2=A0 =C2=A0 </span><sp=
an style=3D"color:#008" class=3D"m_7787654561999999832styled-by-prettify">r=
eturn</span><span style=3D"color:#000" class=3D"m_7787654561999999832styled=
-by-prettify"> ptr </span><span style=3D"color:#660" class=3D"m_77876545619=
99999832styled-by-prettify">?</span><span style=3D"color:#000" class=3D"m_7=
787654561999999832styled-by-prettify"> optional</span><span style=3D"color:=
#660" class=3D"m_7787654561999999832styled-by-prettify">&lt;</span><span st=
yle=3D"color:#000" class=3D"m_7787654561999999832styled-by-prettify">remove=
_cv_t</span><span style=3D"color:#660" class=3D"m_7787654561999999832styled=
-by-prettify">&lt;</span><span style=3D"color:#000" class=3D"m_778765456199=
9999832styled-by-prettify">T</span><span style=3D"color:#660" class=3D"m_77=
87654561999999832styled-by-prettify">&gt;&gt;(*</span><span style=3D"color:=
#000" class=3D"m_7787654561999999832styled-by-prettify">ptr</span><span sty=
le=3D"color:#660" class=3D"m_7787654561999999832styled-by-prettify">)</span=
><span style=3D"color:#000" class=3D"m_7787654561999999832styled-by-prettif=
y"> </span><span style=3D"color:#660" class=3D"m_7787654561999999832styled-=
by-prettify">:</span><span style=3D"color:#000" class=3D"m_7787654561999999=
832styled-by-prettify"> nullopt</span><span style=3D"color:#660" class=3D"m=
_7787654561999999832styled-by-prettify">;</span><span style=3D"color:#000" =
class=3D"m_7787654561999999832styled-by-prettify"><br></span><span style=3D=
"color:#660" class=3D"m_7787654561999999832styled-by-prettify">}</span><spa=
n style=3D"color:#000" class=3D"m_7787654561999999832styled-by-prettify"><b=
r><br></span><span style=3D"color:#008" class=3D"m_7787654561999999832style=
d-by-prettify">template</span><span style=3D"color:#000" class=3D"m_7787654=
561999999832styled-by-prettify"> </span><span style=3D"color:#660" class=3D=
"m_7787654561999999832styled-by-prettify">&lt;</span><span style=3D"color:#=
008" class=3D"m_7787654561999999832styled-by-prettify">typename</span><span=
 style=3D"color:#000" class=3D"m_7787654561999999832styled-by-prettify"> T<=
/span><span style=3D"color:#660" class=3D"m_7787654561999999832styled-by-pr=
ettify">,</span><span style=3D"color:#000" class=3D"m_7787654561999999832st=
yled-by-prettify"> </span><span style=3D"color:#008" class=3D"m_77876545619=
99999832styled-by-prettify">typename</span><span style=3D"color:#000" class=
=3D"m_7787654561999999832styled-by-prettify"> </span><span style=3D"color:#=
660" class=3D"m_7787654561999999832styled-by-prettify">...</span><span styl=
e=3D"color:#606" class=3D"m_7787654561999999832styled-by-prettify">Types</s=
pan><span style=3D"color:#660" class=3D"m_7787654561999999832styled-by-pret=
tify">&gt;</span><span style=3D"color:#000" class=3D"m_7787654561999999832s=
tyled-by-prettify"><br></span><span style=3D"color:#008" class=3D"m_7787654=
561999999832styled-by-prettify">constexpr</span><span style=3D"color:#000" =
class=3D"m_7787654561999999832styled-by-prettify"> </span><span style=3D"co=
lor:#008" class=3D"m_7787654561999999832styled-by-prettify">auto</span><spa=
n style=3D"color:#000" class=3D"m_7787654561999999832styled-by-prettify"> v=
ariant_to_optional</span><span style=3D"color:#660" class=3D"m_778765456199=
9999832styled-by-prettify">(</span><span style=3D"color:#000" class=3D"m_77=
87654561999999832styled-by-prettify">variant</span><span style=3D"color:#66=
0" class=3D"m_7787654561999999832styled-by-prettify">&lt;</span><span style=
=3D"color:#606" class=3D"m_7787654561999999832styled-by-prettify">Types</sp=
an><span style=3D"color:#660" class=3D"m_7787654561999999832styled-by-prett=
ify">...&gt;</span><span style=3D"color:#000" class=3D"m_778765456199999983=
2styled-by-prettify"> </span><span style=3D"color:#008" class=3D"m_77876545=
61999999832styled-by-prettify">const</span><span style=3D"color:#660" class=
=3D"m_7787654561999999832styled-by-prettify">&amp;</span><span style=3D"col=
or:#000" class=3D"m_7787654561999999832styled-by-prettify"> v</span><span s=
tyle=3D"color:#660" class=3D"m_7787654561999999832styled-by-prettify">)</sp=
an><span style=3D"color:#000" class=3D"m_7787654561999999832styled-by-prett=
ify"> noexcept </span><span style=3D"color:#660" class=3D"m_778765456199999=
9832styled-by-prettify">{</span><span style=3D"color:#000" class=3D"m_77876=
54561999999832styled-by-prettify"><br>=C2=A0 =C2=A0 </span><font color=3D"#=
000088"><span style=3D"color:#008" class=3D"m_7787654561999999832styled-by-=
prettify">return</span><span style=3D"color:#000" class=3D"m_77876545619999=
99832styled-by-prettify"> </span></font><span style=3D"color:rgb(0,0,0)"><s=
pan style=3D"color:#000" class=3D"m_7787654561999999832styled-by-prettify">=
ptr_to_optional</span></span><font color=3D"#000088"><span style=3D"color:#=
660" class=3D"m_7787654561999999832styled-by-prettify">(</span></font><span=
 style=3D"color:#000" class=3D"m_7787654561999999832styled-by-prettify">get=
_if</span><span style=3D"color:#660" class=3D"m_7787654561999999832styled-b=
y-prettify">&lt;</span><span style=3D"color:#000" class=3D"m_77876545619999=
99832styled-by-prettify">T</span><span style=3D"color:#660" class=3D"m_7787=
654561999999832styled-by-prettify">&gt;(&amp;</span><span style=3D"color:#0=
00" class=3D"m_7787654561999999832styled-by-prettify">v</span><span style=
=3D"color:#660" class=3D"m_7787654561999999832styled-by-prettify">));</span=
><span style=3D"color:#000" class=3D"m_7787654561999999832styled-by-prettif=
y"><br></span><span style=3D"color:#660" class=3D"m_7787654561999999832styl=
ed-by-prettify">}</span><span style=3D"color:#000" class=3D"m_7787654561999=
999832styled-by-prettify"><br><br></span><span style=3D"color:#008" class=
=3D"m_7787654561999999832styled-by-prettify">template</span><span style=3D"=
color:#000" class=3D"m_7787654561999999832styled-by-prettify"> </span><span=
 style=3D"color:#660" class=3D"m_7787654561999999832styled-by-prettify">&lt=
;</span><font color=3D"#000088"><span style=3D"color:#000" class=3D"m_77876=
54561999999832styled-by-prettify">size_t I</span></font><span style=3D"colo=
r:#660" class=3D"m_7787654561999999832styled-by-prettify">,</span><span sty=
le=3D"color:#000" class=3D"m_7787654561999999832styled-by-prettify"> </span=
><span style=3D"color:#008" class=3D"m_7787654561999999832styled-by-prettif=
y">typename</span><span style=3D"color:#000" class=3D"m_7787654561999999832=
styled-by-prettify"> </span><span style=3D"color:#660" class=3D"m_778765456=
1999999832styled-by-prettify">...</span><span style=3D"color:#606" class=3D=
"m_7787654561999999832styled-by-prettify">Types</span><font color=3D"#66660=
0"><span style=3D"color:#660" class=3D"m_7787654561999999832styled-by-prett=
ify">&gt;</span></font><span style=3D"color:#000" class=3D"m_77876545619999=
99832styled-by-prettify"><br></span><span style=3D"color:#008" class=3D"m_7=
787654561999999832styled-by-prettify">constexpr</span><span style=3D"color:=
#000" class=3D"m_7787654561999999832styled-by-prettify"> </span><span style=
=3D"color:#008" class=3D"m_7787654561999999832styled-by-prettify">auto</spa=
n><span style=3D"color:#000" class=3D"m_7787654561999999832styled-by-pretti=
fy"> variant_to_optional</span><span style=3D"color:#660" class=3D"m_778765=
4561999999832styled-by-prettify">(</span><span style=3D"color:#000" class=
=3D"m_7787654561999999832styled-by-prettify">variant</span><span style=3D"c=
olor:#660" class=3D"m_7787654561999999832styled-by-prettify">&lt;</span><sp=
an style=3D"color:#606" class=3D"m_7787654561999999832styled-by-prettify">T=
ypes</span><span style=3D"color:#660" class=3D"m_7787654561999999832styled-=
by-prettify">...&gt;</span><span style=3D"color:#000" class=3D"m_7787654561=
999999832styled-by-prettify"> </span><span style=3D"color:#008" class=3D"m_=
7787654561999999832styled-by-prettify">const</span><span style=3D"color:#66=
0" class=3D"m_7787654561999999832styled-by-prettify">&amp;</span><span styl=
e=3D"color:#000" class=3D"m_7787654561999999832styled-by-prettify"> v</span=
><span style=3D"color:#660" class=3D"m_7787654561999999832styled-by-prettif=
y">)</span><span style=3D"color:#000" class=3D"m_7787654561999999832styled-=
by-prettify"> noexcept </span><span style=3D"color:#660" class=3D"m_7787654=
561999999832styled-by-prettify">{</span><span style=3D"color:#000" class=3D=
"m_7787654561999999832styled-by-prettify"><br>=C2=A0 =C2=A0 </span><font co=
lor=3D"#000088"><span style=3D"color:#008" class=3D"m_7787654561999999832st=
yled-by-prettify">return</span><span style=3D"color:#000" class=3D"m_778765=
4561999999832styled-by-prettify"> </span></font><span style=3D"color:rgb(0,=
0,0)"><span style=3D"color:#000" class=3D"m_7787654561999999832styled-by-pr=
ettify">ptr_to_optional</span></span><font color=3D"#000088"><span style=3D=
"color:#660" class=3D"m_7787654561999999832styled-by-prettify">(</span></fo=
nt><span style=3D"color:#000" class=3D"m_7787654561999999832styled-by-prett=
ify">get_if</span><span style=3D"color:#660" class=3D"m_7787654561999999832=
styled-by-prettify">&lt;</span><span style=3D"color:#000" class=3D"m_778765=
4561999999832styled-by-prettify">I</span><span style=3D"color:#660" class=
=3D"m_7787654561999999832styled-by-prettify">&gt;(&amp;</span><span style=
=3D"color:#000" class=3D"m_7787654561999999832styled-by-prettify">v</span><=
span style=3D"color:#660" class=3D"m_7787654561999999832styled-by-prettify"=
>));</span><span style=3D"color:#000" class=3D"m_7787654561999999832styled-=
by-prettify"><br></span><span style=3D"color:#660" class=3D"m_7787654561999=
999832styled-by-prettify">}</span><font color=3D"#000000"><span style=3D"co=
lor:#000" class=3D"m_7787654561999999832styled-by-prettify"><br></span></fo=
nt></div></code></div><br>=C2=A0+/- typos, naming choice, etc.</div></div>

<p></p>

-- <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>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/cd369c5c-cb53-4223-83cc-bb0497448e79%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/cd369c5c-cb53-=
4223-83cc-bb0497448e79%40isocpp.org</a>.<br>
</blockquote></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CALvx3hZHHJ4VyZUVNZ5_e1qbEO1UQUD8r4iA=
6tjUkKTeEvbAZA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CALvx3hZHHJ4VyZUV=
NZ5_e1qbEO1UQUD8r4iA6tjUkKTeEvbAZA%40mail.gmail.com</a>.<br />

--0000000000000e2af7056c42f872--

.


Author: Nevin Liber <nevin@eviloverlord.com>
Date: Tue, 15 May 2018 14:05:34 -0500
Raw View
--000000000000aba2fe056c434b2e
Content-Type: text/plain; charset="UTF-8"

On Tue, May 15, 2018 at 1:42 PM Richard Hodges <hodges.r@gmail.com> wrote:

> > Well, one problem is that you have to copy because there's no optional
> reference
>
> What on earth possessed the committee to come to the conclusion that this
> was a good idea?
>

https://stackoverflow.com/questions/26858034/stdoptional-specialization-for-reference-types/26895581#26895581


> Another shameful failure.
>

*shrug*
--
 Nevin ":-)" Liber  <mailto:nevin@eviloverlord.com>  +1-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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAGg_6%2BOSaNEGEeJ2o122HU8vZ%2BBjXh05yMteD8yttmtWWhUv8g%40mail.gmail.com.

--000000000000aba2fe056c434b2e
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Tue, May 15, 2018 at 1:42 PM Richard Hodges &lt;<a href=
=3D"mailto:hodges.r@gmail.com">hodges.r@gmail.com</a>&gt; wrote:<br><div cl=
ass=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0=
px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-colo=
r:rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr">&gt;=C2=A0<span style=
=3D"color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:no=
rmal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400=
;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none=
;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);floa=
t:none;display:inline">Well, one problem is that you have to copy because t=
here&#39;s no optional reference</span><div><span style=3D"color:rgb(34,34,=
34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-li=
gatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:norm=
al;text-align:start;text-indent:0px;text-transform:none;white-space:normal;=
word-spacing:0px;background-color:rgb(255,255,255);float:none;display:inlin=
e"><br></span></div><div><span style=3D"color:rgb(34,34,34);font-family:san=
s-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font=
-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start=
;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;ba=
ckground-color:rgb(255,255,255);float:none;display:inline">What on earth po=
ssessed the committee to come to the conclusion that this was a good idea?<=
/span></div></div></blockquote><div><br></div><div><a href=3D"https://stack=
overflow.com/questions/26858034/stdoptional-specialization-for-reference-ty=
pes/26895581#26895581">https://stackoverflow.com/questions/26858034/stdopti=
onal-specialization-for-reference-types/26895581#26895581</a></div><div>=C2=
=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8e=
x;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,2=
04,204);padding-left:1ex"><div dir=3D"ltr"><div>Another shameful failure.<b=
r></div></div></blockquote><div><br></div><div>*shrug*</div></div>-- <br><d=
iv dir=3D"ltr" class=3D"gmail_signature"><div dir=3D"ltr"><div><div dir=3D"=
ltr"><div>=C2=A0Nevin &quot;:-)&quot; Liber=C2=A0 &lt;mailto:<a href=3D"mai=
lto:nevin@eviloverlord.com" target=3D"_blank">nevin@eviloverlord.com</a>&gt=
; =C2=A0+1-847-691-1404</div></div></div></div></div></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAGg_6%2BOSaNEGEeJ2o122HU8vZ%2BBjXh05=
yMteD8yttmtWWhUv8g%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAGg_6%2BOSaN=
EGEeJ2o122HU8vZ%2BBjXh05yMteD8yttmtWWhUv8g%40mail.gmail.com</a>.<br />

--000000000000aba2fe056c434b2e--

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Tue, 15 May 2018 23:34:32 +0200
Raw View
Le 15/05/2018 =C3=A0 17:39, tortoise741@gmail.com a =C3=A9crit=C2=A0:
> Hi,
> =C2=A0=C2=A0=C2=A0 Apologies if this has been asked before. variant and o=
ptional are=20
> quite common search terms.
>
> =C2=A0=C2=A0=C2=A0 I'm wondering if there is, or should be a standard way=
 to convert=20
> a variant into an optional?
> Or if its a bad idea why there shouldn't be.
>
> Consider the following example. Imagine Foo is an object representing=20
> a configuration.
> One part of the configuration bar has two possible modes of operation=20
> one requires one piece of configuration
> and one requires the other but it is not valid to specify both.
>
> #include <variant>
> #include <optional>
>
> class Foo
> {
> private:
> =C2=A0=C2=A0=C2=A0 std::variant<int, std::string> bar;
> public:
> =C2=A0=C2=A0=C2=A0 Foo(int a): bar(a) {}
> =C2=A0=C2=A0=C2=A0 Foo(const std::string& b): bar(b) {}
>
> =C2=A0=C2=A0=C2=A0 std::optional<int> getInt() const
> =C2=A0=C2=A0=C2=A0 {
> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::optional<int> ret;
> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto got =3D std::get_if<int>(=
&this->bar);
> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (got) ret =3D *got;
> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return ret;
> =C2=A0=C2=A0=C2=A0 }
>
> =C2=A0=C2=A0=C2=A0 std::optional<std::string> getString() const
> =C2=A0=C2=A0=C2=A0 {
> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::optional<std::string> ret=
;
> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto got =3D std::get_if<std::=
string>(&this->bar);
> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (got) ret =3D *got;
> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return ret;
> =C2=A0=C2=A0=C2=A0 }
> };
>
> There seems to be a lot of boilerplate to convert the variant into a=20
> optional for the return.
> There is an inefficiency here in that the type contained has to be=20
> checked twice to use this.
>
> There are other ways to do this. You can expose the variant member and=20
> use a visitor
> but using a visitor feels like overkill for this. Also the variant is=20
> an internal implementation detail.
> An equally valid implementation would have two different optional=20
> members (but would not enforce their mutual exclusivity).
>
> So do we need (or is there already) something kind of like:
>
> =C2=A0=C2=A0=C2=A0 std::optional<std::string> getString() const
> =C2=A0=C2=A0=C2=A0 {
> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return make_optional<std::stri=
ng>(this->bar);
> =C2=A0=C2=A0=C2=A0 }
>
> or bikeshedding:
>
> =C2=A0=C2=A0=C2=A0 std::optional<std::string> getString() const
> =C2=A0=C2=A0=C2=A0 {
> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return to_optional<std::string=
>(this->bar);
> =C2=A0=C2=A0=C2=A0 }
>

The conversion is simple, but we don't need to do the conversion until=20
requested. We can see a variant<Ts...> as some kind of ValueOrNone type=20
(that can not change of alternative) once we select one of the=20
alternatives T. Lets name this function select<T>(SumType).

The conversion would be done only when requested, e.g. by an implicit=20
conversion.

 =C2=A0=C2=A0=C2=A0 optional<T> o =3D select<T>(SumType);


However, we could as well

 =C2=A0=C2=A0=C2=A0 auto von =3D select<T>(SumType);

von is not an optional<T>. It is something else, a reference to a=20
sum-type, with the perspective of only one of the alternatives. Now we=20
can use von as a ValueOrNone, with the usual von.has_value() and *von.=20
Note that these functions don't need to check the type twice:
 =C2=A0=C2=A0=C2=A0 von.has_value() should be equivalent to std::get_if<T>(=
&von) and
 =C2=A0=C2=A0=C2=A0 *von equivalent to std::get<T>(von).


Just my 2cts.

Vicente

--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/2e6b1fb6-e7e1-fc87-bb42-b5179e826638%40wanadoo.f=
r.

.


Author: tortoise741@gmail.com
Date: Thu, 17 May 2018 03:30:12 -0700 (PDT)
Raw View
------=_Part_815_1324439873.1526553012730
Content-Type: multipart/alternative;
 boundary="----=_Part_816_571158546.1526553012731"

------=_Part_816_571158546.1526553012731
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Tuesday, 15 May 2018 22:34:36 UTC+1, Vicente J. Botet Escriba wrote:
>
> Le 15/05/2018 =C3=A0 17:39, torto...@gmail.com <javascript:> a =C3=A9crit=
 :=20
> > Hi,=20
> >     Apologies if this has been asked before. variant and optional are=
=20
> > quite common search terms.=20
> >=20
> >     I'm wondering if there is, or should be a standard way to convert=
=20
> > a variant into an optional?=20
> > Or if its a bad idea why there shouldn't be.=20
> >=20
> > Consider the following example. Imagine Foo is an object representing=
=20
> > a configuration.=20
> > One part of the configuration bar has two possible modes of operation=
=20
> > one requires one piece of configuration=20
> > and one requires the other but it is not valid to specify both.=20
> >=20
> > #include <variant>=20
> > #include <optional>=20
> >=20
> > class Foo=20
> > {=20
> > private:=20
> >     std::variant<int, std::string> bar;=20
> > public:=20
> >     Foo(int a): bar(a) {}=20
> >     Foo(const std::string& b): bar(b) {}=20
> >=20
> >     std::optional<int> getInt() const=20
> >     {=20
> >         std::optional<int> ret;=20
> >         auto got =3D std::get_if<int>(&this->bar);=20
> >         if (got) ret =3D *got;=20
> >         return ret;=20
> >     }=20
> >=20
> >     std::optional<std::string> getString() const=20
> >     {=20
> >         std::optional<std::string> ret;=20
> >         auto got =3D std::get_if<std::string>(&this->bar);=20
> >         if (got) ret =3D *got;=20
> >         return ret;=20
> >     }=20
> > };=20
> >=20
> > There seems to be a lot of boilerplate to convert the variant into a=20
> > optional for the return.=20
> > There is an inefficiency here in that the type contained has to be=20
> > checked twice to use this.=20
> >=20
> > There are other ways to do this. You can expose the variant member and=
=20
> > use a visitor=20
> > but using a visitor feels like overkill for this. Also the variant is=
=20
> > an internal implementation detail.=20
> > An equally valid implementation would have two different optional=20
> > members (but would not enforce their mutual exclusivity).=20
> >=20
> > So do we need (or is there already) something kind of like:=20
> >=20
> >     std::optional<std::string> getString() const=20
> >     {=20
> >         return make_optional<std::string>(this->bar);=20
> >     }=20
> >=20
> > or bikeshedding:=20
> >=20
> >     std::optional<std::string> getString() const=20
> >     {=20
> >         return to_optional<std::string>(this->bar);=20
> >     }=20
> >=20
>
> The conversion is simple, but we don't need to do the conversion until=20
> requested. We can see a variant<Ts...> as some kind of ValueOrNone type=
=20
> (that can not change of alternative) once we select one of the=20
> alternatives T. Lets name this function select<T>(SumType).=20
>
> The conversion would be done only when requested, e.g. by an implicit=20
> conversion.=20
>
>      optional<T> o =3D select<T>(SumType);=20
>
>
> However, we could as well=20
>
>      auto von =3D select<T>(SumType);=20
>
> von is not an optional<T>. It is something else, a reference to a=20
> sum-type, with the perspective of only one of the alternatives. Now we=20
> can use von as a ValueOrNone, with the usual von.has_value() and *von.=20
> Note that these functions don't need to check the type twice:=20
>      von.has_value() should be equivalent to std::get_if<T>(&von) and=20
>      *von equivalent to std::get<T>(von).=20
>
>
> Just my 2cts.=20
>
> Vicente=20
>
> I very much like the name select.

I see your argument that a ValueOrNone isn't strictly an optional but if it=
=20
isn't don't we complicate the language
with yet another "maybe" type? Wouldn't the language be cleaner with just=
=20
one?
I guess the answer is adding optional references as previously mentioned?

Regards,

Bruce.

=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/bbbc65c3-b9e5-4365-9d06-591fcd86d93a%40isocpp.or=
g.

------=_Part_816_571158546.1526553012731
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Tuesday, 15 May 2018 22:34:36 UTC+1, Vicente J. Botet E=
scriba  wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Le 15/05/2018 =
=C3=A0 17:39, <a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mail=
to=3D"2h2c0_gOCQAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javasc=
ript:&#39;;return true;" onclick=3D"this.href=3D&#39;javascript:&#39;;retur=
n true;">torto...@gmail.com</a> a =C3=A9crit=C2=A0:
<br>&gt; Hi,
<br>&gt; =C2=A0=C2=A0=C2=A0 Apologies if this has been asked before. varian=
t and optional are=20
<br>&gt; quite common search terms.
<br>&gt;
<br>&gt; =C2=A0=C2=A0=C2=A0 I&#39;m wondering if there is, or should be a s=
tandard way to convert=20
<br>&gt; a variant into an optional?
<br>&gt; Or if its a bad idea why there shouldn&#39;t be.
<br>&gt;
<br>&gt; Consider the following example. Imagine Foo is an object represent=
ing=20
<br>&gt; a configuration.
<br>&gt; One part of the configuration bar has two possible modes of operat=
ion=20
<br>&gt; one requires one piece of configuration
<br>&gt; and one requires the other but it is not valid to specify both.
<br>&gt;
<br>&gt; #include &lt;variant&gt;
<br>&gt; #include &lt;optional&gt;
<br>&gt;
<br>&gt; class Foo
<br>&gt; {
<br>&gt; private:
<br>&gt; =C2=A0=C2=A0=C2=A0 std::variant&lt;int, std::string&gt; bar;
<br>&gt; public:
<br>&gt; =C2=A0=C2=A0=C2=A0 Foo(int a): bar(a) {}
<br>&gt; =C2=A0=C2=A0=C2=A0 Foo(const std::string&amp; b): bar(b) {}
<br>&gt;
<br>&gt; =C2=A0=C2=A0=C2=A0 std::optional&lt;int&gt; getInt() const
<br>&gt; =C2=A0=C2=A0=C2=A0 {
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::optional&lt;int&gt=
; ret;
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto got =3D std::get_i=
f&lt;int&gt;(&amp;this-&gt;bar);
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (got) ret =3D *got;
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return ret;
<br>&gt; =C2=A0=C2=A0=C2=A0 }
<br>&gt;
<br>&gt; =C2=A0=C2=A0=C2=A0 std::optional&lt;std::string&gt; getString() co=
nst
<br>&gt; =C2=A0=C2=A0=C2=A0 {
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::optional&lt;std::s=
tring&gt; ret;
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto got =3D std::get_i=
f&lt;std::string&gt;(&amp;<wbr>this-&gt;bar);
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (got) ret =3D *got;
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return ret;
<br>&gt; =C2=A0=C2=A0=C2=A0 }
<br>&gt; };
<br>&gt;
<br>&gt; There seems to be a lot of boilerplate to convert the variant into=
 a=20
<br>&gt; optional for the return.
<br>&gt; There is an inefficiency here in that the type contained has to be=
=20
<br>&gt; checked twice to use this.
<br>&gt;
<br>&gt; There are other ways to do this. You can expose the variant member=
 and=20
<br>&gt; use a visitor
<br>&gt; but using a visitor feels like overkill for this. Also the variant=
 is=20
<br>&gt; an internal implementation detail.
<br>&gt; An equally valid implementation would have two different optional=
=20
<br>&gt; members (but would not enforce their mutual exclusivity).
<br>&gt;
<br>&gt; So do we need (or is there already) something kind of like:
<br>&gt;
<br>&gt; =C2=A0=C2=A0=C2=A0 std::optional&lt;std::string&gt; getString() co=
nst
<br>&gt; =C2=A0=C2=A0=C2=A0 {
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return make_optional&lt=
;std::string&gt;(<wbr>this-&gt;bar);
<br>&gt; =C2=A0=C2=A0=C2=A0 }
<br>&gt;
<br>&gt; or bikeshedding:
<br>&gt;
<br>&gt; =C2=A0=C2=A0=C2=A0 std::optional&lt;std::string&gt; getString() co=
nst
<br>&gt; =C2=A0=C2=A0=C2=A0 {
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return to_optional&lt;s=
td::string&gt;(this-<wbr>&gt;bar);
<br>&gt; =C2=A0=C2=A0=C2=A0 }
<br>&gt;
<br>
<br>The conversion is simple, but we don&#39;t need to do the conversion un=
til=20
<br>requested. We can see a variant&lt;Ts...&gt; as some kind of ValueOrNon=
e type=20
<br>(that can not change of alternative) once we select one of the=20
<br>alternatives T. Lets name this function select&lt;T&gt;(SumType).
<br>
<br>The conversion would be done only when requested, e.g. by an implicit=
=20
<br>conversion.
<br>
<br>=C2=A0=C2=A0=C2=A0=C2=A0 optional&lt;T&gt; o =3D select&lt;T&gt;(SumTyp=
e);
<br>
<br>
<br>However, we could as well
<br>
<br>=C2=A0=C2=A0=C2=A0=C2=A0 auto von =3D select&lt;T&gt;(SumType);
<br>
<br>von is not an optional&lt;T&gt;. It is something else, a reference to a=
=20
<br>sum-type, with the perspective of only one of the alternatives. Now we=
=20
<br>can use von as a ValueOrNone, with the usual von.has_value() and *von.=
=20
<br>Note that these functions don&#39;t need to check the type twice:
<br>=C2=A0=C2=A0=C2=A0=C2=A0 von.has_value() should be equivalent to std::g=
et_if&lt;T&gt;(&amp;von) and
<br>=C2=A0=C2=A0=C2=A0=C2=A0 *von equivalent to std::get&lt;T&gt;(von).
<br>
<br>
<br>Just my 2cts.
<br>
<br>Vicente
<br>
<br></blockquote><div>I very much like the name select.<br><br>I see your a=
rgument that a ValueOrNone isn&#39;t strictly an optional but if it isn&#39=
;t don&#39;t we complicate the language<br>with yet another &quot;maybe&quo=
t; type? Wouldn&#39;t the language be cleaner with just one?<br>I guess the=
 answer is adding optional references as previously mentioned?<br><br>Regar=
ds,<br><br>Bruce.<br><br>=C2=A0</div></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/bbbc65c3-b9e5-4365-9d06-591fcd86d93a%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/bbbc65c3-b9e5-4365-9d06-591fcd86d93a=
%40isocpp.org</a>.<br />

------=_Part_816_571158546.1526553012731--

------=_Part_815_1324439873.1526553012730--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Thu, 17 May 2018 08:03:29 -0700 (PDT)
Raw View
------=_Part_5198_72334775.1526569409387
Content-Type: multipart/alternative;
 boundary="----=_Part_5199_1371347894.1526569409387"

------=_Part_5199_1371347894.1526569409387
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Thursday, May 17, 2018 at 6:30:12 AM UTC-4, Bruce Adams wrote:
>
> On Tuesday, 15 May 2018 22:34:36 UTC+1, Vicente J. Botet Escriba wrote:
>>
>> Le 15/05/2018 =C3=A0 17:39, torto...@gmail.com a =C3=A9crit :=20
>> > Hi,=20
>> >     Apologies if this has been asked before. variant and optional are=
=20
>> > quite common search terms.=20
>> >=20
>> >     I'm wondering if there is, or should be a standard way to convert=
=20
>> > a variant into an optional?=20
>> > Or if its a bad idea why there shouldn't be.=20
>> >=20
>> > Consider the following example. Imagine Foo is an object representing=
=20
>> > a configuration.=20
>> > One part of the configuration bar has two possible modes of operation=
=20
>> > one requires one piece of configuration=20
>> > and one requires the other but it is not valid to specify both.=20
>> >=20
>> > #include <variant>=20
>> > #include <optional>=20
>> >=20
>> > class Foo=20
>> > {=20
>> > private:=20
>> >     std::variant<int, std::string> bar;=20
>> > public:=20
>> >     Foo(int a): bar(a) {}=20
>> >     Foo(const std::string& b): bar(b) {}=20
>> >=20
>> >     std::optional<int> getInt() const=20
>> >     {=20
>> >         std::optional<int> ret;=20
>> >         auto got =3D std::get_if<int>(&this->bar);=20
>> >         if (got) ret =3D *got;=20
>> >         return ret;=20
>> >     }=20
>> >=20
>> >     std::optional<std::string> getString() const=20
>> >     {=20
>> >         std::optional<std::string> ret;=20
>> >         auto got =3D std::get_if<std::string>(&this->bar);=20
>> >         if (got) ret =3D *got;=20
>> >         return ret;=20
>> >     }=20
>> > };=20
>> >=20
>> > There seems to be a lot of boilerplate to convert the variant into a=
=20
>> > optional for the return.=20
>> > There is an inefficiency here in that the type contained has to be=20
>> > checked twice to use this.=20
>> >=20
>> > There are other ways to do this. You can expose the variant member and=
=20
>> > use a visitor=20
>> > but using a visitor feels like overkill for this. Also the variant is=
=20
>> > an internal implementation detail.=20
>> > An equally valid implementation would have two different optional=20
>> > members (but would not enforce their mutual exclusivity).=20
>> >=20
>> > So do we need (or is there already) something kind of like:=20
>> >=20
>> >     std::optional<std::string> getString() const=20
>> >     {=20
>> >         return make_optional<std::string>(this->bar);=20
>> >     }=20
>> >=20
>> > or bikeshedding:=20
>> >=20
>> >     std::optional<std::string> getString() const=20
>> >     {=20
>> >         return to_optional<std::string>(this->bar);=20
>> >     }=20
>> >=20
>>
>> The conversion is simple, but we don't need to do the conversion until=
=20
>> requested. We can see a variant<Ts...> as some kind of ValueOrNone type=
=20
>> (that can not change of alternative) once we select one of the=20
>> alternatives T. Lets name this function select<T>(SumType).=20
>>
>> The conversion would be done only when requested, e.g. by an implicit=20
>> conversion.=20
>>
>>      optional<T> o =3D select<T>(SumType);=20
>>
>>
>> However, we could as well=20
>>
>>      auto von =3D select<T>(SumType);=20
>>
>> von is not an optional<T>. It is something else, a reference to a=20
>> sum-type, with the perspective of only one of the alternatives. Now we=
=20
>> can use von as a ValueOrNone, with the usual von.has_value() and *von.=
=20
>> Note that these functions don't need to check the type twice:=20
>>      von.has_value() should be equivalent to std::get_if<T>(&von) and=20
>>      *von equivalent to std::get<T>(von).=20
>>
>>
>> Just my 2cts.=20
>>
>> Vicente=20
>>
>> I very much like the name select.
>
> I see your argument that a ValueOrNone isn't strictly an optional but if=
=20
> it isn't don't we complicate the language
> with yet another "maybe" type? Wouldn't the language be cleaner with just=
=20
> one?=20
>
I guess the answer is adding optional references as previously mentioned?
>

The thing is, a new type would be able to avoid the big design problem with=
=20
`optional<T&>`: the meaning of assignment. `optional`, by design, is meant=
=20
to be rebindable, modifiable. You can empty it, put a new value into it,=20
copy a new value into its current value.

So a hypothetical `optional<T&>` ought to be rebindable too. But what does=
=20
assignment mean in that context? If you assign a glvalue to an unengaged=20
`optional<T&>` it should take a reference to it. But if you assign to an=20
engaged `optional<T&>`, will it take a reference or copy the value? Some=20
would expect assignment to always take a reference, and some will expect=20
assignment to copy or reference based on engagement. Some might even expect=
=20
it to always copy the value, since that's how `optional<T>` works;=20
presumably on an unengaged `optional<T&>`, you get an exception.

Boost provides one answer, but what makes it the *right* answer? There are=
=20
plenty of people on both sides who have valid viewpoints, and regardless of=
=20
which side you pick, someone is going to get it wrong.

However, if you create some alternative `select` type, it could by design=
=20
*not* be rebindable/assignable. Even for value types. So when you create=20
it, you either provide a value/reference, and the `select<T>` will forever=
=20
either be engaged or not engaged. The binding is *immutable*. If you=20
move-construct from a `select<T>`, it *will not* leave the former object=20
unengaged; it will merely move from the engaged value.

After all, look at this `variant` case. We don't *need* the return value of=
=20
such a function to have mutable bindings. It's perfectly fine for our needs=
=20
if that object is forever associated with the `variant`.

Armed with such a type, we no longer have to deal with the questions of=20
`optional<T&>`'s assignment behavior. It might be cleaner to only have one=
=20
type, yes. But since `optional` is expected to have mutable bindings, and=
=20
that expectation does not play nice with references, it is best to have an=
=20
alternative object for cases where bindings don't need to be mutable.

--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/cba29994-04ba-4d98-ad31-e44b4bca7d7d%40isocpp.or=
g.

------=_Part_5199_1371347894.1526569409387
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Thursday, May 17, 2018 at 6:30:12 AM UTC-4, Bruce Adams=
 wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.=
8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">On Tue=
sday, 15 May 2018 22:34:36 UTC+1, Vicente J. Botet Escriba  wrote:<blockquo=
te class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1p=
x #ccc solid;padding-left:1ex">Le 15/05/2018 =C3=A0 17:39, <a rel=3D"nofoll=
ow">torto...@gmail.com</a> a =C3=A9crit=C2=A0:
<br>&gt; Hi,
<br>&gt; =C2=A0=C2=A0=C2=A0 Apologies if this has been asked before. varian=
t and optional are=20
<br>&gt; quite common search terms.
<br>&gt;
<br>&gt; =C2=A0=C2=A0=C2=A0 I&#39;m wondering if there is, or should be a s=
tandard way to convert=20
<br>&gt; a variant into an optional?
<br>&gt; Or if its a bad idea why there shouldn&#39;t be.
<br>&gt;
<br>&gt; Consider the following example. Imagine Foo is an object represent=
ing=20
<br>&gt; a configuration.
<br>&gt; One part of the configuration bar has two possible modes of operat=
ion=20
<br>&gt; one requires one piece of configuration
<br>&gt; and one requires the other but it is not valid to specify both.
<br>&gt;
<br>&gt; #include &lt;variant&gt;
<br>&gt; #include &lt;optional&gt;
<br>&gt;
<br>&gt; class Foo
<br>&gt; {
<br>&gt; private:
<br>&gt; =C2=A0=C2=A0=C2=A0 std::variant&lt;int, std::string&gt; bar;
<br>&gt; public:
<br>&gt; =C2=A0=C2=A0=C2=A0 Foo(int a): bar(a) {}
<br>&gt; =C2=A0=C2=A0=C2=A0 Foo(const std::string&amp; b): bar(b) {}
<br>&gt;
<br>&gt; =C2=A0=C2=A0=C2=A0 std::optional&lt;int&gt; getInt() const
<br>&gt; =C2=A0=C2=A0=C2=A0 {
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::optional&lt;int&gt=
; ret;
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto got =3D std::get_i=
f&lt;int&gt;(&amp;this-&gt;bar);
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (got) ret =3D *got;
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return ret;
<br>&gt; =C2=A0=C2=A0=C2=A0 }
<br>&gt;
<br>&gt; =C2=A0=C2=A0=C2=A0 std::optional&lt;std::string&gt; getString() co=
nst
<br>&gt; =C2=A0=C2=A0=C2=A0 {
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::optional&lt;std::s=
tring&gt; ret;
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto got =3D std::get_i=
f&lt;std::string&gt;(&amp;<wbr>this-&gt;bar);
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (got) ret =3D *got;
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return ret;
<br>&gt; =C2=A0=C2=A0=C2=A0 }
<br>&gt; };
<br>&gt;
<br>&gt; There seems to be a lot of boilerplate to convert the variant into=
 a=20
<br>&gt; optional for the return.
<br>&gt; There is an inefficiency here in that the type contained has to be=
=20
<br>&gt; checked twice to use this.
<br>&gt;
<br>&gt; There are other ways to do this. You can expose the variant member=
 and=20
<br>&gt; use a visitor
<br>&gt; but using a visitor feels like overkill for this. Also the variant=
 is=20
<br>&gt; an internal implementation detail.
<br>&gt; An equally valid implementation would have two different optional=
=20
<br>&gt; members (but would not enforce their mutual exclusivity).
<br>&gt;
<br>&gt; So do we need (or is there already) something kind of like:
<br>&gt;
<br>&gt; =C2=A0=C2=A0=C2=A0 std::optional&lt;std::string&gt; getString() co=
nst
<br>&gt; =C2=A0=C2=A0=C2=A0 {
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return make_optional&lt=
;std::string&gt;(<wbr>this-&gt;bar);
<br>&gt; =C2=A0=C2=A0=C2=A0 }
<br>&gt;
<br>&gt; or bikeshedding:
<br>&gt;
<br>&gt; =C2=A0=C2=A0=C2=A0 std::optional&lt;std::string&gt; getString() co=
nst
<br>&gt; =C2=A0=C2=A0=C2=A0 {
<br>&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return to_optional&lt;s=
td::string&gt;(this-<wbr>&gt;bar);
<br>&gt; =C2=A0=C2=A0=C2=A0 }
<br>&gt;
<br>
<br>The conversion is simple, but we don&#39;t need to do the conversion un=
til=20
<br>requested. We can see a variant&lt;Ts...&gt; as some kind of ValueOrNon=
e type=20
<br>(that can not change of alternative) once we select one of the=20
<br>alternatives T. Lets name this function select&lt;T&gt;(SumType).
<br>
<br>The conversion would be done only when requested, e.g. by an implicit=
=20
<br>conversion.
<br>
<br>=C2=A0=C2=A0=C2=A0=C2=A0 optional&lt;T&gt; o =3D select&lt;T&gt;(SumTyp=
e);
<br>
<br>
<br>However, we could as well
<br>
<br>=C2=A0=C2=A0=C2=A0=C2=A0 auto von =3D select&lt;T&gt;(SumType);
<br>
<br>von is not an optional&lt;T&gt;. It is something else, a reference to a=
=20
<br>sum-type, with the perspective of only one of the alternatives. Now we=
=20
<br>can use von as a ValueOrNone, with the usual von.has_value() and *von.=
=20
<br>Note that these functions don&#39;t need to check the type twice:
<br>=C2=A0=C2=A0=C2=A0=C2=A0 von.has_value() should be equivalent to std::g=
et_if&lt;T&gt;(&amp;von) and
<br>=C2=A0=C2=A0=C2=A0=C2=A0 *von equivalent to std::get&lt;T&gt;(von).
<br>
<br>
<br>Just my 2cts.
<br>
<br>Vicente
<br>
<br></blockquote><div>I very much like the name select.<br><br>I see your a=
rgument that a ValueOrNone isn&#39;t strictly an optional but if it isn&#39=
;t don&#39;t we complicate the language<br>with yet another &quot;maybe&quo=
t; type? Wouldn&#39;t the language be cleaner with just one? <br></div></di=
v></blockquote><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-=
left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr=
"><div>I guess the answer is adding optional references as previously menti=
oned?<br></div></div></blockquote><div><br></div><div>The thing is, a new t=
ype would be able to avoid the big design problem with `optional&lt;T&amp;&=
gt;`: the meaning of assignment. `optional`, by design, is meant to be rebi=
ndable, modifiable. You can empty it, put a new value into it, copy a new v=
alue into its current value.</div><div><br></div><div>So a hypothetical `op=
tional&lt;T&amp;&gt;` ought to be rebindable too. But what does assignment =
mean in that context? If you assign a glvalue to an unengaged `optional&lt;=
T&amp;&gt;` it should take a reference to it. But if you assign to an engag=
ed `optional&lt;T&amp;&gt;`, will it take a reference or copy the value? So=
me would expect assignment to always take a reference, and some will expect=
 assignment to copy or reference based on engagement. Some might even expec=
t it to always copy the value, since that&#39;s how `optional&lt;T&gt;` wor=
ks; presumably on an unengaged `optional&lt;T&amp;&gt;`, you get an excepti=
on.</div><div><br></div><div>Boost provides one answer, but what makes it t=
he <i>right</i> answer? There are plenty of people on both sides who have v=
alid viewpoints, and regardless of which side you pick, someone is going to=
 get it wrong.<br></div><div></div><div><br></div><div>However, if you crea=
te some alternative `select` type, it could by design <i>not</i> be rebinda=
ble/assignable. Even for value types. So when you create it, you either pro=
vide a value/reference, and the `select&lt;T&gt;` will forever either be en=
gaged or not engaged. The binding is <i>immutable</i>. If you move-construc=
t from a `select&lt;T&gt;`, it <i>will not</i> leave the former object unen=
gaged; it will merely move from the engaged value.</div><div><br></div><div=
>After all, look at this `variant` case. We don&#39;t <i>need</i> the retur=
n value of such a function to have mutable bindings. It&#39;s perfectly fin=
e for our needs if that object is forever associated with the `variant`.<br=
></div><div><br></div><div>Armed with such a type, we no longer have to dea=
l with the questions of `optional&lt;T&amp;&gt;`&#39;s assignment behavior.=
 It might be cleaner to only have one type, yes. But since `optional` is ex=
pected to have mutable bindings, and that expectation does not play nice wi=
th references, it is best to have an alternative object for cases where bin=
dings don&#39;t need to be mutable.</div></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/cba29994-04ba-4d98-ad31-e44b4bca7d7d%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/cba29994-04ba-4d98-ad31-e44b4bca7d7d=
%40isocpp.org</a>.<br />

------=_Part_5199_1371347894.1526569409387--

------=_Part_5198_72334775.1526569409387--

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Fri, 18 May 2018 14:21:08 +0200
Raw View
This is a multi-part message in MIME format.
--------------FEEA91565658746D77502380
Content-Type: text/plain; charset="UTF-8"; format=flowed
Content-Transfer-Encoding: quoted-printable

Le 17/05/2018 =C3=A0 12:30, tortoise741@gmail.com a =C3=A9crit=C2=A0:
> On Tuesday, 15 May 2018 22:34:36 UTC+1, Vicente J. Botet Escriba wrote:
>
>     Le 15/05/2018 =C3=A0 17:39, torto...@gmail.com <javascript:> a =C3=A9=
crit=C2=A0:
>     > =C2=A0=C2=A0=C2=A0 I'm wondering if there is, or should be a standa=
rd way to
>     convert
>     > a variant into an optional?
>     > Or if its a bad idea why there shouldn't be.
>     >
>
>     >
>     > =C2=A0=C2=A0=C2=A0 std::optional<std::string> getString() const
>     > =C2=A0=C2=A0=C2=A0 {
>     > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::optional<std::strin=
g> ret;
>     > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto got =3D std::get_if=
<std::string>(&this->bar);
>     > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (got) ret =3D *got;
>     > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return ret;
>     > =C2=A0=C2=A0=C2=A0 }
>     > };
>     >
>     > There seems to be a lot of boilerplate to convert the variant
>     into a
>     > optional for the return.
>     > There is an inefficiency here in that the type contained has to be
>     > checked twice to use this.
>     >
>     > There are other ways to do this. You can expose the variant
>     member and
>     > use a visitor
>     > but using a visitor feels like overkill for this. Also the
>     variant is
>     > an internal implementation detail.
>     > An equally valid implementation would have two different optional
>     > members (but would not enforce their mutual exclusivity).
>     >
>     > So do we need (or is there already) something kind of like:
>     >
>     > =C2=A0=C2=A0=C2=A0 std::optional<std::string> getString() const
>     > =C2=A0=C2=A0=C2=A0 {
>     > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return make_optional<std=
::string>(this->bar);
>     > =C2=A0=C2=A0=C2=A0 }
>     >
>     > or bikeshedding:
>     >
>     > =C2=A0=C2=A0=C2=A0 std::optional<std::string> getString() const
>     > =C2=A0=C2=A0=C2=A0 {
>     > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return to_optional<std::=
string>(this->bar);
>     > =C2=A0=C2=A0=C2=A0 }
>     >
>
>     The conversion is simple, but we don't need to do the conversion
>     until
>     requested. We can see a variant<Ts...> as some kind of ValueOrNone
>     type
>     (that can not change of alternative) once we select one of the
>     alternatives T. Lets name this function select<T>(SumType).
>
>     The conversion would be done only when requested, e.g. by an implicit
>     conversion.
>
>     =C2=A0=C2=A0=C2=A0=C2=A0 optional<T> o =3D select<T>(SumType);
>
>
>     However, we could as well
>
>     =C2=A0=C2=A0=C2=A0=C2=A0 auto von =3D select<T>(SumType);
>
>     von is not an optional<T>. It is something else, a reference to a
>     sum-type, with the perspective of only one of the alternatives.
>     Now we
>     can use von as a ValueOrNone, with the usual von.has_value() and
>     *von.
>     Note that these functions don't need to check the type twice:
>     =C2=A0=C2=A0=C2=A0=C2=A0 von.has_value() should be equivalent to std:=
:get_if<T>(&von) and
>     =C2=A0=C2=A0=C2=A0=C2=A0 *von equivalent to std::get<T>(von).
>
>
>
> I very much like the name select.
>
> I see your argument that a ValueOrNone isn't strictly an optional but=20
> if it isn't don't we complicate the language
> with yet another "maybe" type? Wouldn't the language be cleaner with=20
> just one?
> I guess the answer is adding optional references as previously mentioned?
>
Well, with the select function, you don't need to do any conversion,=20
even not to optional<T&>. Note that the type obtained with select, can=20
be an implementation detail. We don't have to name it. And of course, it=20
can be convertible to optional<T> or optional<T&> if we had it.

Vicente

P.S. I've a variadic select that applied to std::any results in a sum=20
type that is equivalent to a nullable variant.


std::any a;
auto v =3D select<T1, ..., Tn>(a); // equivalent to variant<none_t, T1&,=20
...., Tn&>

Once we have done that, we can visit a std::any :)
The problem is that the complexity is not O(1) but O(n) :(


--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/c30c63a6-7695-b0be-7d3e-b57f1ed481b0%40wanadoo.f=
r.

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

<html>
  <head>
    <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8=
">
  </head>
  <body text=3D"#000000" bgcolor=3D"#FFFFFF">
    <div class=3D"moz-cite-prefix">Le 17/05/2018 =C3=A0 12:30,
      <a class=3D"moz-txt-link-abbreviated" href=3D"mailto:tortoise741@gmai=
l.com">tortoise741@gmail.com</a> a =C3=A9crit=C2=A0:<br>
    </div>
    <blockquote type=3D"cite"
      cite=3D"mid:bbbc65c3-b9e5-4365-9d06-591fcd86d93a@isocpp.org">
      <div dir=3D"ltr">On Tuesday, 15 May 2018 22:34:36 UTC+1, Vicente J.
        Botet Escriba wrote:
        <blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:
          0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Le
          15/05/2018 =C3=A0 17:39, <a href=3D"javascript:" target=3D"_blank=
"
            gdf-obfuscated-mailto=3D"2h2c0_gOCQAJ" rel=3D"nofollow"
            onmousedown=3D"this.href=3D'javascript:';return true;"
            onclick=3D"this.href=3D'javascript:';return true;"
            moz-do-not-send=3D"true">torto...@gmail.com</a> a =C3=A9crit=C2=
=A0:
          <br>
          &gt; =C2=A0=C2=A0=C2=A0 I'm wondering if there is, or should be a=
 standard
          way to convert <br>
          &gt; a variant into an optional?
          <br>
          &gt; Or if its a bad idea why there shouldn't be.
          <br>
          &gt;
          <br>
          <br>
          &gt;
          <br>
          &gt; =C2=A0=C2=A0=C2=A0 std::optional&lt;std::string&gt; getStrin=
g() const
          <br>
          &gt; =C2=A0=C2=A0=C2=A0 {
          <br>
          &gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::optional&lt;=
std::string&gt; ret;
          <br>
          &gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto got =3D std:=
:get_if&lt;std::string&gt;(&amp;<wbr>this-&gt;bar);
          <br>
          &gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (got) ret =3D =
*got;
          <br>
          &gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return ret;
          <br>
          &gt; =C2=A0=C2=A0=C2=A0 }
          <br>
          &gt; };
          <br>
          &gt;
          <br>
          &gt; There seems to be a lot of boilerplate to convert the
          variant into a <br>
          &gt; optional for the return.
          <br>
          &gt; There is an inefficiency here in that the type contained
          has to be <br>
          &gt; checked twice to use this.
          <br>
          &gt;
          <br>
          &gt; There are other ways to do this. You can expose the
          variant member and <br>
          &gt; use a visitor
          <br>
          &gt; but using a visitor feels like overkill for this. Also
          the variant is <br>
          &gt; an internal implementation detail.
          <br>
          &gt; An equally valid implementation would have two different
          optional <br>
          &gt; members (but would not enforce their mutual exclusivity).
          <br>
          &gt;
          <br>
          &gt; So do we need (or is there already) something kind of
          like:
          <br>
          &gt;
          <br>
          &gt; =C2=A0=C2=A0=C2=A0 std::optional&lt;std::string&gt; getStrin=
g() const
          <br>
          &gt; =C2=A0=C2=A0=C2=A0 {
          <br>
          &gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return make_optio=
nal&lt;std::string&gt;(<wbr>this-&gt;bar);
          <br>
          &gt; =C2=A0=C2=A0=C2=A0 }
          <br>
          &gt;
          <br>
          &gt; or bikeshedding:
          <br>
          &gt;
          <br>
          &gt; =C2=A0=C2=A0=C2=A0 std::optional&lt;std::string&gt; getStrin=
g() const
          <br>
          &gt; =C2=A0=C2=A0=C2=A0 {
          <br>
          &gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return to_optiona=
l&lt;std::string&gt;(this-<wbr>&gt;bar);
          <br>
          &gt; =C2=A0=C2=A0=C2=A0 }
          <br>
          &gt;
          <br>
          <br>
          The conversion is simple, but we don't need to do the
          conversion until <br>
          requested. We can see a variant&lt;Ts...&gt; as some kind of
          ValueOrNone type <br>
          (that can not change of alternative) once we select one of the
          <br>
          alternatives T. Lets name this function
          select&lt;T&gt;(SumType).
          <br>
          <br>
          The conversion would be done only when requested, e.g. by an
          implicit <br>
          conversion.
          <br>
          <br>
          =C2=A0=C2=A0=C2=A0=C2=A0 optional&lt;T&gt; o =3D select&lt;T&gt;(=
SumType);
          <br>
          <br>
          <br>
          However, we could as well
          <br>
          <br>
          =C2=A0=C2=A0=C2=A0=C2=A0 auto von =3D select&lt;T&gt;(SumType);
          <br>
          <br>
          von is not an optional&lt;T&gt;. It is something else, a
          reference to a <br>
          sum-type, with the perspective of only one of the
          alternatives. Now we <br>
          can use von as a ValueOrNone, with the usual von.has_value()
          and *von. <br>
          Note that these functions don't need to check the type twice:
          <br>
          =C2=A0=C2=A0=C2=A0=C2=A0 von.has_value() should be equivalent to
          std::get_if&lt;T&gt;(&amp;von) and
          <br>
          =C2=A0=C2=A0=C2=A0=C2=A0 *von equivalent to std::get&lt;T&gt;(von=
).
          <br>
          <br>
          <br>
          <br>
        </blockquote>
        <div>I very much like the name select.<br>
          <br>
          I see your argument that a ValueOrNone isn't strictly an
          optional but if it isn't don't we complicate the language<br>
          with yet another "maybe" type? Wouldn't the language be
          cleaner with just one?<br>
          I guess the answer is adding optional references as previously
          mentioned?<br>
          <br>
        </div>
      </div>
    </blockquote>
    Well, with the select function, you don't need to do any conversion,
    even not to optional&lt;T&amp;&gt;. Note that the type obtained with
    select, can be an implementation detail. We don't have to name it.
    And of course, it can be convertible to optional&lt;T&gt; or
    optional&lt;T&amp;&gt; if we had it.<br>
    <br>
    Vicente<br>
    <br>
    P.S. I've a variadic select that applied to std::any results in a
    sum type that is equivalent to a nullable variant. <br>
    <br>
    <br>
    std::any a;<br>
    auto v =3D select&lt;T1, ..., Tn&gt;(a); // equivalent to
    variant&lt;none_t, T1&amp;, ..., Tn&amp;&gt;<br>
    <br>
    Once we have done that, we can visit a std::any :) <br>
    The problem is that the complexity is not O(1) but O(n) :(<br>
    <br>
    <br>
  </body>
</html>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/c30c63a6-7695-b0be-7d3e-b57f1ed481b0%=
40wanadoo.fr?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/c30c63a6-7695-b0be-7d3e-b57f1ed481b0=
%40wanadoo.fr</a>.<br />

--------------FEEA91565658746D77502380--

.