Topic: Shouldn't std::optional be a container?
Author: Giovanni Piero Deretta <gpderetta@gmail.com>
Date: Wed, 1 Jun 2016 14:35:45 -0700 (PDT)
Raw View
------=_Part_5_1781829638.1464816945254
Content-Type: multipart/alternative;
boundary="----=_Part_6_1424122992.1464816945254"
------=_Part_6_1424122992.1464816945254
Content-Type: text/plain; charset=UTF-8
std::optional is often described as a container of at most one element, but
it lacks the required iterator accessors to actually make it a proper
range. Should the proper std::{,c,r,cr}{begin,end} specializations be added
to the standard?
In the immediate it would make the following possible:
std::optional<int> getSomethingMaybeOptionally();
...
for(auto x: getSomethingMaybe())
{
// do something in x if optx is non empty
}
In the future there is the possibility of very nice interactions with range
view adaptors a-la boost.range.
I should probably add something about optional being a monad and thus
needing to support similar monadic operators as the other containers, but I
will abstain.
-- gpd
--
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/3d343a85-2c51-4c86-98be-e91b0d449e20%40isocpp.org.
------=_Part_6_1424122992.1464816945254
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">std::optional is often described as a container of at most=
one element, but it lacks the required iterator accessors to actually make=
it a proper range. Should the proper std::{,c,r,cr}{begin,end} specializat=
ions be added to the standard?<br><br>In the immediate it would make the fo=
llowing possible:<br><br>=C2=A0 std::optional<int> getSomethingMaybeO=
ptionally();<br><br>=C2=A0 ...<br>=C2=A0 for(auto x: getSomethingMaybe())<b=
r>=C2=A0 {<br>=C2=A0=C2=A0=C2=A0=C2=A0 // do something in x if optx is non =
empty<br>=C2=A0 }<br><br>In the future there is the possibility of very nic=
e interactions with range view adaptors a-la boost.range.<br><br>I should p=
robably add something about optional being a monad and thus needing to supp=
ort similar monadic operators as the other containers, but I will abstain.<=
br><br>-- gpd<br></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <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/3d343a85-2c51-4c86-98be-e91b0d449e20%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/3d343a85-2c51-4c86-98be-e91b0d449e20=
%40isocpp.org</a>.<br />
------=_Part_6_1424122992.1464816945254--
------=_Part_5_1781829638.1464816945254--
.
Author: "'Matt Calabrese' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Wed, 1 Jun 2016 14:45:15 -0700
Raw View
--94eb2c1244feb8d0da05343e670b
Content-Type: text/plain; charset=UTF-8
On Wed, Jun 1, 2016 at 2:35 PM, Giovanni Piero Deretta <gpderetta@gmail.com>
wrote:
> std::optional is often described as a container of at most one element,
> but it lacks the required iterator accessors to actually make it a proper
> range. Should the proper std::{,c,r,cr}{begin,end} specializations be added
> to the standard?
>
> In the immediate it would make the following possible:
>
> std::optional<int> getSomethingMaybeOptionally();
>
> ...
> for(auto x: getSomethingMaybe())
> {
> // do something in x if optx is non empty
> }
>
> In the future there is the possibility of very nice interactions with
> range view adaptors a-la boost.range.
>
> I should probably add something about optional being a monad and thus
> needing to support similar monadic operators as the other containers, but I
> will abstain.
>
I definitely agree that there should be a way to get a range into an
optional, where the range is size 0 or 1. Whether or not optional itself
models one of the standard container concepts seems separate, though, and I
imagine that there would be more controversy there. In other words, I see
no problem with having something along the lines of:
std::optional<int> my_optional;
for(auto x: range_view_into(my_optional))
{
// do something in x if optx is non empty
}
This allows use of standard range-based algorithms. It doesn't require
intrusively making "my_optional" a model of container, though.
--
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/CANh8DEk-ecxwXAkLD5Cr8iRDsnj%2B1qQMKbVFfZ5L%3Daew8vdosw%40mail.gmail.com.
--94eb2c1244feb8d0da05343e670b
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On W=
ed, Jun 1, 2016 at 2:35 PM, Giovanni Piero Deretta <span dir=3D"ltr"><<a=
href=3D"mailto:gpderetta@gmail.com">gpderetta@gmail.com</a>></span> wro=
te:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;=
border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204=
,204);padding-left:1ex"><div dir=3D"ltr">std::optional is often described a=
s a container of at most one element, but it lacks the required iterator ac=
cessors to actually make it a proper range. Should the proper std::{,c,r,cr=
}{begin,end} specializations be added to the standard?<br><br>In the immedi=
ate it would make the following possible:<br><br>=C2=A0 std::optional<in=
t> getSomethingMaybeOptionally();<br><br>=C2=A0 ...<br>=C2=A0 for(auto x=
: getSomethingMaybe())<br>=C2=A0 {<br>=C2=A0=C2=A0=C2=A0=C2=A0 // do someth=
ing in x if optx is non empty<br>=C2=A0 }<br><br>In the future there is the=
possibility of very nice interactions with range view adaptors a-la boost.=
range.<br><br>I should probably add something about optional being a monad =
and thus needing to support similar monadic operators as the other containe=
rs, but I will abstain.</div></blockquote><div><br></div><div>I definitely =
agree that there should be a way to get a range into an optional, where the=
range is size 0 or 1. Whether or not optional itself models one of the sta=
ndard container concepts seems separate, though, and I imagine that there w=
ould be more controversy there. In other words, I see no problem with havin=
g something along the lines of:</div><div><br></div><div>=C2=A0 std::option=
al<int> my_optional;<br>=C2=A0 for(auto x: range_view_into(my_optiona=
l))<br>=C2=A0 {<br>=C2=A0=C2=A0=C2=A0=C2=A0 // do something in x if optx is=
non empty<br>=C2=A0 }</div><div><br></div><div>This allows use of standard=
range-based algorithms. It doesn't require intrusively making "my=
_optional" a model of container, though.</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" 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/CANh8DEk-ecxwXAkLD5Cr8iRDsnj%2B1qQMKb=
VFfZ5L%3Daew8vdosw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CANh8DEk-ecxw=
XAkLD5Cr8iRDsnj%2B1qQMKbVFfZ5L%3Daew8vdosw%40mail.gmail.com</a>.<br />
--94eb2c1244feb8d0da05343e670b--
.
Author: Zhihao Yuan <zy@miator.net>
Date: Wed, 1 Jun 2016 16:44:53 -0500
Raw View
On Wed, Jun 1, 2016 at 4:35 PM, Giovanni Piero Deretta
<gpderetta@gmail.com> wrote:
>
> std::optional<int> getSomethingMaybeOptionally();
>
> ...
> for(auto x: getSomethingMaybe())
> {
> // do something in x if optx is non empty
> }
Not necessary. Actually I wrote a utility to allow
for (auto&& x : if_present(getSomethingMaybeOptionally()))
{
...
}
work for all Nullable types, not just std::optional.
--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://blog.miator.net/
--
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/CAGsORuDsWZA9x_Ck1ZtreteNF74hqxi9QZnceoE2ci%2B-uNEpUA%40mail.gmail.com.
.
Author: Tony V E <tvaneerd@gmail.com>
Date: Wed, 01 Jun 2016 19:34:30 -0400
Raw View
<html><head></head><body lang=3D"en-US" style=3D"background-color: rgb(255,=
255, 255); line-height: initial;"> =
<div style=3D"width: 100%; fo=
nt-size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif=
; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, =
255, 255);">I think the 'Container of at most one' is a bad model for optio=
nal. (and I've thought about optional waaaaay too much)</div><div style=3D"=
width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-se=
rif, sans-serif; color: rgb(31, 73, 125); text-align: initial; background-c=
olor: rgb(255, 255, 255);"><br></div><div style=3D"width: 100%; font-size: =
initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color: =
rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255)=
;">Containers don't have comparisons to there value type. ie</div><div styl=
e=3D"width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sa=
ns-serif, sans-serif; color: rgb(31, 73, 125); text-align: initial; backgro=
und-color: rgb(255, 255, 255);"><br></div><div style=3D"width: 100%; font-s=
ize: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; co=
lor: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255,=
255);"> vector<int>{} <=3D 17; // doesn't compile</d=
iv><div style=3D"width: 100%; font-size: initial; font-family: Calibri, 'Sl=
ate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); text-align: init=
ial; background-color: rgb(255, 255, 255);"> optional <int&=
gt;{} <=3D 17; // compiles</div><div style=3D"width: 100%; font-size: in=
itial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rg=
b(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);"=
><br></div><div style=3D"width: 100%; font-size: initial; font-family: Cali=
bri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); text-ali=
gn: initial; background-color: rgb(255, 255, 255);">Optional is a Wrapper t=
ype. It tries to b like the type it wraps. </div><div style=3D"width: 100%;=
font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-se=
rif; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(25=
5, 255, 255);">(if/when we get operator dot, optional may become even more =
like T or a 'smart wrapper' similar to a smart pointer.)</div><div style=3D=
"width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-s=
erif, sans-serif; color: rgb(31, 73, 125); text-align: initial; background-=
color: rgb(255, 255, 255);"><br></div><div style=3D"width: 100%; font-size:=
initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color:=
rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255=
);">A good model for optional is 'T with one more (smallest) value'. This i=
s how < is defined for optional. </div><div style=3D"width: 100%; f=
ont-size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-seri=
f; color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255,=
255, 255);"><br></div><div style=3D"width: 100%; font-size: initial; font-=
family: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(31, 73, 12=
5); text-align: initial; background-color: rgb(255, 255, 255);">The actual =
best model for optional is 'maybe not constructed yet T (with unconstructed=
being smallest)'. Any other model tends to get optional assignment w=
rong. (optional assignment constructs if not constructed yet, else assigns.=
For most types, the result is the same, but not for all types)</div><div s=
tyle=3D"width: 100%; font-size: initial; font-family: Calibri, 'Slate Pro',=
sans-serif, sans-serif; color: rgb(31, 73, 125); text-align: initial; back=
ground-color: rgb(255, 255, 255);"><br></div><div style=3D"width: 100%; fon=
t-size: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif;=
color: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 2=
55, 255);">Alternatively, if there is a better model for optional, then we =
specified something that doesn't match that model. </div><div style=3D"widt=
h: 100%; font-size: initial; font-family: Calibri, 'Slate Pro', sans-serif,=
sans-serif; color: rgb(31, 73, 125); text-align: initial; background-color=
: rgb(255, 255, 255);"><br></div><div style=3D"width: 100%; font-size: init=
ial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(=
31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);">=
=E2=80=8EI do like the idea of a range-adapter that turns optional into a r=
ange. It (or similar) should also turn T into a range (of exactly one). ie =
as_range(17) is a range of one int. Of course you then get ambiguity with a=
s_range(optional_int) - is that a range of 0 or 1 int or a range of one opt=
ional<int>, or somehow both?</div><div style=3D"width: 100%; font-siz=
e: initial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; colo=
r: rgb(31, 73, 125); text-align: initial; background-color: rgb(255, 255, 2=
55);"><br></div> =
<=
div style=3D"width: 100%; font-size: initial; font-family: Calibri, 'Slate =
Pro', sans-serif, sans-serif; color: rgb(31, 73, 125); text-align: initial;=
background-color: rgb(255, 255, 255);"><br style=3D"display:initial"></div=
> =
=
<div style=3D"font-size: init=
ial; font-family: Calibri, 'Slate Pro', sans-serif, sans-serif; color: rgb(=
31, 73, 125); text-align: initial; background-color: rgb(255, 255, 255);">S=
ent from my BlackBerry portable Babbage Devic=
e</div> =
=
<table width=3D"100%" style=3D"backgroun=
d-color:white;border-spacing:0px;"> <tbody><tr><td colspan=3D"2" style=3D"f=
ont-size: initial; text-align: initial; background-color: rgb(255, 255, 255=
);"> <div style=3D"border-style: solid none none;=
border-top-color: rgb(181, 196, 223); border-top-width: 1pt; padding: 3pt =
0in 0in; font-family: Tahoma, 'BB Alpha Sans', 'Slate Pro'; font-size: 10pt=
;"> <div><b>From: </b>Giovanni Piero Deretta</div><div><b>Sent: </b>Wednes=
day, June 1, 2016 5:35 PM</div><div><b>To: </b>ISO C++ Standard - Future Pr=
oposals</div><div><b>Reply To: </b>std-proposals@isocpp.org</div><div><b>Su=
bject: </b>[std-proposals] Shouldn't std::optional be a container?</div></d=
iv></td></tr></tbody></table><div style=3D"border-style: solid none none; b=
order-top-color: rgb(186, 188, 209); border-top-width: 1pt; font-size: init=
ial; text-align: initial; background-color: rgb(255, 255, 255);"></div><br>=
<div id=3D"_originalContent" style=3D""><div dir=3D"ltr">std::optional is o=
ften described as a container of at most one element, but it lacks the requ=
ired iterator accessors to actually make it a proper range. Should the prop=
er std::{,c,r,cr}{begin,end} specializations be added to the standard?<br><=
br>In the immediate it would make the following possible:<br><br> std=
::optional<int> getSomethingMaybeOptionally();<br><br> ...<br>&=
nbsp; for(auto x: getSomethingMaybe())<br> {<br> &nb=
sp; // do something in x if optx is non empty<br> }<br><br>In the fut=
ure there is the possibility of very nice interactions with range view adap=
tors a-la boost.range.<br><br>I should probably add something about optiona=
l being a monad and thus needing to support similar monadic operators as th=
e other containers, but I will abstain.<br><br>-- gpd<br></div>
<p></p>
-- <br>
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" 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/3d343a85-2c51-4c86-98be-e91b0d449e20%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.goo=
gle.com/a/isocpp.org/d/msgid/std-proposals/3d343a85-2c51-4c86-98be-e91b0d44=
9e20%40isocpp.org</a>.<br>
<br><!--end of _originalContent --></div></body></html>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <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/20160601233430.4874320.91355.11550%40=
gmail.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.com=
/a/isocpp.org/d/msgid/std-proposals/20160601233430.4874320.91355.11550%40gm=
ail.com</a>.<br />
.
Author: "'Matt Calabrese' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Wed, 1 Jun 2016 17:24:45 -0700
Raw View
--001a114267aa2665d3053440a2e2
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Wed, Jun 1, 2016 at 4:34 PM, Tony V E <tvaneerd@gmail.com> wrote:
>
> =E2=80=8EI do like the idea of a range-adapter that turns optional into a=
range.
> It (or similar) should also turn T into a range (of exactly one). ie
> as_range(17) is a range of one int.
>
+1 I think the ranges effort actually has that kind of a singular range
already, but I could be mis-remembering.
On Wed, Jun 1, 2016 at 4:34 PM, Tony V E <tvaneerd@gmail.com> wrote:
> Of course you then get ambiguity with as_range(optional_int) - is that a
> range of 0 or 1 int or a range of one optional<int>, or somehow both?
>
Yeah, it shouldn't use the same named function as that breaks generic code
and is also really confusing even when not in generic code. A simple
example of this is when you are in a generic function:
template <class T>
void foo(T arg) {
// The following shouldn't do something semantically different
// in cases where T just happens to resolve to optional<U>.
some_algorithm_taking_a_range(as_range(arg));
}
--=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/CANh8DEkLAKX3UaWHAo2%2BtueOKkrnYkaT76eiXk6gNBS6v=
P05Ag%40mail.gmail.com.
--001a114267aa2665d3053440a2e2
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On W=
ed, Jun 1, 2016 at 4:34 PM, Tony V E <span dir=3D"ltr"><<a href=3D"mailt=
o:tvaneerd@gmail.com">tvaneerd@gmail.com</a>></span> wrote:<blockquote c=
lass=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1p=
x;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1=
ex"><div lang=3D"en-US" style=3D"line-height:initial;background-color:rgb(2=
55,255,255)"><div style=3D"width:100%;font-size:initial;font-family:calibri=
,'slate pro',sans-serif,sans-serif;color:rgb(31,73,125);text-align:=
initial;background-color:rgb(255,255,255)">=E2=80=8EI do like the idea of a=
range-adapter that turns optional into a range. It (or similar) should als=
o turn T into a range (of exactly one). ie as_range(17) is a range of one i=
nt.</div></div></blockquote><div><br></div><div>+1 I think the ranges effor=
t actually has that kind of a singular range already, but I could be mis-re=
membering.</div><div><br></div><div>=C2=A0On Wed, Jun 1, 2016 at 4:34 PM, T=
ony V E=C2=A0<span dir=3D"ltr"><<a href=3D"mailto:tvaneerd@gmail.com">tv=
aneerd@gmail.com</a>></span>=C2=A0wrote:</div><blockquote class=3D"gmail=
_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left=
-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div lang=
=3D"en-US" style=3D"line-height:initial;background-color:rgb(255,255,255)">=
<div style=3D"width:100%;font-size:initial;font-family:calibri,'slate p=
ro',sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;backg=
round-color:rgb(255,255,255)"> Of course you then get ambiguity with as_ran=
ge(optional_int) - is that a range of 0 or 1 int or a range of one optional=
<int>, or somehow both?</div></div></blockquote><div><br></div><div>Y=
eah, it shouldn't use the same named function as that breaks generic co=
de and is also really confusing even when not in generic code. A simple exa=
mple of this is when you are in a generic function:</div><div><br></div><di=
v>template <class T></div><div>void foo(T arg) {</div><div>=C2=A0 // =
The following shouldn't do something semantically different</div><div>=
=C2=A0 // in cases where T just happens to resolve to optional<U>.</d=
iv><div>=C2=A0 some_algorithm_taking_a_range(as_range(arg));</div><div>}</d=
iv></div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <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/CANh8DEkLAKX3UaWHAo2%2BtueOKkrnYkaT76=
eiXk6gNBS6vP05Ag%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CANh8DEkLAKX3Ua=
WHAo2%2BtueOKkrnYkaT76eiXk6gNBS6vP05Ag%40mail.gmail.com</a>.<br />
--001a114267aa2665d3053440a2e2--
.
Author: =?UTF-8?Q?Andrzej_Krzemie=C5=84ski?= <akrzemi1@gmail.com>
Date: Thu, 2 Jun 2016 01:33:52 -0700 (PDT)
Raw View
------=_Part_405_2007214923.1464856432304
Content-Type: multipart/alternative;
boundary="----=_Part_406_1005481460.1464856432305"
------=_Part_406_1005481460.1464856432305
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
W dniu =C5=9Broda, 1 czerwca 2016 23:45:21 UTC+2 u=C5=BCytkownik Matt Calab=
rese=20
napisa=C5=82:
>
> On Wed, Jun 1, 2016 at 2:35 PM, Giovanni Piero Deretta <gpde...@gmail.com=
=20
> <javascript:>> wrote:
>
>> std::optional is often described as a container of at most one element,=
=20
>> but it lacks the required iterator accessors to actually make it a prope=
r=20
>> range. Should the proper std::{,c,r,cr}{begin,end} specializations be ad=
ded=20
>> to the standard?
>>
>> In the immediate it would make the following possible:
>>
>> std::optional<int> getSomethingMaybeOptionally();
>>
>> ...
>> for(auto x: getSomethingMaybe())
>> {
>> // do something in x if optx is non empty
>> }
>>
>> In the future there is the possibility of very nice interactions with=20
>> range view adaptors a-la boost.range.
>>
>> I should probably add something about optional being a monad and thus=20
>> needing to support similar monadic operators as the other containers, bu=
t I=20
>> will abstain.
>>
>
> I definitely agree that there should be a way to get a range into an=20
> optional, where the range is size 0 or 1. Whether or not optional itself=
=20
> models one of the standard container concepts seems separate, though, and=
I=20
> imagine that there would be more controversy there. In other words, I see=
=20
> no problem with having something along the lines of:
>
> std::optional<int> my_optional;
> for(auto x: range_view_into(my_optional))
> {
> // do something in x if optx is non empty
> }
>
> This allows use of standard range-based algorithms. It doesn't require=20
> intrusively making "my_optional" a model of container, though.
>
But which standard algorithms would you use on std::optional in practice?=
=20
sort, partition, find_if? The only one I can think of is for_each, and this=
=20
one can be sufficiently emulated with:
if (my_optional)
// do something with *my_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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/16fe08f1-657d-438f-8b9c-b85e69207e06%40isocpp.or=
g.
------=_Part_406_1005481460.1464856432305
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>W dniu =C5=9Broda, 1 czerwca 2016 23:45:21 UTC+2 u=
=C5=BCytkownik Matt Calabrese napisa=C5=82:<blockquote class=3D"gmail_quote=
" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding=
-left: 1ex;"><div dir=3D"ltr"><div><div class=3D"gmail_quote">On Wed, Jun 1=
, 2016 at 2:35 PM, Giovanni Piero Deretta <span dir=3D"ltr"><<a href=3D"=
javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"mfI6yCwiDAAJ" rel=
=3D"nofollow" onmousedown=3D"this.href=3D'javascript:';return true;=
" onclick=3D"this.href=3D'javascript:';return true;">gpde...@gmail.=
com</a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"mar=
gin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-=
left-color:rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr">std::optiona=
l is often described as a container of at most one element, but it lacks th=
e required iterator accessors to actually make it a proper range. Should th=
e proper std::{,c,r,cr}{begin,end} specializations be added to the standard=
?<br><br>In the immediate it would make the following possible:<br><br>=C2=
=A0 std::optional<int> getSomethingMaybeOptionally();<br><br>=C2=A0 .=
...<br>=C2=A0 for(auto x: getSomethingMaybe())<br>=C2=A0 {<br>=C2=A0=C2=A0=
=C2=A0=C2=A0 // do something in x if optx is non empty<br>=C2=A0 }<br><br>I=
n the future there is the possibility of very nice interactions with range =
view adaptors a-la boost.range.<br><br>I should probably add something abou=
t optional being a monad and thus needing to support similar monadic operat=
ors as the other containers, but I will abstain.</div></blockquote><div><br=
></div><div>I definitely agree that there should be a way to get a range in=
to an optional, where the range is size 0 or 1. Whether or not optional its=
elf models one of the standard container concepts seems separate, though, a=
nd I imagine that there would be more controversy there. In other words, I =
see no problem with having something along the lines of:</div><div><br></di=
v><div>=C2=A0 std::optional<int> my_optional;<br>=C2=A0 for(auto x: r=
ange_view_into(my_optional))<br>=C2=A0 {<br>=C2=A0=C2=A0=C2=A0=C2=A0 // do =
something in x if optx is non empty<br>=C2=A0 }</div><div><br></div><div>Th=
is allows use of standard range-based algorithms. It doesn't require in=
trusively making "my_optional" a model of container, though.</div=
></div></div></div></blockquote><div><br>But which standard algorithms woul=
d you use on std::optional in practice? sort, partition, find_if? The only =
one I can think of is for_each, and this one can be sufficiently emulated w=
ith:<br><br>=C2=A0 if (my_optional)<br>=C2=A0=C2=A0 // do something with *m=
y_optional <br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <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/16fe08f1-657d-438f-8b9c-b85e69207e06%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/16fe08f1-657d-438f-8b9c-b85e69207e06=
%40isocpp.org</a>.<br />
------=_Part_406_1005481460.1464856432305--
------=_Part_405_2007214923.1464856432304--
.
Author: Giovanni Piero Deretta <gpderetta@gmail.com>
Date: Thu, 2 Jun 2016 03:36:52 -0700 (PDT)
Raw View
------=_Part_688_669247144.1464863812421
Content-Type: multipart/alternative;
boundary="----=_Part_689_1857214692.1464863812421"
------=_Part_689_1857214692.1464863812421
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Thursday, June 2, 2016 at 9:33:52 AM UTC+1, Andrzej Krzemie=C5=84ski wro=
te:
>
>
>
> W dniu =C5=9Broda, 1 czerwca 2016 23:45:21 UTC+2 u=C5=BCytkownik Matt Cal=
abrese=20
> napisa=C5=82:
>>
>> On Wed, Jun 1, 2016 at 2:35 PM, Giovanni Piero Deretta <gpde...@gmail.co=
m
>> > wrote:
>>
>>> std::optional is often described as a container of at most one element,=
=20
>>> but it lacks the required iterator accessors to actually make it a prop=
er=20
>>> range. Should the proper std::{,c,r,cr}{begin,end} specializations be a=
dded=20
>>> to the standard?
>>>
>>> In the immediate it would make the following possible:
>>>
>>> std::optional<int> getSomethingMaybeOptionally();
>>>
>>>
Of the standard algos, possibly the set algos (union, intersection,=20
difference, etc) would be the most interesting, but what I had in mind are=
=20
the range views a-la boost.range: zip, map, filter. Also a range compatible=
=20
'optional' would be a good result type for many range algorithms (for=20
example head, binary search, etc).
=20
> ...
>>> for(auto x: getSomethingMaybe())
>>> {
>>> // do something in x if optx is non empty
>>> }
>>>
>>> In the future there is the possibility of very nice interactions with=
=20
>>> range view adaptors a-la boost.range.
>>>
>>> I should probably add something about optional being a monad and thus=
=20
>>> needing to support similar monadic operators as the other containers, b=
ut I=20
>>> will abstain.
>>>
>>
>> I definitely agree that there should be a way to get a range into an=20
>> optional, where the range is size 0 or 1. Whether or not optional itself=
=20
>> models one of the standard container concepts seems separate, though, an=
d I=20
>> imagine that there would be more controversy there. In other words, I se=
e=20
>> no problem with having something along the lines of:
>>
>> std::optional<int> my_optional;
>> for(auto x: range_view_into(my_optional))
>> {
>> // do something in x if optx is non empty
>> }
>>
>> This allows use of standard range-based algorithms. It doesn't require=
=20
>> intrusively making "my_optional" a model of container, though.
>>
>
> But which standard algorithms would you use on std::optional in practice?=
=20
> sort, partition, find_if? The only one I can think of is for_each, and th=
is=20
> one can be sufficiently emulated with:
>
> if (my_optional)
> // do something with *my_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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/6e40dbcc-e2e2-432f-9230-a32195ea8e8f%40isocpp.or=
g.
------=_Part_689_1857214692.1464863812421
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Thursday, June 2, 2016 at 9:33:52 AM UTC+1, Andrzej Krz=
emie=C5=84ski wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;ma=
rgin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr"><br><br>W dniu =C5=9Broda, 1 czerwca 2016 23:45:21 UTC+2 u=C5=BCyt=
kownik Matt Calabrese napisa=C5=82:<blockquote class=3D"gmail_quote" style=
=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"=
><div dir=3D"ltr"><div><div class=3D"gmail_quote">On Wed, Jun 1, 2016 at 2:=
35 PM, Giovanni Piero Deretta <span dir=3D"ltr"><<a rel=3D"nofollow">gpd=
e...@gmail.com</a>></span> wrote:<br><blockquote class=3D"gmail_quote" s=
tyle=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:so=
lid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr">s=
td::optional is often described as a container of at most one element, but =
it lacks the required iterator accessors to actually make it a proper range=
.. Should the proper std::{,c,r,cr}{begin,end} specializations be added to t=
he standard?<br><br>In the immediate it would make the following possible:<=
br><br>=C2=A0 std::optional<int> getSomethingMaybeOptionally();<br><b=
r></div></blockquote></div></div></div></blockquote></div></blockquote><div=
><br>Of the standard algos, possibly the set algos (union, intersection, di=
fference, etc) would be the most interesting, but what I had in mind are th=
e range views a-la boost.range: zip, map, filter. Also a range compatible &=
#39;optional' would be a good result type for many range algorithms (fo=
r example head, binary search, etc).<br><br>=C2=A0</div><blockquote class=
=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #cc=
c solid;padding-left: 1ex;"><div dir=3D"ltr"><blockquote class=3D"gmail_quo=
te" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-=
left:1ex"><div dir=3D"ltr"><div><div class=3D"gmail_quote"><blockquote clas=
s=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;b=
order-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"=
><div dir=3D"ltr">=C2=A0 ...<br>=C2=A0 for(auto x: getSomethingMaybe())<br>=
=C2=A0 {<br>=C2=A0=C2=A0=C2=A0=C2=A0 // do something in x if optx is non em=
pty<br>=C2=A0 }<br><br>In the future there is the possibility of very nice =
interactions with range view adaptors a-la boost.range.<br><br>I should pro=
bably add something about optional being a monad and thus needing to suppor=
t similar monadic operators as the other containers, but I will abstain.</d=
iv></blockquote><div><br></div><div>I definitely agree that there should be=
a way to get a range into an optional, where the range is size 0 or 1. Whe=
ther or not optional itself models one of the standard container concepts s=
eems separate, though, and I imagine that there would be more controversy t=
here. In other words, I see no problem with having something along the line=
s of:</div><div><br></div><div>=C2=A0 std::optional<int> my_optional;=
<br>=C2=A0 for(auto x: range_view_into(my_optional))<br>=C2=A0 {<br>=C2=A0=
=C2=A0=C2=A0=C2=A0 // do something in x if optx is non empty<br>=C2=A0 }</d=
iv><div><br></div><div>This allows use of standard range-based algorithms. =
It doesn't require intrusively making "my_optional" a model o=
f container, though.</div></div></div></div></blockquote><div><br>But which=
standard algorithms would you use on std::optional in practice? sort, part=
ition, find_if? The only one I can think of is for_each, and this one can b=
e sufficiently emulated with:<br><br>=C2=A0 if (my_optional)<br>=C2=A0=C2=
=A0 // do something with *my_optional <br></div></div></blockquote></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <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/6e40dbcc-e2e2-432f-9230-a32195ea8e8f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6e40dbcc-e2e2-432f-9230-a32195ea8e8f=
%40isocpp.org</a>.<br />
------=_Part_689_1857214692.1464863812421--
------=_Part_688_669247144.1464863812421--
.
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Thu, 2 Jun 2016 19:15:04 +0200
Raw View
This is a multi-part message in MIME format.
--------------D91493F604C87C2A2AA01D8A
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Le 01/06/2016 =C3=A0 23:45, 'Matt Calabrese' via ISO C++ Standard - Future=
=20
Proposals a =C3=A9crit :
> On Wed, Jun 1, 2016 at 2:35 PM, Giovanni Piero Deretta=20
> <gpderetta@gmail.com <mailto:gpderetta@gmail.com>> wrote:
>
> std::optional is often described as a container of at most one
> element, but it lacks the required iterator accessors to actually
> make it a proper range. Should the proper
> std::{,c,r,cr}{begin,end} specializations be added to the standard?
>
I believe that if what we want to traverse an optional using Range-based=20
for loops we should consider it as a Range but not as a Container.
>
> In the immediate it would make the following possible:
>
> std::optional<int> getSomethingMaybeOptionally();
>
> ...
> for(auto x: getSomethingMaybe())
> {
> // do something in x if optx is non empty
> }
>
> In the future there is the possibility of very nice interactions
> with range view adaptors a-la boost.range.
>
> I should probably add something about optional being a monad and
> thus needing to support similar monadic operators as the other
> containers, but I will abstain.
>
>
> I definitely agree that there should be a way to get a range into an=20
> optional, where the range is size 0 or 1. Whether or not optional=20
> itself models one of the standard container concepts seems separate,=20
> though, and I imagine that there would be more controversy there. In=20
> other words, I see no problem with having something along the lines of:
>
> std::optional<int> my_optional;
> for(auto x: range_view_into(my_optional))
> {
> // do something in x if optx is non empty
> }
>
> This allows use of standard range-based algorithms. It doesn't require=20
> intrusively making "my_optional" a model of container, though.
I don't like this kind of wrappers as either an optional can be seen as=20
a Range or not. There should be no need to add noise.
Why do you believe that it is better to be explicit?
I would like to be able to consider any NullablePointer also as a Range=20
and why not any Nullable [P0196R1]. However the customization point for=20
Ranges-based for loops looks on the associated namespace of the Range,=20
and so we can not SFINAE the overload for some specific Concept.=20
(Please let me know if I'm wrong)
TS Range would have std::range::begin/std::range::end and these=20
functions and could take care of the specializations for some concepts.
But the Ranges-based for loops would need to be changed (backward=20
compatibly) to make direct use of std::range::begin/std::range::end=20
instead. This has the inconvenient that the core language would depend=20
on the library and so we need to change the freestanding implementation.
There is an additional advantage to use=20
std::range::begin/std::range::end. The core language wording would be=20
simpler, as we don't needed anymore to take care of c-arrays and the two=20
current customization points explicitly. This will be moved to the=20
std::range::begin/std::range::end functions.
I recognize that this implies some changes, but I believe that this=20
could be done for STL (Ranges).
The alternatives I see are:
Short-term
* overload begin/end for optional
* wrap optional using as_range or whatever
Long term
* Change the Range-base for loop to make use of=20
std::range::begin/std::range::end and let these functions to take care=20
of some concepts as Nullable.
Now that C++11 is closed I don't see any urgency on short term solutions.
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/8fc73f28-4b67-f064-4ea9-0baf43a99c7f%40wanadoo.f=
r.
--------------D91493F604C87C2A2AA01D8A
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
</head>
<body bgcolor=3D"#FFFFFF" text=3D"#000000">
<div class=3D"moz-cite-prefix">Le 01/06/2016 =C3=A0 23:45, 'Matt Calabr=
ese'
via ISO C++ Standard - Future Proposals a =C3=A9crit=C2=A0:<br>
</div>
<blockquote
cite=3D"mid:CANh8DEk-ecxwXAkLD5Cr8iRDsnj+1qQMKbVFfZ5L=3Daew8vdosw@mail.gmai=
l.com"
type=3D"cite">
<div dir=3D"ltr">
<div class=3D"gmail_extra">
<div class=3D"gmail_quote">On Wed, Jun 1, 2016 at 2:35 PM,
Giovanni Piero Deretta <span dir=3D"ltr"><<a
moz-do-not-send=3D"true" href=3D"mailto:gpderetta@gmail.com=
"><a class=3D"moz-txt-link-abbreviated" href=3D"mailto:gpderetta@gmail.com"=
>gpderetta@gmail.com</a></a>></span>
wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(2=
04,204,204);padding-left:1ex">
<div dir=3D"ltr">std::optional is often described as a
container of at most one element, but it lacks the
required iterator accessors to actually make it a proper
range. Should the proper std::{,c,r,cr}{begin,end}
specializations be added to the standard?<br>
<br>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
I believe that if what we want to traverse an optional using
Range-based for loops we should consider it as a Range but not as a
Container. <br>
<blockquote
cite=3D"mid:CANh8DEk-ecxwXAkLD5Cr8iRDsnj+1qQMKbVFfZ5L=3Daew8vdosw@mail.gmai=
l.com"
type=3D"cite">
<div dir=3D"ltr">
<div class=3D"gmail_extra">
<div class=3D"gmail_quote">
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(2=
04,204,204);padding-left:1ex">
<div dir=3D"ltr">In the immediate it would make the
following possible:<br>
<br>
=C2=A0 std::optional<int>
getSomethingMaybeOptionally();<br>
<br>
=C2=A0 ...<br>
=C2=A0 for(auto x: getSomethingMaybe())<br>
=C2=A0 {<br>
=C2=A0=C2=A0=C2=A0=C2=A0 // do something in x if optx is no=
n empty<br>
=C2=A0 }<br>
<br>
In the future there is the possibility of very nice
interactions with range view adaptors a-la boost.range.<br>
<br>
I should probably add something about optional being a
monad and thus needing to support similar monadic
operators as the other containers, but I will abstain.</div=
>
</blockquote>
<div><br>
</div>
<div>I definitely agree that there should be a way to get a
range into an optional, where the range is size 0 or 1.
Whether or not optional itself models one of the standard
container concepts seems separate, though, and I imagine
that there would be more controversy there. In other
words, I see no problem with having something along the
lines of:</div>
<div><br>
</div>
<div>=C2=A0 std::optional<int> my_optional;<br>
=C2=A0 for(auto x: range_view_into(my_optional))<br>
=C2=A0 {<br>
=C2=A0=C2=A0=C2=A0=C2=A0 // do something in x if optx is non =
empty<br>
=C2=A0 }</div>
<div><br>
</div>
<div>This allows use of standard range-based algorithms. It
doesn't require intrusively making "my_optional" a model
of container, though.</div>
</div>
</div>
</div>
</blockquote>
<br>
I don't like this kind of wrappers as either an optional can be seen
as a Range or not. There should be no need to add noise.<br>
Why do you believe that it is better to be explicit?<br>
<br>
I would like to be able to consider any NullablePointer also as a
Range and why not any Nullable [P0196R1]. However the customization
point for Ranges-based for loops looks on the associated namespace
of the Range, and so we can not=C2=A0 SFINAE the overload for some
specific Concept. (Please let me know if I'm wrong)<br>
TS Range would have std::range::begin/std::range::end and these
functions and could take care of the specializations for some
concepts. <br>
<br>
But the Ranges-based for loops would need to be changed (backward
compatibly) to make direct use of std::range::begin/std::range::end
instead. This has the inconvenient that the core language would
depend on the library and so we need to change the freestanding
implementation.<br>
<br>
There is an additional advantage to use
std::range::begin/std::range::end. The core language wording would
be simpler, as we don't needed anymore to take care of c-arrays and
the two current customization points explicitly. This will be moved
to the std::range::begin/std::range::end functions.=C2=A0 <br>
<br>
I recognize that this implies some changes, but I believe that this
could be done for STL (Ranges).<br>
<br>
The alternatives I see are:<br>
<br>
Short-term <br>
* overload begin/end for optional<br>
* wrap optional using as_range or whatever<br>
=C2=A0 <br>
Long term<br>
* Change the Range-base for loop to make use of
std::range::begin/std::range::end and let these functions to take
care of some concepts as Nullable.<br>
<br>
<br>
Now that C++11 is closed I don't see any urgency on short term
solutions.<br>
<br>
Vicente<br>
</body>
</html>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <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/8fc73f28-4b67-f064-4ea9-0baf43a99c7f%=
40wanadoo.fr?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/8fc73f28-4b67-f064-4ea9-0baf43a99c7f=
%40wanadoo.fr</a>.<br />
--------------D91493F604C87C2A2AA01D8A--
.
Author: "'Matt Calabrese' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Thu, 2 Jun 2016 10:23:12 -0700
Raw View
--001a114267aa5b054505344edc59
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Thu, Jun 2, 2016 at 1:33 AM, Andrzej Krzemie=C5=84ski <akrzemi1@gmail.co=
m>
wrote:
>
> But which standard algorithms would you use on std::optional in practice?
> sort, partition, find_if? The only one I can think of is for_each, and th=
is
> one can be sufficiently emulated with:
>
All of them produce meaningful results and all of them can obviously be
emulated as well, just like for other containers. Of course, if you know
your range is at most one element, you'd probably not *directly* sort it
using std::sort in top-level code, although even those kinds of algorithms
may be applied to such a range as soon as you add one more level of
indirection in generic code. It's very difficult to say "a person would
never want to do that and it would obviously be a user-error." This is a
similar kind of battle I face regarding the Regular void proposal *cough*.
Especially in the ranges TS world, where the range algorithms are easily
composable, making it possible for optional to model a range can be useful.
--=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/CANh8DEmGygGS5sqHRBC6SW%3D39xCmLtoJhGdz6TOO9MN0_=
Gg6oQ%40mail.gmail.com.
--001a114267aa5b054505344edc59
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
hu, Jun 2, 2016 at 1:33 AM, Andrzej Krzemie=C5=84ski <span dir=3D"ltr"><=
<a href=3D"mailto:akrzemi1@gmail.com" target=3D"_blank">akrzemi1@gmail.com<=
/a>></span> wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0 0 =
0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>B=
ut which standard algorithms would you use on std::optional in practice? so=
rt, partition, find_if? The only one I can think of is for_each, and this o=
ne can be sufficiently emulated with:</div></div></blockquote><div><br></di=
v><div>All of them produce meaningful results and all of them can obviously=
be emulated as well, just like for other containers. Of course, if you kno=
w your range is at most one element, you'd probably not *directly* sort=
it using std::sort in top-level code, although even those kinds of algorit=
hms may be applied to such a range as soon as you add one more level of ind=
irection in generic code. It's very difficult to say "a person wou=
ld never want to do that and it would obviously be a user-error." This=
is a similar kind of battle I face regarding the Regular void proposal *co=
ugh*.</div><div><br></div><div>Especially in the ranges TS world, where the=
range algorithms are easily composable, making it possible for optional to=
model a range can be useful.</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" 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/CANh8DEmGygGS5sqHRBC6SW%3D39xCmLtoJhG=
dz6TOO9MN0_Gg6oQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CANh8DEmGygGS5s=
qHRBC6SW%3D39xCmLtoJhGdz6TOO9MN0_Gg6oQ%40mail.gmail.com</a>.<br />
--001a114267aa5b054505344edc59--
.
Author: Nevin Liber <nevin@eviloverlord.com>
Date: Thu, 2 Jun 2016 12:29:42 -0500
Raw View
--94eb2c116456f54e7205344ef5ee
Content-Type: text/plain; charset=UTF-8
On 1 June 2016 at 16:35, Giovanni Piero Deretta <gpderetta@gmail.com> wrote:
> std::optional is often described as a container of at most one element,
> but it lacks the required iterator accessors to actually make it a proper
> range. Should the proper std::{,c,r,cr}{begin,end} specializations be added
> to the standard?
>
+1.
However, there are many different mental models (I wish I had documented
them during the optional debates on the mailing lists way back when) for
optional. When someone has a mental model(s) in their head for what
optional should look like and something proposed doesn't fit that mental
model(s), they will fight you tooth and nail on it.
I still think it would be worth presenting it to LEWG just to get the
definitive answer on it.
--
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%2BM-Q%2B18ifaqxoBMAAFei1%2B0mL%3DXfF3x-3yN-mJ5Di%2B6XA%40mail.gmail.com.
--94eb2c116456f54e7205344ef5ee
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On 1 June 2016 at 16:35, Giovanni Piero Deretta <span dir=
=3D"ltr"><<a href=3D"mailto:gpderetta@gmail.com" target=3D"_blank">gpder=
etta@gmail.com</a>></span> wrote:<br><div class=3D"gmail_extra"><div cla=
ss=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 =
..8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">std::opt=
ional is often described as a container of at most one element, but it lack=
s the required iterator accessors to actually make it a proper range. Shoul=
d the proper std::{,c,r,cr}{begin,end} specializations be added to the stan=
dard?<br></div></blockquote><div><br></div><div>+1.</div><div><br></div><di=
v>However, there are many different mental models (I wish I had documented =
them during the optional debates on the mailing lists way back when) for op=
tional.=C2=A0 When someone has a mental model(s) in their head for what opt=
ional should look like and something proposed doesn't fit that mental m=
odel(s), they will fight you tooth and nail on it.</div><div><br></div><div=
>I still think it would be worth presenting it to LEWG just to get the defi=
nitive answer on it.</div></div>-- <br><div class=3D"gmail_signature" data-=
smartmail=3D"gmail_signature"><div dir=3D"ltr"><div><div dir=3D"ltr"><div>=
=C2=A0Nevin ":-)" Liber=C2=A0 <mailto:<a href=3D"mailto:nevin@=
eviloverlord.com" target=3D"_blank">nevin@eviloverlord.com</a>> =C2=A0+1=
-847-691-1404</div></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" 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%2BM-Q%2B18ifaqxoBMAAFei1%2B0mL=
%3DXfF3x-3yN-mJ5Di%2B6XA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Df=
ooter">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAGg_6%=
2BM-Q%2B18ifaqxoBMAAFei1%2B0mL%3DXfF3x-3yN-mJ5Di%2B6XA%40mail.gmail.com</a>=
..<br />
--94eb2c116456f54e7205344ef5ee--
.
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Thu, 2 Jun 2016 19:35:51 +0200
Raw View
This is a multi-part message in MIME format.
--------------8947738369842B20ECC23998
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Le 02/06/2016 =C3=A0 02:24, 'Matt Calabrese' via ISO C++ Standard - Future=
=20
Proposals a =C3=A9crit :
> On Wed, Jun 1, 2016 at 4:34 PM, Tony V E <tvaneerd@gmail.com=20
> <mailto:tvaneerd@gmail.com>> wrote:
>
> =E2=80=8EI do like the idea of a range-adapter that turns optional in=
to a
> range. It (or similar) should also turn T into a range (of exactly
> one). ie as_range(17) is a range of one int.
>
>
> +1 I think the ranges effort actually has that kind of a singular=20
> range already, but I could be mis-remembering.
Do someone have a pointer?
>
> On Wed, Jun 1, 2016 at 4:34 PM, Tony V E <tvaneerd@gmail.com=20
> <mailto:tvaneerd@gmail.com>> wrote:
>
> Of course you then get ambiguity with as_range(optional_int) - is
> that a range of 0 or 1 int or a range of one optional<int>, or
> somehow both?
>
>
> Yeah, it shouldn't use the same named function as that breaks generic=20
> code and is also really confusing even when not in generic code. A=20
> simple example of this is when you are in a generic function:
>
> template <class T>
> void foo(T arg) {
> // The following shouldn't do something semantically different
> // in cases where T just happens to resolve to optional<U>.
> some_algorithm_taking_a_range(as_range(arg));
> }
as_range should return his parameter if it is already a Range, isn't it?
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/89777ccf-cc7d-408a-ff60-331764faf485%40wanadoo.f=
r.
--------------8947738369842B20ECC23998
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
</head>
<body bgcolor=3D"#FFFFFF" text=3D"#000000">
<div class=3D"moz-cite-prefix">Le 02/06/2016 =C3=A0 02:24, 'Matt Calabr=
ese'
via ISO C++ Standard - Future Proposals a =C3=A9crit=C2=A0:<br>
</div>
<blockquote
cite=3D"mid:CANh8DEkLAKX3UaWHAo2+tueOKkrnYkaT76eiXk6gNBS6vP05Ag@mail.gmail.=
com"
type=3D"cite">
<div dir=3D"ltr">
<div class=3D"gmail_extra">
<div class=3D"gmail_quote">On Wed, Jun 1, 2016 at 4:34 PM, Tony
V E <span dir=3D"ltr"><<a moz-do-not-send=3D"true"
href=3D"mailto:tvaneerd@gmail.com">tvaneerd@gmail.com</a>&g=
t;</span>
wrote:
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(2=
04,204,204);padding-left:1ex">
<div
style=3D"line-height:initial;background-color:rgb(255,255,2=
55)"
lang=3D"en-US">
<div
style=3D"width:100%;font-size:initial;font-family:calibri=
,'slate
pro',sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;backgrou=
nd-color:rgb(255,255,255)">=E2=80=8EI
do like the idea of a range-adapter that turns
optional into a range. It (or similar) should also
turn T into a range (of exactly one). ie as_range(17)
is a range of one int.</div>
</div>
</blockquote>
<div><br>
</div>
<div>+1 I think the ranges effort actually has that kind of
a singular range already, but I could be mis-remembering.</di=
v>
</div>
</div>
</div>
</blockquote>
Do someone have a pointer?<br>
<blockquote
cite=3D"mid:CANh8DEkLAKX3UaWHAo2+tueOKkrnYkaT76eiXk6gNBS6vP05Ag@mail.gmail.=
com"
type=3D"cite">
<div dir=3D"ltr">
<div class=3D"gmail_extra">
<div class=3D"gmail_quote">
<div><br>
</div>
<div>=C2=A0On Wed, Jun 1, 2016 at 4:34 PM, Tony V E=C2=A0<span
dir=3D"ltr"><<a moz-do-not-send=3D"true"
href=3D"mailto:tvaneerd@gmail.com">tvaneerd@gmail.com</a>=
></span>=C2=A0wrote:</div>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(2=
04,204,204);padding-left:1ex">
<div
style=3D"line-height:initial;background-color:rgb(255,255,2=
55)"
lang=3D"en-US">
<div
style=3D"width:100%;font-size:initial;font-family:calibri=
,'slate
pro',sans-serif,sans-serif;color:rgb(31,73,125);text-align:initial;backgrou=
nd-color:rgb(255,255,255)">
Of course you then get ambiguity with
as_range(optional_int) - is that a range of 0 or 1 int
or a range of one optional<int>, or somehow
both?</div>
</div>
</blockquote>
<div><br>
</div>
<div>Yeah, it shouldn't use the same named function as that
breaks generic code and is also really confusing even when
not in generic code. A simple example of this is when you
are in a generic function:</div>
<div><br>
</div>
<div>template <class T></div>
<div>void foo(T arg) {</div>
<div>=C2=A0 // The following shouldn't do something semanticall=
y
different</div>
<div>=C2=A0 // in cases where T just happens to resolve to
optional<U>.</div>
<div>=C2=A0 some_algorithm_taking_a_range(as_range(arg));</div>
<div>}</div>
</div>
</div>
</div>
</blockquote>
as_range should return his parameter if it is already a Range, isn't
it?<br>
<br>
Vicente<br>
</body>
</html>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <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/89777ccf-cc7d-408a-ff60-331764faf485%=
40wanadoo.fr?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/89777ccf-cc7d-408a-ff60-331764faf485=
%40wanadoo.fr</a>.<br />
--------------8947738369842B20ECC23998--
.
Author: "'Matt Calabrese' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Thu, 2 Jun 2016 10:37:57 -0700
Raw View
--94eb2c1244fe2c0dc605344f1104
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Thu, Jun 2, 2016 at 10:15 AM, Vicente J. Botet Escriba <
vicente.botet@wanadoo.fr> wrote:
> Le 01/06/2016 =C3=A0 23:45, 'Matt Calabrese' via ISO C++ Standard - Futur=
e
> Proposals a =C3=A9crit :
>
> On Wed, Jun 1, 2016 at 2:35 PM, Giovanni Piero Deretta <
> <gpderetta@gmail.com>gpderetta@gmail.com> wrote:
>
>> std::optional is often described as a container of at most one element,
>> but it lacks the required iterator accessors to actually make it a prope=
r
>> range. Should the proper std::{,c,r,cr}{begin,end} specializations be ad=
ded
>> to the standard?
>>
>> I believe that if what we want to traverse an optional using Range-based
> for loops we should consider it as a Range but not as a Container.
>
I disagree with that for the reason being that copying an optional copies
the underlying elements. The state of an optional with respect to its copy
operations and comparisons and constness of operations is the element or
the nullopt state.
On Thu, Jun 2, 2016 at 10:15 AM, Vicente J. Botet Escriba <
vicente.botet@wanadoo.fr> wrote:
> In the immediate it would make the following possible:
>>
>> std::optional<int> getSomethingMaybeOptionally();
>>
>> ...
>> for(auto x: getSomethingMaybe())
>> {
>> // do something in x if optx is non empty
>> }
>>
>
That can be made to work even if optional itself isn't a range, though.
On Thu, Jun 2, 2016 at 10:15 AM, Vicente J. Botet Escriba <
vicente.botet@wanadoo.fr> wrote:
> I don't like this kind of wrappers as either an optional can be seen as a
> Range or not. There should be no need to add noise.
> Why do you believe that it is better to be explicit?
>
Because the semantics are different. I don't follow the ranges TS really so
maybe the concepts involved are more subtle now, but I imagine that there
is some kind of a requirement, at least for forward ranges and its
refinements, that when you do something like:
//////////
SomeRange a =3D /*whatever*/;
SomeRange b =3D a;
// This should effectively modify *std::begin(a);
*std::begin(b) =3D /*something new*/;
//////////
That does not hold true for a container, nor for optional.
That said, that doesn't mean that an optional itself needs to model one of
the standard container concepts. That's a separate question. The main thing
that matters is that is useful is being able to get a view into the
optional as a range in some way.
On Thu, Jun 2, 2016 at 10:15 AM, Vicente J. Botet Escriba <
vicente.botet@wanadoo.fr> wrote:
> I would like to be able to consider any NullablePointer also as a Range
> and why not any Nullable [P0196R1].
>
That is a bit different, because there you really do have the expected
semantics modeled regarding copies -- the state of such a pointer is the
pointer value (in other words, the relationship to the element) and not the
target element itself.
--=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/CANh8DEnhLcK66xOFxqvGBCom2_sw%3DHoswFv%2BmNhJoJ_=
TCwRDQw%40mail.gmail.com.
--94eb2c1244fe2c0dc605344f1104
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
hu, Jun 2, 2016 at 10:15 AM, Vicente J. Botet Escriba <span dir=3D"ltr"><=
;<a href=3D"mailto:vicente.botet@wanadoo.fr">vicente.botet@wanadoo.fr</a>&g=
t;</span> wrote:<br><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">
=20
=20
=20
<div bgcolor=3D"#FFFFFF"><span class=3D"gmail-">
<div>Le 01/06/2016 =C3=A0 23:45, 'Matt Calabrese'
via ISO C++ Standard - Future Proposals a =C3=A9crit=C2=A0:<br>
</div>
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div class=3D"gmail_extra">
<div class=3D"gmail_quote">On Wed, Jun 1, 2016 at 2:35 PM,
Giovanni Piero Deretta <span dir=3D"ltr"><<a href=3D"mailto:=
gpderetta@gmail.com"></a><a href=3D"mailto:gpderetta@gmail.com">gpderetta@g=
mail.com</a>></span>
wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0=
..8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(20=
4,204,204);padding-left:1ex">
<div dir=3D"ltr">std::optional is often described as a
container of at most one element, but it lacks the
required iterator accessors to actually make it a proper
range. Should the proper std::{,c,r,cr}{begin,end}
specializations be added to the standard?<br>
<br>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote></span>
I believe that if what we want to traverse an optional using
Range-based for loops we should consider it as a Range but not as a
Container. <br></div></blockquote><div><br></div><div>I disagree with t=
hat for the reason being that copying an optional copies the underlying ele=
ments. The state of an optional with respect to its copy operations and com=
parisons and constness of operations is the element or the nullopt state.</=
div><div><br></div><div>On Thu, Jun 2, 2016 at 10:15 AM, Vicente J. Botet E=
scriba=C2=A0<span dir=3D"ltr"><<a href=3D"mailto:vicente.botet@wanadoo.f=
r">vicente.botet@wanadoo.fr</a>></span>=C2=A0wrote:<br></div><blockquote=
class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:=
1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left=
:1ex"><div bgcolor=3D"#FFFFFF"><span class=3D"gmail-">
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div class=3D"gmail_extra">
<div class=3D"gmail_quote">
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0=
..8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(20=
4,204,204);padding-left:1ex">
<div dir=3D"ltr">In the immediate it would make the
following possible:<br>
<br>
=C2=A0 std::optional<int>
getSomethingMaybeOptionally();<br>
<br>
=C2=A0 ...<br>
=C2=A0 for(auto x: getSomethingMaybe())<br>
=C2=A0 {<br>
=C2=A0=C2=A0=C2=A0=C2=A0 // do something in x if optx is no=
n empty<br>
=C2=A0 }<br></div></blockquote></div></div></div></blockquo=
te></span></div></blockquote><div><br></div><div>That can be made to work e=
ven if optional itself isn't a range, though.<br></div><div><br></div><=
div>On Thu, Jun 2, 2016 at 10:15 AM, Vicente J. Botet Escriba=C2=A0<span di=
r=3D"ltr"><<a href=3D"mailto:vicente.botet@wanadoo.fr">vicente.botet@wan=
adoo.fr</a>></span>=C2=A0wrote:</div><blockquote class=3D"gmail_quote" s=
tyle=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:so=
lid;border-left-color:rgb(204,204,204);padding-left:1ex"><div bgcolor=3D"#F=
FFFFF">
I don't like this kind of wrappers as either an optional can be see=
n
as a Range or not. There should be no need to add noise.<br>
Why do you believe that it is better to be explicit?<br></div></blockqu=
ote><div><br></div><div>Because the semantics are different. I don't fo=
llow the ranges TS really so maybe the concepts involved are more subtle no=
w, but I imagine that there is some kind of a requirement, at least for for=
ward ranges and its refinements, that when you do something like:</div><div=
><br></div><div>//////////</div><div>SomeRange a =3D /*whatever*/;</div><di=
v>SomeRange b =3D a;</div><div><br></div><div>// This should effectively mo=
dify *std::begin(a);</div><div>*std::begin(b) =3D /*something new*/;</div>/=
/////////</div><div class=3D"gmail_quote"><br><div>That does not hold true =
for a container, nor for optional.</div><div><br></div><div>That said, that=
doesn't mean that an optional itself needs to model one of the standar=
d container concepts. That's a separate question. The main thing that m=
atters is that is useful is being able to get a view into the optional as a=
range in some way.</div><div>=C2=A0<br></div><div>On Thu, Jun 2, 2016 at 1=
0:15 AM, Vicente J. Botet Escriba=C2=A0<span dir=3D"ltr"><<a href=3D"mai=
lto:vicente.botet@wanadoo.fr">vicente.botet@wanadoo.fr</a>></span>=C2=A0=
wrote:</div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0=
..8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(20=
4,204,204);padding-left:1ex"><div bgcolor=3D"#FFFFFF">
I would like to be able to consider any NullablePointer also as a
Range and why not any Nullable [P0196R1].</div></blockquote><div><br></=
div><div>That is a bit different, because there you really do have the expe=
cted semantics modeled regarding copies -- the state of such a pointer is t=
he pointer value (in other words, the relationship to the element) and not =
the target element itself.</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" 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/CANh8DEnhLcK66xOFxqvGBCom2_sw%3DHoswF=
v%2BmNhJoJ_TCwRDQw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CANh8DEnhLcK6=
6xOFxqvGBCom2_sw%3DHoswFv%2BmNhJoJ_TCwRDQw%40mail.gmail.com</a>.<br />
--94eb2c1244fe2c0dc605344f1104--
.
Author: "'Matt Calabrese' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Thu, 2 Jun 2016 10:47:35 -0700
Raw View
--94eb2c123f129f05bd05344f3368
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Thu, Jun 2, 2016 at 10:35 AM, Vicente J. Botet Escriba <
vicente.botet@wanadoo.fr> wrote:
> Le 02/06/2016 =C3=A0 02:24, 'Matt Calabrese' via ISO C++ Standard - Futur=
e
> Proposals a =C3=A9crit :
>
> On Wed, Jun 1, 2016 at 4:34 PM, Tony V E <tvaneerd@gmail.com> wrote:
>>
>> =E2=80=8EI do like the idea of a range-adapter that turns optional into =
a range.
>> It (or similar) should also turn T into a range (of exactly one). ie
>> as_range(17) is a range of one int.
>>
>
> +1 I think the ranges effort actually has that kind of a singular range
> already, but I could be mis-remembering.
>
> Do someone have a pointer?
>
Found it:
https://github.com/ericniebler/range-v3/blob/master/include/range/v3/view/s=
ingle.hpp
On Thu, Jun 2, 2016 at 10:35 AM, Vicente J. Botet Escriba <
vicente.botet@wanadoo.fr> wrote:
> as_range should return his parameter if it is already a Range, isn't it?
>
No, they need to be different functions. The one that works with an
optional should just be something specific to an optional. If you have some
adaptor that produces a view of that object as a range of a single element,
it should not change in meaning when you give it a range already, or an
optional, or whatever. If you have a range already, it should produce a
singular range where the sole element of that range is the range that you
pass it (it's a range of ranges). It's for similar reasons that if you pass
an optional<T> to "make_optional", you would *not* want it to produce
optional<T>. Rather, it should produce optional<optional<T>>. They are very
different in meaning, and this can really break generic code (and is also
confusing to users for similar reasons) especially if optional<T> is
actually some template parameter "U", and you don't know whether it is an
optional or not in the given context.
--=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/CANh8DEk2UBzb2zmcaPwf-DZuNpYeMs8U2Vp9CvszMrTii5n=
dng%40mail.gmail.com.
--94eb2c123f129f05bd05344f3368
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
hu, Jun 2, 2016 at 10:35 AM, Vicente J. Botet Escriba <span dir=3D"ltr"><=
;<a href=3D"mailto:vicente.botet@wanadoo.fr">vicente.botet@wanadoo.fr</a>&g=
t;</span> wrote:<br><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">
=20
=20
=20
<div bgcolor=3D"#FFFFFF"><span class=3D"gmail-">
<div>Le 02/06/2016 =C3=A0 02:24, 'Matt Calabrese'
via ISO C++ Standard - Future Proposals a =C3=A9crit=C2=A0:<br>
</div>
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div class=3D"gmail_extra">
<div class=3D"gmail_quote">On Wed, Jun 1, 2016 at 4:34 PM, Tony
V E <span dir=3D"ltr"><<a href=3D"mailto:tvaneerd@gmail.com"=
>tvaneerd@gmail.com</a>></span>
wrote:
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0=
..8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(20=
4,204,204);padding-left:1ex">
<div style=3D"line-height:initial;background-color:rgb(255,25=
5,255)" lang=3D"en-US">
<div>=E2=80=8EI
do like the idea of a range-adapter that turns
optional into a range. It (or similar) should also
turn T into a range (of exactly one). ie as_range(17)
is a range of one int.</div>
</div>
</blockquote>
<div><br>
</div>
<div>+1 I think the ranges effort actually has that kind of
a singular range already, but I could be mis-remembering.</di=
v>
</div>
</div>
</div>
</blockquote></span>
Do someone have a pointer?</div></blockquote><div><br></div><div>Found =
it:</div><div><a href=3D"https://github.com/ericniebler/range-v3/blob/maste=
r/include/range/v3/view/single.hpp">https://github.com/ericniebler/range-v3=
/blob/master/include/range/v3/view/single.hpp</a></div><div><br></div><div>=
On Thu, Jun 2, 2016 at 10:35 AM, Vicente J. Botet Escriba=C2=A0<span dir=3D=
"ltr"><<a href=3D"mailto:vicente.botet@wanadoo.fr">vicente.botet@wanadoo=
..fr</a>></span>=C2=A0wrote:=C2=A0</div><blockquote class=3D"gmail_quote"=
style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:=
solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div bgcolor=3D"=
#FFFFFF"><span class=3D"gmail-"><blockquote type=3D"cite"><div dir=3D"ltr">=
<div class=3D"gmail_extra"><div class=3D"gmail_quote">
</div>
</div>
</div>
</blockquote></span>
as_range should return his parameter if it is already a Range, isn'=
t
it?</div></blockquote><div><br></div><div>No, they need to be different=
functions. The one that works with an optional should just be something sp=
ecific to an optional. If you have some adaptor that produces a view of tha=
t object as a range of a single element, it should not change in meaning wh=
en you give it a range already, or an optional, or whatever. If you have a =
range already, it should produce a singular range where the sole element of=
that range is the range that you pass it (it's a range of ranges). It&=
#39;s for similar reasons that if you pass an optional<T> to "ma=
ke_optional", you would *not* want it to produce optional<T>. Ra=
ther, it should produce optional<optional<T>>. They are very di=
fferent in meaning, and this can really break generic code (and is also con=
fusing to users for similar reasons) especially if optional<T> is act=
ually some template parameter "U", and you don't know whether=
it is an optional or not in the given context.</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" 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/CANh8DEk2UBzb2zmcaPwf-DZuNpYeMs8U2Vp9=
CvszMrTii5ndng%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CANh8DEk2UBzb2zmc=
aPwf-DZuNpYeMs8U2Vp9CvszMrTii5ndng%40mail.gmail.com</a>.<br />
--94eb2c123f129f05bd05344f3368--
.
Author: "'Matt Calabrese' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Thu, 2 Jun 2016 10:50:36 -0700
Raw View
--94eb2c09152661393f05344f3e55
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Thu, Jun 2, 2016 at 10:47 AM, Matt Calabrese <calabrese@google.com>
wrote:
> On Thu, Jun 2, 2016 at 10:35 AM, Vicente J. Botet Escriba <
> vicente.botet@wanadoo.fr> wrote:
>
>> Le 02/06/2016 =C3=A0 02:24, 'Matt Calabrese' via ISO C++ Standard - Futu=
re
>> Proposals a =C3=A9crit :
>>
>> On Wed, Jun 1, 2016 at 4:34 PM, Tony V E <tvaneerd@gmail.com> wrote:
>>>
>>> =E2=80=8EI do like the idea of a range-adapter that turns optional into=
a range.
>>> It (or similar) should also turn T into a range (of exactly one). ie
>>> as_range(17) is a range of one int.
>>>
>>
>> +1 I think the ranges effort actually has that kind of a singular range
>> already, but I could be mis-remembering.
>>
>> Do someone have a pointer?
>>
>
> Found it:
>
> https://github.com/ericniebler/range-v3/blob/master/include/range/v3/view=
/single.hpp
>
Hrm. This seems to imply a deep copy :/ That is... unfortunate.
--=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/CANh8DEk0tb7-_eA%2Bg4DDhp_nCCsKLrgv%3D5WFjSGzR45=
tGBpwHA%40mail.gmail.com.
--94eb2c09152661393f05344f3e55
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
hu, Jun 2, 2016 at 10:47 AM, Matt Calabrese <span dir=3D"ltr"><<a href=
=3D"mailto:calabrese@google.com" target=3D"_blank">calabrese@google.com</a>=
></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0=
0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div =
class=3D"gmail_extra"><div class=3D"gmail_quote"><span class=3D"">On Thu, J=
un 2, 2016 at 10:35 AM, Vicente J. Botet Escriba <span dir=3D"ltr"><<a h=
ref=3D"mailto:vicente.botet@wanadoo.fr" target=3D"_blank">vicente.botet@wan=
adoo.fr</a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D=
"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;bor=
der-left-color:rgb(204,204,204);padding-left:1ex">
=20
=20
=20
<div bgcolor=3D"#FFFFFF"><span>
<div>Le 02/06/2016 =C3=A0 02:24, 'Matt Calabrese'
via ISO C++ Standard - Future Proposals a =C3=A9crit=C2=A0:<br>
</div>
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div class=3D"gmail_extra">
<div class=3D"gmail_quote">On Wed, Jun 1, 2016 at 4:34 PM, Tony
V E <span dir=3D"ltr"><<a href=3D"mailto:tvaneerd@gmail.com"=
target=3D"_blank">tvaneerd@gmail.com</a>></span>
wrote:
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0=
..8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(20=
4,204,204);padding-left:1ex">
<div style=3D"line-height:initial;background-color:rgb(255,25=
5,255)" lang=3D"en-US">
<div>=E2=80=8EI
do like the idea of a range-adapter that turns
optional into a range. It (or similar) should also
turn T into a range (of exactly one). ie as_range(17)
is a range of one int.</div>
</div>
</blockquote>
<div><br>
</div>
<div>+1 I think the ranges effort actually has that kind of
a singular range already, but I could be mis-remembering.</di=
v>
</div>
</div>
</div>
</blockquote></span>
Do someone have a pointer?</div></blockquote><div><br></div></span><div=
>Found it:</div><div><a href=3D"https://github.com/ericniebler/range-v3/blo=
b/master/include/range/v3/view/single.hpp" target=3D"_blank">https://github=
..com/ericniebler/range-v3/blob/master/include/range/v3/view/single.hpp</a><=
/div></div></div></div></blockquote><div><br></div><div>Hrm. This seems to =
imply a deep copy :/ That is... unfortunate.</div></div><br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <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/CANh8DEk0tb7-_eA%2Bg4DDhp_nCCsKLrgv%3=
D5WFjSGzR45tGBpwHA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CANh8DEk0tb7-=
_eA%2Bg4DDhp_nCCsKLrgv%3D5WFjSGzR45tGBpwHA%40mail.gmail.com</a>.<br />
--94eb2c09152661393f05344f3e55--
.
Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Thu, 2 Jun 2016 20:26:29 +0200
Raw View
This is a multi-part message in MIME format.
--------------97A987A9678B7E41F92B5899
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
Le 02/06/2016 =C3=A0 19:37, 'Matt Calabrese' via ISO C++ Standard - Future=
=20
Proposals a =C3=A9crit :
> On Thu, Jun 2, 2016 at 10:15 AM, Vicente J. Botet Escriba=20
> <vicente.botet@wanadoo.fr <mailto:vicente.botet@wanadoo.fr>> wrote:
>
> Le 01/06/2016 =C3=A0 23:45, 'Matt Calabrese' via ISO C++ Standard -
> Future Proposals a =C3=A9crit :
>> On Wed, Jun 1, 2016 at 2:35 PM, Giovanni Piero Deretta
>> <gpderetta@gmail.com <mailto:gpderetta@gmail.com>> wrote:
>>
>> std::optional is often described as a container of at most
>> one element, but it lacks the required iterator accessors to
>> actually make it a proper range. Should the proper
>> std::{,c,r,cr}{begin,end} specializations be added to the
>> standard?
>>
> I believe that if what we want to traverse an optional using
> Range-based for loops we should consider it as a Range but not as
> a Container.
>
>
> I disagree with that for the reason being that copying an optional=20
> copies the underlying elements. The state of an optional with respect=20
> to its copy operations and comparisons and constness of operations is=20
> the element or the nullopt state.
I was talking of the constraints that a Range-based for loop requires,=20
not the constraints that the Range TS could impose to a Range. So there=20
are no copies involved. Sorry I was not clear enough.
>
> On Thu, Jun 2, 2016 at 10:15 AM, Vicente J. Botet Escriba=20
> <vicente.botet@wanadoo.fr <mailto:vicente.botet@wanadoo.fr>> wrote:
>
>> In the immediate it would make the following possible:
>>
>> std::optional<int> getSomethingMaybeOptionally();
>>
>> ...
>> for(auto x: getSomethingMaybe())
>> {
>> // do something in x if optx is non empty
>> }
>>
>
> That can be made to work even if optional itself isn't a range, though.
Sure, but how?
>
> On Thu, Jun 2, 2016 at 10:15 AM, Vicente J. Botet Escriba=20
> <vicente.botet@wanadoo.fr <mailto:vicente.botet@wanadoo.fr>> wrote:
>
> I don't like this kind of wrappers as either an optional can be
> seen as a Range or not. There should be no need to add noise.
> Why do you believe that it is better to be explicit?
>
>
> Because the semantics are different. I don't follow the ranges TS=20
> really so maybe the concepts involved are more subtle now, but I=20
> imagine that there is some kind of a requirement, at least for forward=20
> ranges and its refinements, that when you do something like:
>
> //////////
> SomeRange a =3D /*whatever*/;
> SomeRange b =3D a;
>
> // This should effectively modify *std::begin(a);
> *std::begin(b) =3D /*something new*/;
> //////////
>
> That does not hold true for a container, nor for optional.
>
I was not suggesting to see optional as a STL2 Range, but as Range=20
working with Range-based for loop, which was the Giovanni's subject
> That said, that doesn't mean that an optional itself needs to model=20
> one of the standard container concepts. That's a separate question.=20
> The main thing that matters is that is useful is being able to get a=20
> view into the optional as a range in some way.
>
> On Thu, Jun 2, 2016 at 10:15 AM, Vicente J. Botet Escriba=20
> <vicente.botet@wanadoo.fr <mailto:vicente.botet@wanadoo.fr>> wrote:
>
> I would like to be able to consider any NullablePointer also as a
> Range and why not any Nullable [P0196R1].
>
>
> That is a bit different, because there you really do have the expected=20
> semantics modeled regarding copies -- the state of such a pointer is=20
> the pointer value (in other words, the relationship to the element)=20
> and not the target element itself.
Again we are not talking of the same Range :)
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/4a5fba22-c0d0-ec16-6255-87489c8853e2%40wanadoo.f=
r.
--------------97A987A9678B7E41F92B5899
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
</head>
<body bgcolor=3D"#FFFFFF" text=3D"#000000">
<div class=3D"moz-cite-prefix">Le 02/06/2016 =C3=A0 19:37, 'Matt Calabr=
ese'
via ISO C++ Standard - Future Proposals a =C3=A9crit=C2=A0:<br>
</div>
<blockquote
cite=3D"mid:CANh8DEnhLcK66xOFxqvGBCom2_sw=3DHoswFv+mNhJoJ_TCwRDQw@mail.gmai=
l.com"
type=3D"cite">
<div dir=3D"ltr">
<div class=3D"gmail_extra">
<div class=3D"gmail_quote">On Thu, Jun 2, 2016 at 10:15 AM,
Vicente J. Botet Escriba <span dir=3D"ltr"><<a
moz-do-not-send=3D"true"
href=3D"mailto:vicente.botet@wanadoo.fr"><a class=3D"moz-tx=
t-link-abbreviated" href=3D"mailto:vicente.botet@wanadoo.fr">vicente.botet@=
wanadoo.fr</a></a>></span>
wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(2=
04,204,204);padding-left:1ex">
<div bgcolor=3D"#FFFFFF"><span class=3D"gmail-">
<div>Le 01/06/2016 =C3=A0 23:45, 'Matt Calabrese' via ISO
C++ Standard - Future Proposals a =C3=A9crit=C2=A0:<br>
</div>
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div class=3D"gmail_extra">
<div class=3D"gmail_quote">On Wed, Jun 1, 2016 at
2:35 PM, Giovanni Piero Deretta <span
dir=3D"ltr"><<a moz-do-not-send=3D"true"
href=3D"mailto:gpderetta@gmail.com">gpderetta=
@gmail.com</a>></span>
wrote:<br>
<blockquote class=3D"gmail_quote"
style=3D"margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(2=
04,204,204);padding-left:1ex">
<div dir=3D"ltr">std::optional is often
described as a container of at most one
element, but it lacks the required
iterator accessors to actually make it a
proper range. Should the proper
std::{,c,r,cr}{begin,end} specializations
be added to the standard?<br>
<br>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</span> I believe that if what we want to traverse an
optional using Range-based for loops we should consider
it as a Range but not as a Container. <br>
</div>
</blockquote>
<div><br>
</div>
<div>I disagree with that for the reason being that copying
an optional copies the underlying elements. The state of
an optional with respect to its copy operations and
comparisons and constness of operations is the element or
the nullopt state.</div>
</div>
</div>
</div>
</blockquote>
I was talking of the constraints that a Range-based for loop
requires, not the constraints that the Range TS could impose to a
Range. So there are no copies involved. Sorry I was not clear
enough.<br>
<blockquote
cite=3D"mid:CANh8DEnhLcK66xOFxqvGBCom2_sw=3DHoswFv+mNhJoJ_TCwRDQw@mail.gmai=
l.com"
type=3D"cite">
<div dir=3D"ltr">
<div class=3D"gmail_extra">
<div class=3D"gmail_quote">
<div><br>
</div>
<div>On Thu, Jun 2, 2016 at 10:15 AM, Vicente J. Botet
Escriba=C2=A0<span dir=3D"ltr"><<a moz-do-not-send=3D"true=
"
href=3D"mailto:vicente.botet@wanadoo.fr">vicente.botet@wa=
nadoo.fr</a>></span>=C2=A0wrote:<br>
</div>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(2=
04,204,204);padding-left:1ex">
<div bgcolor=3D"#FFFFFF"><span class=3D"gmail-">
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div class=3D"gmail_extra">
<div class=3D"gmail_quote">
<blockquote class=3D"gmail_quote"
style=3D"margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(2=
04,204,204);padding-left:1ex">
<div dir=3D"ltr">In the immediate it would
make the following possible:<br>
<br>
=C2=A0 std::optional<int>
getSomethingMaybeOptionally();<br>
<br>
=C2=A0 ...<br>
=C2=A0 for(auto x: getSomethingMaybe())<br>
=C2=A0 {<br>
=C2=A0=C2=A0=C2=A0=C2=A0 // do something in x=
if optx is non
empty<br>
=C2=A0 }<br>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</span></div>
</blockquote>
<div><br>
</div>
<div>That can be made to work even if optional itself isn't
a range, though.<br>
</div>
</div>
</div>
</div>
</blockquote>
Sure, but how?<br>
<blockquote
cite=3D"mid:CANh8DEnhLcK66xOFxqvGBCom2_sw=3DHoswFv+mNhJoJ_TCwRDQw@mail.gmai=
l.com"
type=3D"cite">
<div dir=3D"ltr">
<div class=3D"gmail_extra">
<div class=3D"gmail_quote">
<div><br>
</div>
<div>On Thu, Jun 2, 2016 at 10:15 AM, Vicente J. Botet
Escriba=C2=A0<span dir=3D"ltr"><<a moz-do-not-send=3D"true=
"
href=3D"mailto:vicente.botet@wanadoo.fr">vicente.botet@wa=
nadoo.fr</a>></span>=C2=A0wrote:</div>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(2=
04,204,204);padding-left:1ex">
<div bgcolor=3D"#FFFFFF"> I don't like this kind of wrappers
as either an optional can be seen as a Range or not.
There should be no need to add noise.<br>
Why do you believe that it is better to be explicit?<br>
</div>
</blockquote>
<div><br>
</div>
<div>Because the semantics are different. I don't follow the
ranges TS really so maybe the concepts involved are more
subtle now, but I imagine that there is some kind of a
requirement, at least for forward ranges and its
refinements, that when you do something like:</div>
<div><br>
</div>
<div>//////////</div>
<div>SomeRange a =3D /*whatever*/;</div>
<div>SomeRange b =3D a;</div>
<div><br>
</div>
<div>// This should effectively modify *std::begin(a);</div>
<div>*std::begin(b) =3D /*something new*/;</div>
//////////</div>
<div class=3D"gmail_quote"><br>
<div>That does not hold true for a container, nor for
optional.</div>
<div><br>
</div>
</div>
</div>
</div>
</blockquote>
I was not suggesting to see optional as a STL2 Range, but as Range
working with Range-based for loop, which was the Giovanni's subject
<br>
<blockquote
cite=3D"mid:CANh8DEnhLcK66xOFxqvGBCom2_sw=3DHoswFv+mNhJoJ_TCwRDQw@mail.gmai=
l.com"
type=3D"cite">
<div dir=3D"ltr">
<div class=3D"gmail_extra">
<div class=3D"gmail_quote">
<div>That said, that doesn't mean that an optional itself
needs to model one of the standard container concepts.
That's a separate question. The main thing that matters is
that is useful is being able to get a view into the
optional as a range in some way.</div>
<div>=C2=A0<br>
</div>
<div>On Thu, Jun 2, 2016 at 10:15 AM, Vicente J. Botet
Escriba=C2=A0<span dir=3D"ltr"><<a moz-do-not-send=3D"true=
"
href=3D"mailto:vicente.botet@wanadoo.fr">vicente.botet@wa=
nadoo.fr</a>></span>=C2=A0wrote:</div>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(2=
04,204,204);padding-left:1ex">
<div bgcolor=3D"#FFFFFF"> I would like to be able to
consider any NullablePointer also as a Range and why not
any Nullable [P0196R1].</div>
</blockquote>
<div><br>
</div>
<div>That is a bit different, because there you really do
have the expected semantics modeled regarding copies --
the state of such a pointer is the pointer value (in other
words, the relationship to the element) and not the target
element itself.</div>
</div>
</div>
</div>
</blockquote>
<br>
Again we are not talking of the same Range :)<br>
<br>
Vicente<br>
</body>
</html>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <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/4a5fba22-c0d0-ec16-6255-87489c8853e2%=
40wanadoo.fr?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4a5fba22-c0d0-ec16-6255-87489c8853e2=
%40wanadoo.fr</a>.<br />
--------------97A987A9678B7E41F92B5899--
.
Author: "'Matt Calabrese' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Thu, 2 Jun 2016 11:38:58 -0700
Raw View
--94eb2c1244fe622b7505344feb47
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Thu, Jun 2, 2016 at 11:26 AM, Vicente J. Botet Escriba <
vicente.botet@wanadoo.fr> wrote:
> Le 02/06/2016 =C3=A0 19:37, 'Matt Calabrese' via ISO C++ Standard - Futur=
e
> Proposals a =C3=A9crit :
>
> On Thu, Jun 2, 2016 at 10:15 AM, Vicente J. Botet Escriba <
> <vicente.botet@wanadoo.fr>vicente.botet@wanadoo.fr> wrote:
>
>> Le 01/06/2016 =C3=A0 23:45, 'Matt Calabrese' via ISO C++ Standard - Futu=
re
>> Proposals a =C3=A9crit :
>>
>> On Wed, Jun 1, 2016 at 2:35 PM, Giovanni Piero Deretta <
>> gpderetta@gmail.com> wrote:
>>
>>> std::optional is often described as a container of at most one element,
>>> but it lacks the required iterator accessors to actually make it a prop=
er
>>> range. Should the proper std::{,c,r,cr}{begin,end} specializations be a=
dded
>>> to the standard?
>>>
>>> I believe that if what we want to traverse an optional using Range-base=
d
>> for loops we should consider it as a Range but not as a Container.
>>
>
> I disagree with that for the reason being that copying an optional copies
> the underlying elements. The state of an optional with respect to its cop=
y
> operations and comparisons and constness of operations is the element or
> the nullopt state.
>
> I was talking of the constraints that a Range-based for loop requires, no=
t
> the constraints that the Range TS could impose to a Range. So there are n=
o
> copies involved. Sorry I was not clear enough.
>
Ah, okay, we're just using different definitions of "range," yes.
On Thu, Jun 2, 2016 at 11:26 AM, Vicente J. Botet Escriba <
vicente.botet@wanadoo.fr> wrote:
> That can be made to work even if optional itself isn't a range, though.
>
> Sure, but how?
>
I just meant that you can have begin/end work without it being a range --
we were using different definitions of range, as you've now pointed out. I
personally don't really mind if std::begin/std::end work for an optional
directly, although I'm assuming it's more controversial to have it work
with it directly. That said, in either case, I also think it's important to
have something like "optional_element_as_range(existing_optional)," anyway,
even if std::begin/std::end work for optional directly, since in practice
if you want to use such a range with an algorithm, the semantics of a copy
operation of the range should copy the *relationship* to the existing
element as opposed to copying the element itself.
--=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/CANh8DEm2U%2Bver1_m_0SypcfwYamASFTT__m_kbdmJpuTg=
wE6Dw%40mail.gmail.com.
--94eb2c1244fe622b7505344feb47
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
hu, Jun 2, 2016 at 11:26 AM, Vicente J. Botet Escriba <span dir=3D"ltr"><=
;<a href=3D"mailto:vicente.botet@wanadoo.fr">vicente.botet@wanadoo.fr</a>&g=
t;</span> wrote:<br><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">
=20
=20
=20
<div bgcolor=3D"#FFFFFF"><span class=3D"gmail-">
<div>Le 02/06/2016 =C3=A0 19:37, 'Matt Calabrese'
via ISO C++ Standard - Future Proposals a =C3=A9crit=C2=A0:<br>
</div>
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div class=3D"gmail_extra">
<div class=3D"gmail_quote">On Thu, Jun 2, 2016 at 10:15 AM,
Vicente J. Botet Escriba <span dir=3D"ltr"><<a href=3D"mailt=
o:vicente.botet@wanadoo.fr"></a><a href=3D"mailto:vicente.botet@wanadoo.fr"=
>vicente.botet@wanadoo.fr</a>></span>
wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0=
..8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(20=
4,204,204);padding-left:1ex">
<div bgcolor=3D"#FFFFFF"><span>
<div>Le 01/06/2016 =C3=A0 23:45, 'Matt Calabrese'=
via ISO
C++ Standard - Future Proposals a =C3=A9crit=C2=A0:<br>
</div>
<blockquote type=3D"cite">
<div dir=3D"ltr">
<div class=3D"gmail_extra">
<div class=3D"gmail_quote">On Wed, Jun 1, 2016 at
2:35 PM, Giovanni Piero Deretta <span dir=3D"ltr"=
><<a href=3D"mailto:gpderetta@gmail.com">gpderetta@gmail.com</a>></sp=
an>
wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin=
:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-lef=
t-color:rgb(204,204,204);padding-left:1ex">
<div dir=3D"ltr">std::optional is often
described as a container of at most one
element, but it lacks the required
iterator accessors to actually make it a
proper range. Should the proper
std::{,c,r,cr}{begin,end} specializations
be added to the standard?<br>
<br>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</span> I believe that if what we want to traverse an
optional using Range-based for loops we should consider
it as a Range but not as a Container. <br>
</div>
</blockquote>
<div><br>
</div>
<div>I disagree with that for the reason being that copying
an optional copies the underlying elements. The state of
an optional with respect to its copy operations and
comparisons and constness of operations is the element or
the nullopt state.</div>
</div>
</div>
</div>
</blockquote></span>
I was talking of the constraints that a Range-based for loop
requires, not the constraints that the Range TS could impose to a
Range. So there are no copies involved. Sorry I was not clear
enough.</div></blockquote><div><br></div><div>Ah, okay, we're just =
using different definitions of "range," yes.</div><div><br></div>=
<div>On Thu, Jun 2, 2016 at 11:26 AM, Vicente J. Botet Escriba=C2=A0<span d=
ir=3D"ltr"><<a href=3D"mailto:vicente.botet@wanadoo.fr">vicente.botet@wa=
nadoo.fr</a>></span>=C2=A0wrote:</div><blockquote class=3D"gmail_quote" =
style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:s=
olid;border-left-color:rgb(204,204,204);padding-left:1ex"><div bgcolor=3D"#=
FFFFFF"><span class=3D"gmail-"><blockquote type=3D"cite"><div dir=3D"ltr"><=
div class=3D"gmail_extra"><div class=3D"gmail_quote">
<div>That can be made to work even if optional itself isn't
a range, though.<br>
</div>
</div>
</div>
</div>
</blockquote></span>
Sure, but how?</div></blockquote><div><br></div><div>I just meant that =
you can have begin/end work without it being a range -- we were using diffe=
rent definitions of range, as you've now pointed out. I personally don&=
#39;t really mind if std::begin/std::end work for an optional directly, alt=
hough I'm assuming it's more controversial to have it work with it =
directly. That said, in either case, I also think it's important to hav=
e something like "optional_element_as_range(existing_optional)," =
anyway, even if std::begin/std::end work for optional directly, since in pr=
actice if you want to use such a range with an algorithm, the semantics of =
a copy operation of the range should copy the *relationship* to the existin=
g element as opposed to copying the element itself.</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" 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/CANh8DEm2U%2Bver1_m_0SypcfwYamASFTT__=
m_kbdmJpuTgwE6Dw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CANh8DEm2U%2Bve=
r1_m_0SypcfwYamASFTT__m_kbdmJpuTgwE6Dw%40mail.gmail.com</a>.<br />
--94eb2c1244fe622b7505344feb47--
.