Topic: optional -- almost errata (?)
Author: Tony V E <tvaneerd@gmail.com>
Date: Thu, 7 Feb 2013 14:44:12 -0500
Raw View
More stuff I found in rereading. Not quite as small as spelling/grammar:
---------
"The only thing that can be legitimately expected of a moved from
object (optional object, in particular) is that it can be assigned to
or destroyed without causing any resource leak or undefined behavior."
---
Not sure I agree. (Or maybe I don't understand what you mean by
"thing" and "legitimately expected".)
You should be able to query a moved-from object. You just can't
expect any particular answer. But you can expect an answer, not
undefined behaviour. Your sentence doesn't directly say everything
else is U.B., but it comes close.
---------
optional<T>::optional(const optional<T>& rhs)
Postconditions:
If bool(rhs) == false then bool(*this) == false; otherwise
bool(*this) == true and *(*this) is equivalent to *rhs.
---
What do you mean by "equivalent"?
The statement "*(*this) is equivalent to *rhs" is true if T is
Regular, but we don't know that. (If by "equivalent" you mean "==".
ie you are assuming T a(b); implies a == b; which is not true for all
T.)
Similarly for Postconditions of the move-constructor. You say
"equivalent to the value *rhs had initially" whereas all you can
really say is that you move-constructed your contained value with *rhs
and who knows what T's move constructor does.
And same for the similar mixed-type constructors. Basically anywhere
you say "equivalent" probably.
Also, both say "Throws: Whatever the execution of T's constructor
selected for the copy throws."
"constructor selected for the copy" doesn't sound precise enough.
What do you mean by 'copy', particularly in the move constructor?
---------
what does bad_optional_access constructor throw?
---------
template <class T> constexpr bool operator<(const optional<T>& x, const T& v);
template <class T> constexpr bool operator>(const T& v, const optional<T>& x);
Returns:
bool(x) ? *x < v : true.
---
I don't think you can define operator>() using <. That's an
assumption you can't make. They need to be separate:
template <class T> constexpr bool operator<(const optional<T>& x, const T& v);
Returns:
bool(x) ? *x < v : true.
template <class T> constexpr bool operator>(const T& v, const optional<T>& x);
Returns:
bool(x) ? v > *x : true.
Same with the other relops.
----------
Tony
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.
.
Author: =?UTF-8?Q?Andrzej_Krzemie=C5=84ski?= <akrzemi1@gmail.com>
Date: Thu, 7 Feb 2013 13:02:08 -0800 (PST)
Raw View
------=_Part_3_19875346.1360270928182
Content-Type: text/plain; charset=ISO-8859-2
Content-Transfer-Encoding: quoted-printable
W dniu czwartek, 7 lutego 2013 20:44:12 UTC+1 u=BFytkownik Tony V E napisa=
=B3:
>
> More stuff I found in rereading. Not quite as small as spelling/grammar:=
=20
>
Thanks again! This is really helpful. (And I learned a lot.)=20
=20
>
>
> ---------=20
>
>
> "The only thing that can be legitimately expected of a moved from=20
> object (optional object, in particular) is that it can be assigned to=20
> or destroyed without causing any resource leak or undefined behavior."=20
>
> ---=20
>
> Not sure I agree. (Or maybe I don't understand what you mean by=20
> "thing" and "legitimately expected".)=20
> You should be able to query a moved-from object. You just can't=20
> expect any particular answer. But you can expect an answer, not=20
> undefined behaviour. Your sentence doesn't directly say everything=20
> else is U.B., but it comes close.=20
>
You are right here. I should have written "given the library constrains in=
=20
17.6.5.15 (Moved-from state of library types) optional is only obliged to=
=20
be in a valid but not necessarily specified state". I needed to write it in=
=20
response to people who claim that moved-from optional object "should" be=20
disengaged. I will fix it. =20
=20
>
>
>
> ---------=20
>
>
> optional<T>::optional(const optional<T>& rhs)=20
>
> Postconditions:=20
>
> If bool(rhs) =3D=3D false then bool(*this) =3D=3D false; otherwise=20
> bool(*this) =3D=3D true and *(*this) is equivalent to *rhs.=20
>
> ---=20
>
> What do you mean by "equivalent"?=20
>
> The statement "*(*this) is equivalent to *rhs" is true if T is=20
> Regular, but we don't know that. (If by "equivalent" you mean "=3D=3D".=
=20
> ie you are assuming T a(b); implies a =3D=3D b; which is not true for al=
l=20
> T.)=20
>
=20
I see. I guess you were right when you said people often take regularity=20
for granted :)=20
>
> Similarly for Postconditions of the move-constructor. You say=20
> "equivalent to the value *rhs had initially" whereas all you can=20
> really say is that you move-constructed your contained value with *rhs=20
> and who knows what T's move constructor does.
>
> And same for the similar mixed-type constructors. Basically anywhere=20
> you say "equivalent" probably.=20
>
>
> Also, both say "Throws: Whatever the execution of T's constructor=20
> selected for the copy throws."=20
> "constructor selected for the copy" doesn't sound precise enough.=20
> What do you mean by 'copy', particularly in the move constructor?=20
>
Oh. Don't try to understand it. Just an unfortunate copy and paste. I will=
=20
change it to " Whatever the execution of T's selected constructor throws."
>
>
> ---------=20
>
>
>
> what does bad_optional_access constructor throw?=20
>
This is unfair. Other exceptions derived from logic_error do not specify=20
this. I do not want to be smarter than the Standard. (If you are really=20
interested, I think it can just throw whatever it wants.)
=20
>
>
>
> ---------=20
>
>
> template <class T> constexpr bool operator<(const optional<T>& x, const T=
&=20
> v);=20
> template <class T> constexpr bool operator>(const T& v, const optional<T>=
&=20
> x);=20
>
> Returns:=20
>
> bool(x) ? *x < v : true.=20
>
> ---=20
>
> I don't think you can define operator>() using <. That's an=20
> assumption you can't make. They need to be separate:=20
>
>
> template <class T> constexpr bool operator<(const optional<T>& x, const T=
&=20
> v);=20
>
> Returns:=20
>
> bool(x) ? *x < v : true.=20
>
> template <class T> constexpr bool operator>(const T& v, const optional<T>=
&=20
> x);=20
>
> Returns:=20
>
> bool(x) ? v > *x : true.=20
>
>
> Same with the other relops.=20
>
but is it fair if I define optional::operator> in terms of=20
optional::operator< ? (std::tuple does that.)=20
>
> ----------=20
>
> Tony=20
>
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/?hl=3Den.
------=_Part_3_19875346.1360270928182
Content-Type: text/html; charset=ISO-8859-2
Content-Transfer-Encoding: quoted-printable
<br><br>W dniu czwartek, 7 lutego 2013 20:44:12 UTC+1 u=BFytkownik Tony V E=
napisa=B3:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left=
: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">More stuff I found =
in rereading. Not quite as small as spelling/grammar:
<br></blockquote><div><br>Thanks again! This is really helpful. (And I lear=
ned a lot.) <br> <br></div><blockquote class=3D"gmail_quote" style=3D"=
margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;=
">
<br>
<br>---------
<br>
<br>
<br>"The only thing that can be legitimately expected of a moved from
<br>object (optional object, in particular) is that it can be assigned to
<br>or destroyed without causing any resource leak or undefined behavior."
<br>
<br>---
<br>
<br>Not sure I agree. (Or maybe I don't understand what you mean by
<br>"thing" and "legitimately expected".)
<br>You should be able to query a moved-from object. You just can't
<br>expect any particular answer. But you can expect an answer, not
<br>undefined behaviour. Your sentence doesn't directly say everythin=
g
<br>else is U.B., but it comes close.
<br></blockquote><div><br>You are right here. I should have written "given =
the library constrains in 17.6.5.15 (Moved-from state of library types) opt=
ional is only obliged to be in a valid but not necessarily specified state"=
.. I needed to write it in response to people who claim that moved-from opti=
onal object "should" be disengaged. I will fix it. <br> <br></di=
v><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;b=
order-left: 1px #ccc solid;padding-left: 1ex;">
<br>
<br>
<br>---------
<br>
<br>
<br>optional<T>::optional(const optional<T>& rhs)
<br>
<br>Postconditions:
<br>
<br> If bool(rhs) =3D=3D false then bool(*this) =3D=3D false; =
otherwise
<br>bool(*this) =3D=3D true and *(*this) is equivalent to *rhs.
<br>
<br>---
<br>
<br>What do you mean by "equivalent"?
<br>
<br>The statement "*(*this) is equivalent to *rhs" is true if =
T is
<br>Regular, but we don't know that. (If by "equivalent" you mean "=
=3D=3D".
<br>ie you are assuming T a(b); implies a =3D=3D b; which is not true=
for all
<br>T.)
<br></blockquote><div> </div><div>I see. I guess you were right when y=
ou said people often take regularity for granted :) <br><br></div><blockquo=
te class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left:=
1px #ccc solid;padding-left: 1ex;">
<br>
<br>Similarly for Postconditions of the move-constructor. You say
<br>"equivalent to the value *rhs had initially" whereas all you can
<br>really say is that you move-constructed your contained value with *rhs
<br>and who knows what T's move constructor does.</blockquote><blockquote c=
lass=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px=
#ccc solid;padding-left: 1ex;">
<br>
<br>And same for the similar mixed-type constructors. Basically anywh=
ere
<br>you say "equivalent" probably.
<br>
<br>
<br>Also, both say "Throws: Whatever the execution of T's constructor
<br>selected for the copy throws."
<br>"constructor selected for the copy" doesn't sound precise enough.
<br>What do you mean by 'copy', particularly in the move constructor?
<br></blockquote><div><br>Oh. Don't try to understand it. Just an unfortuna=
te copy and paste. I will change it to " Whatever the execution of T'=
s selected constructor
throws."<br><br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0;=
margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
<br>
<br>
<br>---------
<br>
<br>
<br>
<br>what does bad_optional_access constructor throw?
<br></blockquote><div><br>This is unfair. Other exceptions derived from log=
ic_error do not specify this. I do not want to be smarter than the Standard=
.. (If you are really interested, I think it can just throw whatever it want=
s.)<br> <br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0=
;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
<br>
<br>
<br>---------
<br>
<br>
<br>template <class T> constexpr bool operator<(const optional<=
T>& x, const T& v);
<br>template <class T> constexpr bool operator>(const T& v, co=
nst optional<T>& x);
<br>
<br>Returns:
<br>
<br> bool(x) ? *x < v : true.
<br>
<br>---
<br>
<br>I don't think you can define operator>() using <. That's an
<br>assumption you can't make. They need to be separate:
<br>
<br>
<br>template <class T> constexpr bool operator<(const optional<=
T>& x, const T& v);
<br>
<br>Returns:
<br>
<br> bool(x) ? *x < v : true.
<br>
<br>template <class T> constexpr bool operator>(const T& v, co=
nst optional<T>& x);
<br>
<br>Returns:
<br>
<br> bool(x) ? v > *x : true.
<br>
<br>
<br>Same with the other relops.
<br></blockquote><div><br>but is it fair if I define optional::operator>=
in terms of optional::operator< ? (std::tuple does that.) <br><br></div=
><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bo=
rder-left: 1px #ccc solid;padding-left: 1ex;">
<br>
<br>----------
<br>
<br>Tony
<br></blockquote>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
<br />
<br />
------=_Part_3_19875346.1360270928182--
.
Author: Tony V E <tvaneerd@gmail.com>
Date: Thu, 7 Feb 2013 18:04:48 -0500
Raw View
On Thu, Feb 7, 2013 at 4:02 PM, Andrzej Krzemie=C5=84ski <akrzemi1@gmail.co=
m> wrote:
>
> Oh. Don't try to understand it. Just an unfortunate copy and paste. I wil=
l
> change it to " Whatever the execution of T's selected constructor throws=
.."
>
sounds good to me
>>
>> ---------
>>
>> what does bad_optional_access constructor throw?
>
>
> This is unfair. Other exceptions derived from logic_error do not specify
> this. I do not want to be smarter than the Standard. (If you are really
> interested, I think it can just throw whatever it wants.)
>
OK then. I just find it odd that exceptions can throw exceptions due
to their use of std::string.
>>
>> template <class T> constexpr bool operator<(const optional<T>& x, const =
T&
>> v);
>> template <class T> constexpr bool operator>(const T& v, const optional<T=
>&
>> x);
>>
>> Returns:
>>
>> bool(x) ? *x < v : true.
>>
>> ---
>>
>> I don't think you can define operator>() using <. That's an
>> assumption you can't make. They need to be separate:
>>
>>
>> template <class T> constexpr bool operator<(const optional<T>& x, const =
T&
>> v);
>>
>> Returns:
>>
>> bool(x) ? *x < v : true.
>>
>> template <class T> constexpr bool operator>(const T& v, const optional<T=
>&
>> x);
>>
>> Returns:
>>
>> bool(x) ? v > *x : true.
>>
>>
>> Same with the other relops.
>
>
> but is it fair if I define optional::operator> in terms of
> optional::operator< ? (std::tuple does that.)
>
Hmmm. Interesting. I would say that std::tuple is wrong then. I
would prefer it used operator>. But maybe there is good reason for
the way it is?
My mental model for optional is becoming "if engaged, whatever T
does". So using the proper operator seems to make sense.
(And I know that that mental model might seem obvious, but I find it
is somehow different than the higher-level models 1,2,3 listed in the
proposal.)
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/?hl=3Den.
.
Author: =?UTF-8?Q?Andrzej_Krzemie=C5=84ski?= <akrzemi1@gmail.com>
Date: Tue, 12 Feb 2013 10:42:36 -0800 (PST)
Raw View
------=_Part_92_30940693.1360694556746
Content-Type: text/plain; charset=ISO-8859-1
> ---
>
> I don't think you can define operator>() using <. That's an
> assumption you can't make. They need to be separate:
>
>
> template <class T> constexpr bool operator<(const optional<T>& x, const T&
> v);
>
> Returns:
>
> bool(x) ? *x < v : true.
>
> template <class T> constexpr bool operator>(const T& v, const optional<T>&
> x);
>
> Returns:
>
> bool(x) ? v > *x : true.
>
>
> Same with the other relops.
>
template <class T> constexpr bool operator==(const optional<T>& x, const T&
v);
template <class T> constexpr bool operator==(const T& v, const optional<T>&
x);
* Returns:* bool(x) ? *x == v : false.
Is the above correct, or should I also split it into two:
template <class T> constexpr bool operator==(const optional<T>& x, const T&
v);
* Returns:* bool(x) ? *x == v : false.
template <class T> constexpr bool operator==(const T& v, const optional<T>&
x);
* Returns:* bool(x) ? v == *x : false.
(because I should not assume that T::operator== is symmetrical). The latter
looks technically more correct, but it is getting too formal...
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.
------=_Part_92_30940693.1360694556746
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<br><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex=
;border-left: 1px #ccc solid;padding-left: 1ex;">---
<br>
<br>I don't think you can define operator>() using <. That's an
<br>assumption you can't make. They need to be separate:
<br>
<br>
<br>template <class T> constexpr bool operator<(const optional<=
T>& x, const T& v);
<br>
<br>Returns:
<br>
<br> bool(x) ? *x < v : true.
<br>
<br>template <class T> constexpr bool operator>(const T& v, co=
nst optional<T>& x);
<br>
<br>Returns:
<br>
<br> bool(x) ? v > *x : true.
<br>
<br>
<br>Same with the other relops.
<br></blockquote><div><br><br><p class=3D"function">
<code>template <class T> constexpr bool operator=3D=3D(const option=
al<T>& <var>x</var>, const T& <var>v</var>);<br>template <=
class T> constexpr bool operator=3D=3D(const T& <var>v</var>, const =
optional<T>& x);</code>
</p>
=20
<dl class=3D"attribute"><dt><i> Returns:</i><code> bool(<var>x</var=
>) ? *<var>x</var> =3D=3D <var>v</var> : false</code>.</dt></dl> <br>I=
s the above correct, or should I also split it into two:<br><br><p class=3D=
"function">
<code>template <class T> constexpr bool operator=3D=3D(const option=
al<T>& <var>x</var>, const T& <var>v</var>);</code></p><p cla=
ss=3D"function"><code><i> <span style=3D"font-family: arial,sans-serif=
;">Returns:</span></i><code> bool(<var>x</var>) ? *<var>x</var> =3D=3D <var=
>v</var> : false</code>.</code></p><p class=3D"function"><code>template <=
;class T> constexpr bool operator=3D=3D(const T& <var>v</var>, const=
optional<T>& x);</code>
</p>
=20
<dl class=3D"attribute"><dt><i> Returns:</i><code> bool(<var>=
x</var>) ? <var>v =3D=3D *x</var> : false</code>.</dt></dl><br>(because I s=
hould not assume that T::operator=3D=3D is symmetrical). The latter looks t=
echnically more correct, but it is getting too formal...<br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
<br />
<br />
------=_Part_92_30940693.1360694556746--
.
Author: Tony V E <tvaneerd@gmail.com>
Date: Tue, 12 Feb 2013 14:08:43 -0500
Raw View
On Tue, Feb 12, 2013 at 1:42 PM, Andrzej Krzemie=C5=84ski <akrzemi1@gmail.c=
om> wrote:
>
>> ---
>>
>> I don't think you can define operator>() using <. That's an
>> assumption you can't make. They need to be separate:
>>
>>
>> template <class T> constexpr bool operator<(const optional<T>& x, const =
T&
>> v);
>>
>> Returns:
>>
>> bool(x) ? *x < v : true.
>>
>> template <class T> constexpr bool operator>(const T& v, const optional<T=
>&
>> x);
>>
>> Returns:
>>
>> bool(x) ? v > *x : true.
>>
>>
>> Same with the other relops.
>
>
>
> template <class T> constexpr bool operator=3D=3D(const optional<T>& x, co=
nst T&
> v);
> template <class T> constexpr bool operator=3D=3D(const T& v, const option=
al<T>&
> x);
>
> Returns: bool(x) ? *x =3D=3D v : false.
> Is the above correct, or should I also split it into two:
>
> template <class T> constexpr bool operator=3D=3D(const optional<T>& x, co=
nst T&
> v);
>
> Returns: bool(x) ? *x =3D=3D v : false.
>
> template <class T> constexpr bool operator=3D=3D(const T& v, const option=
al<T>&
> x);
>
> Returns: bool(x) ? v =3D=3D *x : false.
> (because I should not assume that T::operator=3D=3D is symmetrical). The =
latter
> looks technically more correct, but it is getting too formal...
>
Makes sense to me. It has to get formal at some point.
Tony
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/?hl=3Den.
.