Topic: Null -conditional and -coalescing operators
Author: joewoodbury@gmail.com
Date: Tue, 22 Sep 2015 10:03:47 -0700 (PDT)
Raw View
------=_Part_3284_1043426421.1442941427135
Content-Type: multipart/alternative;
boundary="----=_Part_3285_434060113.1442941427135"
------=_Part_3285_434060113.1442941427135
Content-Type: text/plain; charset=UTF-8
Checking for null and then doing one thing is a common task.
null-conditional and null-coalescing operators would be a nice solution.
For example, given the following pointer:
unique_ptr<Connection> connection;
This may happen:
if (connection)
{
connection->sendMessage(msg);
}
A nice alternative would be:
connection ?: connection->SendMessage(msg);
I've had situations where if anything resolves to false on the left, this
?: would be useful.
Or even better, to carry the concept forward:
connection?->SendMessage(msg);
Likewise:
bool success = connection ?: false;
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_3285_434060113.1442941427135
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Checking for null and then doing one thing is a common tas=
k. null-conditional and null-coalescing operators would be a nice solution.=
<br><br>For example, given the following pointer:<br><br>=C2=A0=C2=A0=C2=A0=
unique_ptr<Connection> connection;<br><br>This may happen:<br><br>=
=C2=A0=C2=A0=C2=A0 if (connection)<br>=C2=A0=C2=A0=C2=A0 {<br>=C2=A0=C2=A0=
=C2=A0 =C2=A0=C2=A0=C2=A0 connection->sendMessage(msg);<br>=C2=A0=C2=A0=
=C2=A0 }<br><br>A nice alternative would be:<br><br>=C2=A0=C2=A0=C2=A0 conn=
ection ?: connection->SendMessage(msg);<br><br>I've had situations w=
here if anything resolves to false on the left, this ?: would be useful.<br=
><br>Or even better, to carry the concept forward:<br><br>=C2=A0=C2=A0=C2=
=A0 connection?->SendMessage(msg);<br><br>Likewise:<br><br>=C2=A0=C2=A0=
=C2=A0 bool success =3D connection ?: false;<br><br><br></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_3285_434060113.1442941427135--
------=_Part_3284_1043426421.1442941427135--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Tue, 22 Sep 2015 10:15:58 -0700 (PDT)
Raw View
------=_Part_6521_1704363543.1442942158518
Content-Type: multipart/alternative;
boundary="----=_Part_6522_697935313.1442942158518"
------=_Part_6522_697935313.1442942158518
Content-Type: text/plain; charset=UTF-8
On Tuesday, September 22, 2015 at 1:03:47 PM UTC-4, joewo...@gmail.com
wrote:
>
> Checking for null and then doing one thing is a common task.
> null-conditional and null-coalescing operators would be a nice solution.
>
> For example, given the following pointer:
>
> unique_ptr<Connection> connection;
>
> This may happen:
>
> if (connection)
> {
> connection->sendMessage(msg);
> }
>
> A nice alternative would be:
>
> connection ?: connection->SendMessage(msg);
>
Or you could have just written:
if(connection) connection->SendMessage(msg);
That requires only one or two extra keystrokes. Both of these are
restricted to single lines to be executed.
I've had situations where if anything resolves to false on the left, this
> ?: would be useful.
>
> Or even better, to carry the concept forward:
>
> connection?->SendMessage(msg);
>
Ultimately, I don't think good coding practices make this as necessary as
you let on. Most of the time, if you have a pointer, you know it's valid.
It was checked for validity when you received it, and you don't want to
constantly check to see if the thing that was valid before remains valid
now.
We don't need to use up precious syntax for a relatively infrequent case.
Likewise:
>
> bool success = connection ?: false;
>
Also easily done like this:
auto success = bool{connection};
`explicit operator bool` will be called here, since you explicitly asked
for it.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_6522_697935313.1442942158518
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, September 22, 2015 at 1:03:47 PM UTC-4, joewo.=
...@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;mar=
gin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D=
"ltr">Checking for null and then doing one thing is a common task. null-con=
ditional and null-coalescing operators would be a nice solution.<br><br>For=
example, given the following pointer:<br><br>=C2=A0=C2=A0=C2=A0 unique_ptr=
<Connection> connection;<br><br>This may happen:<br><br>=C2=A0=C2=A0=
=C2=A0 if (connection)<br>=C2=A0=C2=A0=C2=A0 {<br>=C2=A0=C2=A0=C2=A0 =C2=A0=
=C2=A0=C2=A0 connection->sendMessage(msg);<br>=C2=A0=C2=A0=C2=A0 }<br><b=
r>A nice alternative would be:<br><br>=C2=A0=C2=A0=C2=A0 connection ?: conn=
ection->SendMessage(msg);<br></div></blockquote><div><br>Or you could ha=
ve just written:<br><br><div class=3D"prettyprint" style=3D"background-colo=
r: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: soli=
d; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><=
div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">if</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">conne=
ction</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> connection</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">-></span><=
span style=3D"color: #606;" class=3D"styled-by-prettify">SendMessage</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">msg</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">);</span></div></code></div><br>T=
hat requires only one or two extra keystrokes. Both of these are restricted=
to single lines to be executed.<br><br></div><blockquote class=3D"gmail_qu=
ote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padd=
ing-left: 1ex;"><div dir=3D"ltr">I've had situations where if anything =
resolves to false on the left, this ?: would be useful.<br><br>Or even bett=
er, to carry the concept forward:<br><br>=C2=A0=C2=A0=C2=A0 connection?->=
;SendMessage(msg);<br></div></blockquote><div><br>Ultimately, I don't t=
hink good coding practices make this as necessary=20
as you let on. Most of the time, if you have a pointer, you know it's=
=20
valid. It was checked for validity when you received it, and you don't=
=20
want to constantly check to see if the thing that was valid before=20
remains valid now.<br><br>We don't need to use up precious syntax for a=
relatively infrequent case.<br><br></div><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">Likewise:<br><br>=C2=A0=C2=A0=C2=A0 bool succe=
ss =3D connection ?: false;<br></div></blockquote><div><br>Also easily done=
like this:<br><br><div class=3D"prettyprint" style=3D"background-color: rg=
b(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; bo=
rder-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div c=
lass=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> success </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">bool</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">connection</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">};</span></div></code></div><br=
>`explicit operator bool` will be called here, since you explicitly asked f=
or it.<br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_6522_697935313.1442942158518--
------=_Part_6521_1704363543.1442942158518--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Tue, 22 Sep 2015 20:32:28 +0300
Raw View
On 22 September 2015 at 20:03, <joewoodbury@gmail.com> wrote:
> Checking for null and then doing one thing is a common task.
> null-conditional and null-coalescing operators would be a nice solution.
>
> For example, given the following pointer:
>
> unique_ptr<Connection> connection;
>
> This may happen:
>
> if (connection)
> {
> connection->sendMessage(msg);
> }
>
> A nice alternative would be:
>
> connection ?: connection->SendMessage(msg);
This was proposed and rejected, see
http://cplusplus.github.io/EWG/ewg-closed.html#138
--
---
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/.
.
Author: Matthew Woehlke <mwoehlke.floss@gmail.com>
Date: Tue, 22 Sep 2015 13:38:16 -0400
Raw View
On 2015-09-22 13:03, joewoodbury@gmail.com wrote:
> Checking for null and then doing one thing is a common task.
>
> bool success = connection ?: false;
That makes no sense; you are assigning the value 'false' to 'success' if
'connection' "is true", but what if it is false? Then what? Nor does it
make sense for the declaration to be conditional.
Rather, you would need to write something like:
bool success = connection ? false : true;
....which you can do already. Or just use the converted value directly,
as Nicol notes.
> connection?->SendMessage(msg);
I think the syntax ought to be more like:
?(connection)->SendMessage(msg);
....where '?(expr)' says to evaluate the truth-value of 'expr' and, if
true, "return" 'expr', otherwise skip the statement. (I'd avoid 'expr?'
as it seems likely to make parsing that vs. 'expr?expr:expr' difficult.
Plus, one would expect 'expr?expr' to act more like the trinary, just
without the ':expr' part, and not "reuse" the LHS expression.)
You could also write things like:
x = ?(y); // if (y) x = y;
However, this is a very unusual construct for questionable gain.
--
Matthew
--
---
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/.
.
Author: joewoodbury@gmail.com
Date: Tue, 22 Sep 2015 10:38:58 -0700 (PDT)
Raw View
------=_Part_284_642464533.1442943538915
Content-Type: multipart/alternative;
boundary="----=_Part_285_1814952225.1442943538915"
------=_Part_285_1814952225.1442943538915
Content-Type: text/plain; charset=UTF-8
First, I didn't say it was necessary nor even imply it; I said it would be
"a nice solution"
Second, my examples were intentionally trivial.
Thus if I wrote
int val = connection ?: 5;
your solution wouldn't work.
On Tuesday, September 22, 2015 at 10:15:58 AM UTC-7, Nicol Bolas wrote:
>
> On Tuesday, September 22, 2015 at 1:03:47 PM UTC-4, joewo...@gmail.com
> wrote:
>>
>> Checking for null and then doing one thing is a common task.
>> null-conditional and null-coalescing operators would be a nice solution.
>>
>> For example, given the following pointer:
>>
>> unique_ptr<Connection> connection;
>>
>> This may happen:
>>
>> if (connection)
>> {
>> connection->sendMessage(msg);
>> }
>>
>> A nice alternative would be:
>>
>> connection ?: connection->SendMessage(msg);
>>
>
> Or you could have just written:
>
> if(connection) connection->SendMessage(msg);
>
> That requires only one or two extra keystrokes. Both of these are
> restricted to single lines to be executed.
>
> I've had situations where if anything resolves to false on the left, this
>> ?: would be useful.
>>
>> Or even better, to carry the concept forward:
>>
>> connection?->SendMessage(msg);
>>
>
> Ultimately, I don't think good coding practices make this as necessary as
> you let on. Most of the time, if you have a pointer, you know it's valid.
> It was checked for validity when you received it, and you don't want to
> constantly check to see if the thing that was valid before remains valid
> now.
>
> We don't need to use up precious syntax for a relatively infrequent case.
>
> Likewise:
>>
>> bool success = connection ?: false;
>>
>
> Also easily done like this:
>
> auto success = bool{connection};
>
> `explicit operator bool` will be called here, since you explicitly asked
> for it.
>
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_285_1814952225.1442943538915
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">First, I didn't say it was necessary nor even imply it=
; I said it would be "a nice solution"<br><br>Second, my examples=
were intentionally trivial.<br><br>Thus if I wrote<br><br>int val =3D conn=
ection ?: 5;<br><br>your solution wouldn't work.<br><br><br>On Tuesday,=
September 22, 2015 at 10:15:58 AM UTC-7, Nicol Bolas wrote:<blockquote cla=
ss=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #=
ccc solid;padding-left: 1ex;"><div dir=3D"ltr">On Tuesday, September 22, 20=
15 at 1:03:47 PM UTC-4, <a>joewo...@gmail.com</a> wrote:<blockquote class=
=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc s=
olid;padding-left:1ex"><div dir=3D"ltr">Checking for null and then doing on=
e thing is a common task. null-conditional and null-coalescing operators wo=
uld be a nice solution.<br><br>For example, given the following pointer:<br=
><br>=C2=A0=C2=A0=C2=A0 unique_ptr<Connection> connection;<br><br>Thi=
s may happen:<br><br>=C2=A0=C2=A0=C2=A0 if (connection)<br>=C2=A0=C2=A0=C2=
=A0 {<br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 connection->sendMessage(m=
sg);<br>=C2=A0=C2=A0=C2=A0 }<br><br>A nice alternative would be:<br><br>=C2=
=A0=C2=A0=C2=A0 connection ?: connection->SendMessage(msg);<br></div></b=
lockquote><div><br>Or you could have just written:<br><br><div style=3D"bac=
kground-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:s=
olid;border-width:1px;word-wrap:break-word"><code><div><span style=3D"color=
:#008">if</span><span style=3D"color:#660">(</span><span style=3D"color:#00=
0">connection</span><span style=3D"color:#660">)</span><span style=3D"color=
:#000"> connection</span><span style=3D"color:#660">-></span><span style=
=3D"color:#606">SendMessage</span><span style=3D"color:#660">(</span><span =
style=3D"color:#000">msg</span><span style=3D"color:#660">);</span></div></=
code></div><br>That requires only one or two extra keystrokes. Both of thes=
e are restricted to single lines to be executed.<br><br></div><blockquote c=
lass=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #c=
cc solid;padding-left:1ex"><div dir=3D"ltr">I've had situations where i=
f anything resolves to false on the left, this ?: would be useful.<br><br>O=
r even better, to carry the concept forward:<br><br>=C2=A0=C2=A0=C2=A0 conn=
ection?->SendMessage(msg);<br></div></blockquote><div><br>Ultimately, I =
don't think good coding practices make this as necessary=20
as you let on. Most of the time, if you have a pointer, you know it's=
=20
valid. It was checked for validity when you received it, and you don't=
=20
want to constantly check to see if the thing that was valid before=20
remains valid now.<br><br>We don't need to use up precious syntax for a=
relatively infrequent case.<br><br></div><blockquote class=3D"gmail_quote"=
style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-lef=
t:1ex"><div dir=3D"ltr">Likewise:<br><br>=C2=A0=C2=A0=C2=A0 bool success =
=3D connection ?: false;<br></div></blockquote><div><br>Also easily done li=
ke this:<br><br><div style=3D"background-color:rgb(250,250,250);border-colo=
r:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:break-word=
"><code><div><span style=3D"color:#008">auto</span><span style=3D"color:#00=
0"> success </span><span style=3D"color:#660">=3D</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#008">bool</span><span style=3D"color:=
#660">{</span><span style=3D"color:#000">connection</span><span style=3D"co=
lor:#660">};</span></div></code></div><br>`explicit operator bool` will be =
called here, since you explicitly asked for it.<br></div></div></blockquote=
></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_285_1814952225.1442943538915--
------=_Part_284_642464533.1442943538915--
.
Author: Bjorn Reese <breese@mail1.stofanet.dk>
Date: Tue, 22 Sep 2015 20:37:40 +0200
Raw View
On 09/22/2015 07:03 PM, joewoodbury@gmail.com wrote:
> A nice alternative would be:
>
> connection ?: connection->SendMessage(msg);
connection && connection->SendMessage(msg);
--
---
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/.
.
Author: joewoodbury@gmail.com
Date: Tue, 22 Sep 2015 11:41:49 -0700 (PDT)
Raw View
------=_Part_6_1670467107.1442947309489
Content-Type: multipart/alternative;
boundary="----=_Part_7_1948381328.1442947309489"
------=_Part_7_1948381328.1442947309489
Content-Type: text/plain; charset=UTF-8
My mistake. I had collapsed several examples in order to keep my message
short and in the process created a bogus example. I apologize.
I had been considering a recent bug where a reference had "contained" a
nullptr (not in my code!) and wondered if this could be a solution.
I was thinking of another spot of code where an overloaded operator is
returning either a nullptr or valid pointer. If the former, it assigns
another value to lvalue.
On Tuesday, September 22, 2015 at 10:38:35 AM UTC-7, Matthew Woehlke wrote:
>
> On 2015-09-22 13:03, joewo...@gmail.com <javascript:> wrote:
> > Checking for null and then doing one thing is a common task.
> >
> > bool success = connection ?: false;
>
> That makes no sense; you are assigning the value 'false' to 'success' if
> 'connection' "is true", but what if it is false? Then what? Nor does it
> make sense for the declaration to be conditional.
>
> Rather, you would need to write something like:
>
> bool success = connection ? false : true;
>
> ...which you can do already. Or just use the converted value directly,
> as Nicol notes.
>
> > connection?->SendMessage(msg);
>
> I think the syntax ought to be more like:
>
> ?(connection)->SendMessage(msg);
>
> ...where '?(expr)' says to evaluate the truth-value of 'expr' and, if
> true, "return" 'expr', otherwise skip the statement. (I'd avoid 'expr?'
> as it seems likely to make parsing that vs. 'expr?expr:expr' difficult.
> Plus, one would expect 'expr?expr' to act more like the trinary, just
> without the ':expr' part, and not "reuse" the LHS expression.)
>
> You could also write things like:
>
> x = ?(y); // if (y) x = y;
>
> However, this is a very unusual construct for questionable gain.
>
> --
> Matthew
>
>
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_7_1948381328.1442947309489
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">My mistake. I had collapsed several examples in order to k=
eep my message short and in the process created a bogus example. I apologiz=
e.<br><br>I had been considering a recent bug where a reference had "c=
ontained" a nullptr (not in my code!) and wondered if this could be a =
solution.<br><br>I was thinking of another spot of code where an overloaded=
operator is returning either a nullptr or valid pointer. If the former, it=
assigns another value to lvalue.<br><br><br><br>On Tuesday, September 22, =
2015 at 10:38:35 AM UTC-7, Matthew Woehlke wrote:<blockquote class=3D"gmail=
_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;p=
adding-left: 1ex;">On 2015-09-22 13:03, <a href=3D"javascript:" target=3D"_=
blank" gdf-obfuscated-mailto=3D"rToj9SAZBgAJ" rel=3D"nofollow" onmousedown=
=3D"this.href=3D'javascript:';return true;" onclick=3D"this.href=3D=
'javascript:';return true;">joewo...@gmail.com</a> wrote:
<br>> Checking for null and then doing one thing is a common task.=20
<br>>=20
<br>> =C2=A0 =C2=A0 bool success =3D connection ?: false;
<br>
<br>That makes no sense; you are assigning the value 'false' to =
9;success' if
<br>'connection' "is true", but what if it is false? Then=
what? Nor does it
<br>make sense for the declaration to be conditional.
<br>
<br>Rather, you would need to write something like:
<br>
<br>=C2=A0 bool success =3D connection ? false : true;
<br>
<br>...which you can do already. Or just use the converted value directly,
<br>as Nicol notes.
<br>
<br>> =C2=A0 =C2=A0 connection?->SendMessage(msg);
<br>
<br>I think the syntax ought to be more like:
<br>
<br>=C2=A0 ?(connection)->SendMessage(<wbr>msg);
<br>
<br>...where '?(expr)' says to evaluate the truth-value of 'exp=
r' and, if
<br>true, "return" 'expr', otherwise skip the statement. =
(I'd avoid 'expr?'
<br>as it seems likely to make parsing that vs. 'expr?expr:expr' di=
fficult.
<br>Plus, one would expect 'expr?expr' to act more like the trinary=
, just
<br>without the ':expr' part, and not "reuse" the LHS exp=
ression.)
<br>
<br>You could also write things like:
<br>
<br>=C2=A0 x =3D ?(y); // if (y) x =3D y;
<br>
<br>However, this is a very unusual construct for questionable gain.
<br>
<br>--=20
<br>Matthew
<br>
<br></blockquote></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_7_1948381328.1442947309489--
------=_Part_6_1670467107.1442947309489--
.
Author: joewoodbury@gmail.com
Date: Tue, 22 Sep 2015 17:34:20 -0700 (PDT)
Raw View
------=_Part_665_1464794827.1442968460559
Content-Type: multipart/alternative;
boundary="----=_Part_666_883898929.1442968460560"
------=_Part_666_883898929.1442968460560
Content-Type: text/plain; charset=UTF-8
Here in interesting example I just encountered:
strLen is passed into a function along with pStr. After nullptr checks, the
following is done:
size_t tmpStrLen = wcslen(pStr);
if (strLen > tmpStrLen)
strLen = tmpStrLen;
Using the ?: operator, you could do:
strLen = wcslen(pStr) < strLen ?: strLen;
Again, a trivial example, but one in actual code.
On Tuesday, September 22, 2015 at 10:03:47 AM UTC-7, joewo...@gmail.com
wrote:
>
> Checking for null and then doing one thing is a common task.
> null-conditional and null-coalescing operators would be a nice solution.
>
> For example, given the following pointer:
>
> unique_ptr<Connection> connection;
>
> This may happen:
>
> if (connection)
> {
> connection->sendMessage(msg);
> }
>
> A nice alternative would be:
>
> connection ?: connection->SendMessage(msg);
>
> I've had situations where if anything resolves to false on the left, this
> ?: would be useful.
>
> Or even better, to carry the concept forward:
>
> connection?->SendMessage(msg);
>
> Likewise:
>
> bool success = connection ?: false;
>
>
>
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_666_883898929.1442968460560
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Here in interesting example I just encountered:<br><br>str=
Len is passed into a function along with pStr. After nullptr checks, the fo=
llowing is done:<br><br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=
=C2=A0 size_t tmpStrLen =3D wcslen(pStr);<br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=
=A0=C2=A0 =C2=A0=C2=A0=C2=A0 if (strLen > tmpStrLen)<br>=C2=A0=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 strLen =3D tmp=
StrLen;<br><br>Using the ?: operator, you could do:<br><br>=C2=A0=C2=A0=C2=
=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 strLen =3D wcslen(pStr) < strL=
en ?: strLen;<br><br>Again, a trivial example, but one in actual code.<br><=
br><br><br>On Tuesday, September 22, 2015 at 10:03:47 AM UTC-7, joewo...@gm=
ail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"=
>Checking for null and then doing one thing is a common task. null-conditio=
nal and null-coalescing operators would be a nice solution.<br><br>For exam=
ple, given the following pointer:<br><br>=C2=A0=C2=A0=C2=A0 unique_ptr<C=
onnection> connection;<br><br>This may happen:<br><br>=C2=A0=C2=A0=C2=A0=
if (connection)<br>=C2=A0=C2=A0=C2=A0 {<br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=
=C2=A0 connection->sendMessage(msg);<br>=C2=A0=C2=A0=C2=A0 }<br><br>A ni=
ce alternative would be:<br><br>=C2=A0=C2=A0=C2=A0 connection ?: connection=
->SendMessage(msg);<br><br>I've had situations where if anything res=
olves to false on the left, this ?: would be useful.<br><br>Or even better,=
to carry the concept forward:<br><br>=C2=A0=C2=A0=C2=A0 connection?->Se=
ndMessage(msg);<br><br>Likewise:<br><br>=C2=A0=C2=A0=C2=A0 bool success =3D=
connection ?: false;<br><br><br></div></blockquote></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_666_883898929.1442968460560--
------=_Part_665_1464794827.1442968460559--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Tue, 22 Sep 2015 19:53:07 -0700 (PDT)
Raw View
------=_Part_7076_99725498.1442976787356
Content-Type: multipart/alternative;
boundary="----=_Part_7077_1075964204.1442976787356"
------=_Part_7077_1075964204.1442976787356
Content-Type: text/plain; charset=UTF-8
On Tuesday, September 22, 2015 at 8:34:20 PM UTC-4, joewo...@gmail.com
wrote:
>
> Here in interesting example I just encountered:
>
> strLen is passed into a function along with pStr. After nullptr checks,
> the following is done:
>
> size_t tmpStrLen = wcslen(pStr);
> if (strLen > tmpStrLen)
> strLen = tmpStrLen;
>
> Using the ?: operator, you could do:
>
> strLen = wcslen(pStr) < strLen ?: strLen;
>
> Again, a trivial example, but one in actual code.
>
And this code would have made it much more clear what you were doing:
strLen = std::min(wcslen(pStr), strLen);
Also, I'm not sure how your suggestion is equivalent to the original. I see
you have an expression that evaluates to bool. And I see you have an
expression which will be evaluated if the boolean expression is true.
I don't see what the value of that expression will be if the boolean
expression is false. So I'm not clear on exactly what your code means.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_7077_1075964204.1442976787356
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Tuesday, September 22, 2015 at 8:34:20 PM UTC-4=
, joewo...@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margi=
n: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><di=
v dir=3D"ltr">Here in interesting example I just encountered:<br><br>strLen=
is passed into a function along with pStr. After nullptr checks, the follo=
wing is done:<br><br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 size_t tmpStrLen =3D wcslen(pStr);<br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=
=C2=A0 =C2=A0=C2=A0=C2=A0 if (strLen > tmpStrLen)<br>=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 strLen =3D tmpStrL=
en;<br><br>Using the ?: operator, you could do:<br><br>=C2=A0=C2=A0=C2=A0 =
=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 strLen =3D wcslen(pStr) < strLen ?=
: strLen;<br><br>Again, a trivial example, but one in actual code.<br></div=
></blockquote><div dir=3D"ltr"><br>And this code would have made it much mo=
re clear what you were doing:<br><br><div class=3D"prettyprint" style=3D"ba=
ckground-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); borde=
r-style: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"p=
rettyprint"><div class=3D"subprettyprint"><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">strLen </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">min</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">wcslen</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">pStr</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">),</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> strLen</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span></div></code></div><br>Also, I'm not=
sure how your suggestion is equivalent to the original. I see you have an =
expression that evaluates to bool. And I see you have an expression which w=
ill be evaluated if the boolean expression is true.<br><br>I don't see =
what the value of that expression will be if the boolean expression is fals=
e. So I'm not clear on exactly what your code means.<br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_7077_1075964204.1442976787356--
------=_Part_7076_99725498.1442976787356--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Tue, 22 Sep 2015 23:06:53 -0700
Raw View
On Tuesday 22 September 2015 10:38:58 joewoodbury@gmail.com wrote:
> Thus if I wrote
>
> int val = connection ?: 5;
>
> your solution wouldn't work.
Assuming that connection was a pointer here, you'd get an error about
assigning a pointer to an integer.
The ?: syntax with the missing second operand already has a precedent to mean
a repeat of the first operand. Therefore, the above reads:
int val = connection ? connection : 5;
However, I would like to see the syntax standardised. When you're dealing with
C code that returns error conditions, this is useful:
ErrorCode err = some_function();
err = err ?: some_other_function();
err = err ?: some_third_function();
I'm not going to ask for, but it would be nice to have
err ?:= some_function();
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--
---
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/.
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Tue, 22 Sep 2015 23:11:33 -0700
Raw View
On Tuesday 22 September 2015 17:34:20 joewoodbury@gmail.com wrote:
> strLen is passed into a function along with pStr. After nullptr checks, the
> following is done:
>
> size_t tmpStrLen = wcslen(pStr);
> if (strLen > tmpStrLen)
> strLen = tmpStrLen;
>
> Using the ?: operator, you could do:
>
> strLen = wcslen(pStr) < strLen ?: strLen;
>
> Again, a trivial example, but one in actual code.
This does not do the same as the above. It does:
bool tmp = wcslen(pStr) < strLen;
strLen = tmp ? tmp : strLen;
That is, it assigns 1 to strLen if the conditional was true.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--
---
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/.
.
Author: David Krauss <potswa@gmail.com>
Date: Wed, 23 Sep 2015 17:31:54 +0800
Raw View
--Apple-Mail=_49C9D21C-13B2-4AC7-A590-9C0B299084F3
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
All this confusion aside, it would be nice to have such a thing in the libr=
ary. It would be on a similar level of abstraction as std::exchange.
Not tested, but it might look something like this:
template< typename alternative, typename value >
alternative value_or( value && v, alternative && a ) {
if ( v ) return std::forward< value >( v );
else return std::forward< alternative >( a );
}
Given such a facility, experimental::optional shouldn=E2=80=99t need a memb=
er value_or. This one does work a bit differently, but the goal is the same=
..
It would be better if it returned by reference. This would be enabled by my=
lifetime extension proposal (bit.ly/genlife <http://bit.ly/genlife>) and m=
arking both parameters as export.
Unlike the OP, the second argument gets evaluated even if it=E2=80=99s not =
used. Hopefully at some point the language will support user-defined short-=
circuit operators via lazy argument evaluation. In the big picture, the def=
iciency is minor.
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--Apple-Mail=_49C9D21C-13B2-4AC7-A590-9C0B299084F3
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D"">All this confusion=
aside, it would be nice to have such a thing in the library. It would be o=
n a similar level of abstraction as <font face=3D"Courier" class=3D"">std::=
exchange</font>.<div class=3D""><br class=3D""></div><div class=3D"">Not te=
sted, but it might look something like this:</div><div class=3D""><br class=
=3D""></div><div class=3D""><font face=3D"Courier" class=3D"">template<&=
nbsp;</font><span style=3D"font-family: Courier;" class=3D"">typename alter=
native, </span><span style=3D"font-family: Courier;" class=3D"">typena=
me value ></span></div><div class=3D""><font face=3D"Courier" class=3D""=
>alternative value_or( value && v, alternative && a ) {</fo=
nt></div><div class=3D""><font face=3D"Courier" class=3D""> if=
( v ) return std::forward< value >( v );</font></div><div class=3D""=
><font face=3D"Courier" class=3D""> else return std::forward&l=
t; alternative >( a );</font></div><div class=3D""><font face=3D"Courier=
" class=3D"">}</font></div><div class=3D""><br class=3D""></div><div class=
=3D"">Given such a facility, <font face=3D"Courier" class=3D"">experimental=
::optional</font> shouldn=E2=80=99t need a member <font face=3D"Courier" cl=
ass=3D"">value_or</font>. This one does work a bit differently, but the goa=
l is the same.</div><div class=3D""><br class=3D""></div><div class=3D"">It=
would be better if it returned by reference. This would be enabled by my l=
ifetime extension proposal (<a href=3D"http://bit.ly/genlife" class=3D"">bi=
t.ly/genlife</a>) and marking both parameters as <font face=3D"Courier=
" class=3D"">export</font>.</div><div class=3D""><br class=3D""></div><div =
class=3D"">Unlike the OP, the second argument gets evaluated even if it=E2=
=80=99s not used. Hopefully at some point the language will support user-de=
fined short-circuit operators via lazy argument evaluation. In the big pict=
ure, the deficiency is minor.</div><div class=3D""><br class=3D""></div></b=
ody></html>
<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--Apple-Mail=_49C9D21C-13B2-4AC7-A590-9C0B299084F3--
.
Author: Matthew Woehlke <mwoehlke.floss@gmail.com>
Date: Wed, 23 Sep 2015 10:31:02 -0400
Raw View
On 2015-09-23 02:06, Thiago Macieira wrote:
> On Tuesday 22 September 2015 10:38:58 joewoodbury@gmail.com wrote:
>> Thus if I wrote
>>
>> int val = connection ?: 5;
>>
>> your solution wouldn't work.
>
> Assuming that connection was a pointer here, you'd get an error about
> assigning a pointer to an integer.
>
> The ?: syntax with the missing second operand already has a precedent to mean
> a repeat of the first operand. Therefore, the above reads:
>
> int val = connection ? connection : 5;
>
> However, I would like to see the syntax standardised. When you're dealing with
> C code that returns error conditions, this is useful:
>
> ErrorCode err = some_function();
> err = err ?: some_other_function();
> err = err ?: some_third_function();
err || err = some_other_function();
:-)
(I've actually written code like that. Pedantically, I think it was of
the form 'success && ...', but same idea...)
> I'm not going to ask for, but it would be nice to have
>
> err ?:= some_function();
....or, as in my reply, '?!(err) = some_function();'; tacking '?' / '?:'
/ '?!' on to other operator tokens makes me nervous ;-). I too think it
would be nice to have, but don't see it being sufficiently nice as to
actually be accepted as a proposal.
Actually... hmm...
#define iff(var) \
for (auto _guard = true; _guard;) \
for (auto&& _var = var; _guard && bool{_var}; _guard = false) \
_var
#define ifn(var) \
for (auto _guard = true; _guard;) \
for (auto&& _var = var; _guard && !bool{_var}; _guard = false) \
_var
iff(object)->method();
ifn(err) = some_function();
--
Matthew
--
---
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/.
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Wed, 23 Sep 2015 07:41:54 -0700
Raw View
On Wednesday 23 September 2015 10:31:02 Matthew Woehlke wrote:
> > C code that returns error conditions, this is useful:
> > ErrorCode err = some_function();
> > err = err ?: some_other_function();
> > err = err ?: some_third_function();
>
> err || err = some_other_function();
>
> :-)
>
> (I've actually written code like that. Pedantically, I think it was of
> the form 'success && ...', but same idea...)
Hmm... good idea. Ugly, but why not?
Thanks for the suggestion.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Software Architect - Intel Open Source Technology Center
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
--
---
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/.
.
Author: Peter Koch Larsen <peter.koch.larsen@gmail.com>
Date: Thu, 24 Sep 2015 16:03:17 +0200
Raw View
On 9/22/15, joewoodbury@gmail.com <joewoodbury@gmail.com> wrote:
> Checking for null and then doing one thing is a common task.
> null-conditional and null-coalescing operators would be a nice solution.
>
> For example, given the following pointer:
>
> unique_ptr<Connection> connection;
>
> This may happen:
>
> if (connection)
> {
> connection->sendMessage(msg);
> }
>
> A nice alternative would be:
>
> connection ?: connection->SendMessage(msg);
>
> I've had situations where if anything resolves to false on the left, this
> ?: would be useful.
>
> Or even better, to carry the concept forward:
>
> connection?->SendMessage(msg);
>
> Likewise:
>
> bool success = connection ?: false;
>
You could just do
connection && connection->SendMessage(msg);
/Peter
--
---
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/.
.
Author: Matthew Woehlke <mwoehlke.floss@gmail.com>
Date: Thu, 24 Sep 2015 10:35:53 -0400
Raw View
On 2015-09-24 10:03, Peter Koch Larsen wrote:
> On 9/22/15, joewoodbury@gmail.com <joewoodbury@gmail.com> wrote:
>> Checking for null and then doing one thing is a common task.
>> null-conditional and null-coalescing operators would be a nice solution.
>>
>> For example, given the following pointer:
>>
>> unique_ptr<Connection> connection;
>>
>> This may happen:
>>
>> if (connection)
>> {
>> connection->sendMessage(msg);
>> }
>>
>> A nice alternative would be:
>>
>> connection ?: connection->SendMessage(msg);
>>
>> I've had situations where if anything resolves to false on the left, this
>> ?: would be useful.
>>
>> Or even better, to carry the concept forward:
>>
>> connection?->SendMessage(msg);
>>
>> Likewise:
>>
>> bool success = connection ?: false;
>
> You could just do
> connection && connection->SendMessage(msg);
....not if SendMessage returns void, you can't. You'd have to use:
connection && (connection->SendMessage(msg), true);
....which is even worse than:
if (connection) connection->SendMessage(msg);
Personally, I like my macro ;-).
iff(connection)->SendMessage(msg);
Alas, it can't solve this case, however:
written += ?(stream)->write(buffer);
(I'll note that part of the motivation here probably comes from wanting
to dodge draconian coding styles that mandate multiline braces around
ANY conditional body. Which, I'll be honest, I've done myself...
employed ugly hacks to dodge such, I mean; I personally loathe requiring
braces in single-statement conditional bodies.)
--
Matthew
--
---
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/.
.
Author: Myriachan <myriachan@gmail.com>
Date: Thu, 24 Sep 2015 11:48:01 -0700 (PDT)
Raw View
------=_Part_1372_428541199.1443120481506
Content-Type: multipart/alternative;
boundary="----=_Part_1373_1970431957.1443120481507"
------=_Part_1373_1970431957.1443120481507
Content-Type: text/plain; charset=UTF-8
On Tuesday, September 22, 2015 at 11:06:57 PM UTC-7, Thiago Macieira wrote:
>
> However, I would like to see the syntax standardised. When you're dealing
> with
> C code that returns error conditions, this is useful:
>
> ErrorCode err = some_function();
> err = err ?: some_other_function();
> err = err ?: some_third_function();
>
>
Me too, but since it was rejected in May of this year, good luck =/
One way to get this would be to convince the C committee, which would put
pressure on the C++ committee. That GCC and Clang already support this is
important.
Melissa
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_1373_1970431957.1443120481507
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Tuesday, September 22, 2015 at 11:06:57 PM UTC-7, Thiag=
o Macieira wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">However, I wo=
uld like to see the syntax standardised. When you're dealing with=20
<br>C code that returns error conditions, this is useful:
<br>
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0ErrorCode err =3D some_=
function();
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0err =3D err ?: some_oth=
er_function();
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0err =3D err ?: some_thi=
rd_function();
<br>
<br></blockquote><div><br>Me too, but since it was rejected in May of this =
year, good luck =3D/<br><br>One way to get this would be to convince the C =
committee, which would put pressure on the C++ committee.=C2=A0 That GCC an=
d Clang already support this is important.<br><br>Melissa<br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_1373_1970431957.1443120481507--
------=_Part_1372_428541199.1443120481506--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 24 Sep 2015 21:50:52 +0300
Raw View
On 24 September 2015 at 21:48, Myriachan <myriachan@gmail.com> wrote:
> Me too, but since it was rejected in May of this year, good luck =/
> One way to get this would be to convince the C committee, which would put
> pressure on the C++ committee.
Good luck indeed. :)
--
---
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/.
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Thu, 24 Sep 2015 12:51:02 -0700 (PDT)
Raw View
------=_Part_1062_489372124.1443124262460
Content-Type: multipart/alternative;
boundary="----=_Part_1063_960156838.1443124262460"
------=_Part_1063_960156838.1443124262460
Content-Type: text/plain; charset=UTF-8
On Thursday, September 24, 2015 at 10:36:06 AM UTC-4, Matthew Woehlke wrote:
written += ?(stream)->write(buffer);
>
That brings up a question. Namely... what does that actually do?
What I mean is this: `?(stream)->write(buffer)` is an expression. What type
does it resolve to? The general idea with these things is that they resolve
to doing something or not doing something. And thus, is equivalent to:
if(stream) then stream->write(buffer)
But that's not an expression; that's a statement. Statements don't resolve
to values.
So if the condition is false, what does the overall expression resolve to?
Does it default-construct a value of the type that would result if the
condition was true?
Or does the condition being false completely wipe out the entire statement.
That is, even the += is part of the condition. If so, that requires
look-ahead. Potentially *lots* of look-ahead.
?: makes it clear exactly what's going on:
written += stream ? stream->write(buffer) : 0;
(I'll note that part of the motivation here probably comes from wanting
> to dodge draconian coding styles that mandate multiline braces around
> ANY conditional body. Which, I'll be honest, I've done myself...
> employed ugly hacks to dodge such, I mean; I personally loathe requiring
> braces in single-statement conditional bodies.)
>
That's a pretty poor motivation for a language feature.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_1063_960156838.1443124262460
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Thursday, September 24, 2015 at 10:36:06 AM UTC-4, Matt=
hew Woehlke wrote:<br><br><blockquote style=3D"margin: 0px 0px 0px 0.8ex; b=
order-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class=3D"gmai=
l_quote">written +=3D ?(stream)->write(buffer);<br></blockquote><div><br=
>That brings up a question. Namely... what does that actually do?<br><br>Wh=
at I mean is this: `?(stream)->write(buffer)` is an expression. What typ=
e does it resolve to? The general idea with these things is that they resol=
ve to doing something or not doing something. And thus, is equivalent to:<b=
r><br><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 2=
50); border-color: rgb(187, 187, 187); border-style: solid; border-width: 1=
px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subpr=
ettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">if</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify">stream</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;"=
class=3D"styled-by-prettify">then</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> stream</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">-></span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">write</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
">buffer</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span>=
</div></code></div><br>But that's not an expression; that's a state=
ment. Statements don't resolve to values.<br><br>So if the condition is=
false, what does the overall expression resolve to? Does it default-constr=
uct a value of the type that would result if the condition was true?<br><br=
>Or does the condition being false completely wipe out the entire statement=
.. That is, even the +=3D is part of the condition. If so, that requires loo=
k-ahead. Potentially <i>lots</i> of look-ahead.<br><br>?: makes it clear ex=
actly what's going on:<br><br><div class=3D"prettyprint" style=3D"backg=
round-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-s=
tyle: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"pret=
typrint"><div class=3D"subprettyprint"><span style=3D"color: #000;" class=
=3D"styled-by-prettify">written </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">+=3D</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> stream </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">?</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> stream</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">-></span><span style=3D"color: #000;" class=3D"styled-by-prettify">w=
rite</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">buffer</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"=
styled-by-prettify">0</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">;</span></div></code></div><br></div><blockquote class=3D"gmail_=
quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;pa=
dding-left: 1ex;">(I'll note that part of the motivation here probably =
comes from wanting
<br>to dodge draconian coding styles that mandate multiline braces around
<br>ANY conditional body. Which, I'll be honest, I've done myself..=
..
<br>employed ugly hacks to dodge such, I mean; I personally loathe requirin=
g
<br>braces in single-statement conditional bodies.)
<br></blockquote><div><br>That's a pretty poor motivation for a languag=
e feature.<br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_1063_960156838.1443124262460--
------=_Part_1062_489372124.1443124262460--
.
Author: Matthew Woehlke <mwoehlke.floss@gmail.com>
Date: Thu, 24 Sep 2015 16:28:20 -0400
Raw View
On 2015-09-24 15:51, Nicol Bolas wrote:
> On Thursday, September 24, 2015 at 10:36:06 AM UTC-4, Matthew Woehlke wrote:
>> written += ?(stream)->write(buffer);
>
> That brings up a question. Namely... what does that actually do?
As previously explained:
auto&& __temp = stream;
if (__temp) written += ?(__temp)->write(buffer);
Yes, the fact that you may have to backtrack on the statement when you
see '?()' is atrocious. I didn't say I'd actually *vote* for the feature
:-).
> What I mean is this: `?(stream)->write(buffer)` is an expression. What type
> does it resolve to?
Same as 'stream->write(buffer)'. The effect of '?()' applies to the
entire statement.
> So if the condition is false, what does the overall expression resolve to?
> [...] does the condition being false completely wipe out the entire statement.
Yes.
> That is, even the += is part of the condition. If so, that requires
> look-ahead. Potentially *lots* of look-ahead.
And yes. As I said, I realize it's ugly. While I think it would be a
useful feature to have, I'd have a hard time actually supporting such a
proposal.
> ?: makes it clear exactly what's going on:
>
> written += stream ? stream->write(buffer) : 0;
....and, at least for POD types, compilers can hopefully optimize this to
the same code, anyway. The main places where '?(expr)' would be useful
are where 'expr' is complex. Such cases are not likely to be common,
however, and the benefits not likely worth the problems.
>> (I'll note that part of the motivation here probably comes from wanting
>> to dodge draconian coding styles that mandate multiline braces around
>> ANY conditional body. Which, I'll be honest, I've done myself...
>> employed ugly hacks to dodge such, I mean; I personally loathe requiring
>> braces in single-statement conditional bodies.)
>
> That's a pretty poor motivation for a language feature.
Oh, agreed :-). I didn't mean to imply otherwise.
--
Matthew
--
---
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/.
.
Author: Myriachan <myriachan@gmail.com>
Date: Thu, 24 Sep 2015 13:51:26 -0700 (PDT)
Raw View
------=_Part_1637_1965809576.1443127886946
Content-Type: multipart/alternative;
boundary="----=_Part_1638_1766924748.1443127886946"
------=_Part_1638_1766924748.1443127886946
Content-Type: text/plain; charset=UTF-8
On Thursday, September 24, 2015 at 12:51:03 PM UTC-7, Nicol Bolas wrote:
>
>
> ?: makes it clear exactly what's going on:
>
> written += stream ? stream->write(buffer) : 0;
>
>
I'd argue that this is pretty clear as well:
void Meow(Kitty *kitty = nullptr)
{
(kitty ? : GetDefaultCat())->Meow();
}
That's a pretty poor motivation for a language feature.
>
The ? : version with empty middle is a longstanding extension supported by
both GCC and Clang. I think that the ?()-> stuff is really weird, though.
a ? : b is also nice in that a is evaluated only once.
Melissa
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_1638_1766924748.1443127886946
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<br>On Thursday, September 24, 2015 at 12:51:03 PM UTC-7, Nicol Bolas wrote=
:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bo=
rder-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><br><div>?: =
makes it clear exactly what's going on:<br><br><div style=3D"background=
-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;bo=
rder-width:1px;word-wrap:break-word"><code><div><span style=3D"color:#000">=
written </span><span style=3D"color:#660">+=3D</span><span style=3D"color:#=
000"> stream </span><span style=3D"color:#660">?</span><span style=3D"color=
:#000"> stream</span><span style=3D"color:#660">-></span><span style=3D"=
color:#000">write</span><span style=3D"color:#660">(</span><span style=3D"c=
olor:#000">buffer</span><span style=3D"color:#660">)</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#660">:</span><span style=3D"color:=
#000"> </span><span style=3D"color:#066">0</span><span style=3D"color:#660"=
>;</span></div></code></div><br></div></div></blockquote><div><br>I'd a=
rgue that this is pretty clear as well:<br><br><div class=3D"prettyprint" s=
tyle=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 1=
87); border-style: solid; border-width: 1px; word-wrap: break-word;"><code =
class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #=
008;" class=3D"styled-by-prettify">void</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"=
styled-by-prettify">Meow</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">(</span><span style=3D"color: #606;" class=3D"styled-by-prett=
ify">Kitty</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">kitty </span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">nullptr</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">kitty </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">?</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">GetDefaultCat</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">())-></span><span styl=
e=3D"color: #606;" class=3D"styled-by-prettify">Meow</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">();</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br></span></div></code></div><br><blockquote style=3D"=
margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); paddi=
ng-left: 1ex;" class=3D"gmail_quote">That's a pretty poor motivation fo=
r a language feature.<br></blockquote><br>The ? : version with empty middle=
is a longstanding extension supported by both GCC and Clang.=C2=A0 I think=
that the ?()-> stuff is really weird, though.<br><br>a ? : b is also ni=
ce in that a is evaluated only once.<br><br>Melissa<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_1638_1766924748.1443127886946--
------=_Part_1637_1965809576.1443127886946--
.
Author: joewoodbury@gmail.com
Date: Sat, 26 Sep 2015 13:11:39 -0700 (PDT)
Raw View
------=_Part_4021_641098898.1443298299612
Content-Type: multipart/alternative;
boundary="----=_Part_4022_267548149.1443298299612"
------=_Part_4022_267548149.1443298299612
Content-Type: text/plain; charset=UTF-8
I hang my head in shame. Need to think more before posting.
On Tuesday, September 22, 2015 at 7:53:07 PM UTC-7, Nicol Bolas wrote:
>
>
>
> On Tuesday, September 22, 2015 at 8:34:20 PM UTC-4, joewo...@gmail.com
> wrote:
>>
>> Here in interesting example I just encountered:
>>
>> strLen is passed into a function along with pStr. After nullptr checks,
>> the following is done:
>>
>> size_t tmpStrLen = wcslen(pStr);
>> if (strLen > tmpStrLen)
>> strLen = tmpStrLen;
>>
>> Using the ?: operator, you could do:
>>
>> strLen = wcslen(pStr) < strLen ?: strLen;
>>
>> Again, a trivial example, but one in actual code.
>>
>
> And this code would have made it much more clear what you were doing:
>
> strLen = std::min(wcslen(pStr), strLen);
>
> Also, I'm not sure how your suggestion is equivalent to the original. I
> see you have an expression that evaluates to bool. And I see you have an
> expression which will be evaluated if the boolean expression is true.
>
> I don't see what the value of that expression will be if the boolean
> expression is false. So I'm not clear on exactly what your code means.
>
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_4022_267548149.1443298299612
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I hang my head in shame. Need to think more before posting=
..<br><br>On Tuesday, September 22, 2015 at 7:53:07 PM UTC-7, Nicol Bolas wr=
ote:<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"><br><br>O=
n Tuesday, September 22, 2015 at 8:34:20 PM UTC-4, <a>joewo...@gmail.com</a=
> wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8=
ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Here in in=
teresting example I just encountered:<br><br>strLen is passed into a functi=
on along with pStr. After nullptr checks, the following is done:<br><br>=C2=
=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 size_t tmpStrLen =3D =
wcslen(pStr);<br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 i=
f (strLen > tmpStrLen)<br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=
=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 strLen =3D tmpStrLen;<br><br>Using the ?: o=
perator, you could do:<br><br>=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=
=C2=A0=C2=A0 strLen =3D wcslen(pStr) < strLen ?: strLen;<br><br>Again, a=
trivial example, but one in actual code.<br></div></blockquote><div dir=3D=
"ltr"><br>And this code would have made it much more clear what you were do=
ing:<br><br><div style=3D"background-color:rgb(250,250,250);border-color:rg=
b(187,187,187);border-style:solid;border-width:1px;word-wrap:break-word"><c=
ode><div><span style=3D"color:#000">strLen </span><span style=3D"color:#660=
">=3D</span><span style=3D"color:#000"> std</span><span style=3D"color:#660=
">::</span><span style=3D"color:#000">min</span><span style=3D"color:#660">=
(</span><span style=3D"color:#000">wcslen</span><span style=3D"color:#660">=
(</span><span style=3D"color:#000">pStr</span><span style=3D"color:#660">),=
</span><span style=3D"color:#000"> strLen</span><span style=3D"color:#660">=
);</span><span style=3D"color:#000"><br></span></div></code></div><br>Also,=
I'm not sure how your suggestion is equivalent to the original. I see =
you have an expression that evaluates to bool. And I see you have an expres=
sion which will be evaluated if the boolean expression is true.<br><br>I do=
n't see what the value of that expression will be if the boolean expres=
sion is false. So I'm not clear on exactly what your code means.<br></d=
iv></div></blockquote></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_4022_267548149.1443298299612--
------=_Part_4021_641098898.1443298299612--
.