Topic: Initializer List as parameter to any_of, none_of,
Author: pushkoff@gmail.com
Date: Thu, 25 Feb 2016 03:19:09 -0800 (PST)
Raw View
------=_Part_277_166138114.1456399149505
Content-Type: multipart/alternative;
boundary="----=_Part_278_1366208920.1456399149506"
------=_Part_278_1366208920.1456399149506
Content-Type: text/plain; charset=UTF-8
It would be great to have functions any_of, none_of, all_of what works with
initializer lists
now it is:
int a = 0, b = 0, c = 1;
std::initializer_list<int> arr = {a,b,c};
if (std::any_of(std::begin(arr), std::end(arr), [](int x){return x > 0;}))
std::cout<< "any > 0" <<std::endl;
proposal is:
int a = 0, b = 0, c = 1;
if (std::any_of({a,b,c}, [](int x){return x > 0;}))
std::cout<< "any > 0" <<std::endl;
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/20d70f22-a54b-4a72-9e03-6412dda1d497%40isocpp.org.
------=_Part_278_1366208920.1456399149506
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">It would be great to have functions any_of, none_of, all_o=
f what works with initializer lists<br><br>now it is:<div><br></div><div><d=
iv class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); wor=
d-wrap: break-word; background-color: rgb(250, 250, 250);"><code class=3D"p=
rettyprint"><div class=3D"subprettyprint"><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">=C2=A0</span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> a </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">=3D</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><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> b </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" clas=
s=3D"styled-by-prettify">0</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> c </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: #066;" class=3D"styled-by-prettify">1</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>=C2=A0std</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify">initializer_list</span><span style=3D"c=
olor: #080;" class=3D"styled-by-prettify"><int></span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> arr </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: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">a</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify">b</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">c</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br>=C2=A0</span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">if</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"style=
d-by-prettify">std</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
any_of</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">begin</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">arr</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">),</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">::</span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">end</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">arr</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">),</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">[](</span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">int</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> x</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">){</span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">return</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> x </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&g=
t;</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 sty=
le=3D"color: #660;" class=3D"styled-by-prettify">;}))</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0std</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify">cout</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=
: #080;" class=3D"styled-by-prettify">"any > 0"</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify"><<</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">std</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">endl</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">;</span></div></code></div><div><br></div></div><div>prop=
osal is:<br><br><div class=3D"prettyprint" style=3D"border: 1px solid rgb(1=
87, 187, 187); word-wrap: break-word; background-color: rgb(250, 250, 250);=
"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"=
color: #000;" class=3D"styled-by-prettify">=C2=A0</span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">int</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> a </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-p=
rettify">0</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> b </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: #066;" class=3D"styled-by-prettify">0</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> c </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify=
">1</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</span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">if</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">std</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">any_of</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">({</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">a</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">b</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">c</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">},</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">[](</span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> x</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)=
{</span><span style=3D"color: #008;" class=3D"styled-by-prettify">return</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> x </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">></span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #066;" class=3D"styled-by-prettify">0</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">;}))</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0std</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">cout</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify"><<</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=3D"sty=
led-by-prettify">"any > 0"</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"st=
yled-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">endl</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</=
span></div></code></div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/20d70f22-a54b-4a72-9e03-6412dda1d497%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/20d70f22-a54b-4a72-9e03-6412dda1d497=
%40isocpp.org</a>.<br />
------=_Part_278_1366208920.1456399149506--
------=_Part_277_166138114.1456399149505--
.
Author: =?UTF-8?Q?Daniel_Kr=C3=BCgler?= <daniel.kruegler@gmail.com>
Date: Thu, 25 Feb 2016 12:43:43 +0100
Raw View
2016-02-25 12:19 GMT+01:00 <pushkoff@gmail.com>:
> It would be great to have functions any_of, none_of, all_of what works with
> initializer lists
>
> now it is:
>
> int a = 0, b = 0, c = 1;
> std::initializer_list<int> arr = {a,b,c};
> if (std::any_of(std::begin(arr), std::end(arr), [](int x){return x > 0;}))
> std::cout<< "any > 0" <<std::endl;
>
> proposal is:
>
> int a = 0, b = 0, c = 1;
> if (std::any_of({a,b,c}, [](int x){return x > 0;}))
> std::cout<< "any > 0" <<std::endl;
This feature would automatically fall out of the range TS,
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4569.pdf
because an std::initializer_list meets the requirements for the
InputRange concept (See the any_of declaration accepting ranges on
page 122).
- Daniel
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAGNvRgBhsGBP7U-n-X091eXWymBOahjczMW0yqhPmBNHxDEWuA%40mail.gmail.com.
.
Author: "T. C." <rs2740@gmail.com>
Date: Sun, 28 Feb 2016 01:44:26 -0800 (PST)
Raw View
------=_Part_2178_1498793676.1456652666797
Content-Type: multipart/alternative;
boundary="----=_Part_2179_1107751520.1456652666797"
------=_Part_2179_1107751520.1456652666797
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Thursday, February 25, 2016 at 7:43:46 PM UTC+8, Daniel Kr=C3=BCgler wro=
te:
>
> 2016-02-25 12:19 GMT+01:00 <push...@gmail.com <javascript:>>:=20
> > It would be great to have functions any_of, none_of, all_of what works=
=20
> with=20
> > initializer lists=20
> >=20
> > now it is:=20
> >=20
> > int a =3D 0, b =3D 0, c =3D 1;=20
> > std::initializer_list<int> arr =3D {a,b,c};=20
> > if (std::any_of(std::begin(arr), std::end(arr), [](int x){return x >=
=20
> 0;}))=20
> > std::cout<< "any > 0" <<std::endl;=20
> >=20
> > proposal is:=20
> >=20
> > int a =3D 0, b =3D 0, c =3D 1;=20
> > if (std::any_of({a,b,c}, [](int x){return x > 0;}))=20
> > std::cout<< "any > 0" <<std::endl;=20
>
> This feature would automatically fall out of the range TS,=20
>
=20
Not the one in OP's code, though, because you can't deduce=20
std::initializer_list out of {a, b, c}. For that to work, you'll need an=20
overload taking a std::initializer_list<T>.
I'm not sure providing such an overload is a good idea, though, since=20
constructing the backing array is a lot of copying.
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/a0bc78e7-39b4-4cfd-918b-51f85927160f%40isocpp.or=
g.
------=_Part_2179_1107751520.1456652666797
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Thursday, February 25, 2016 at 7:43:46 PM UTC+8=
, Daniel Kr=C3=BCgler wrote:<blockquote class=3D"gmail_quote" style=3D"marg=
in: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">20=
16-02-25 12:19 GMT+01:00 =C2=A0<<a href=3D"javascript:" target=3D"_blank=
" gdf-obfuscated-mailto=3D"VT-SF9ORAgAJ" rel=3D"nofollow" onmousedown=3D"th=
is.href=3D'javascript:';return true;" onclick=3D"this.href=3D'j=
avascript:';return true;">push...@gmail.com</a>>:
<br>> It would be great to have functions any_of, none_of, all_of what w=
orks with
<br>> initializer lists
<br>>
<br>> now it is:
<br>>
<br>> =C2=A0int a =3D 0, b =3D 0, c =3D 1;
<br>> =C2=A0std::initializer_list<int> arr =3D {a,b,c};
<br>> =C2=A0if (std::any_of(std::begin(arr), std::end(arr), [](int x){re=
turn x > 0;}))
<br>> =C2=A0 =C2=A0 =C2=A0std::cout<< "any > 0" <&=
lt;std::endl;
<br>>
<br>> proposal is:
<br>>
<br>> =C2=A0int a =3D 0, b =3D 0, c =3D 1;
<br>> =C2=A0if (std::any_of({a,b,c}, [](int x){return x > 0;}))
<br>> =C2=A0 =C2=A0 =C2=A0std::cout<< "any > 0" <&=
lt;std::endl;
<br>
<br>This feature would automatically fall out of the range TS,=C2=A0<br></b=
lockquote><div>=C2=A0</div><div>Not the one in OP's code, though, becau=
se you can't deduce std::initializer_list out of {a, b, c}. For that to=
work, you'll need an overload taking a std::initializer_list<T>.=
<br></div><div><br></div><div>I'm not sure providing such an overload i=
s a good idea, though, since constructing the backing array is a lot of cop=
ying.</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/a0bc78e7-39b4-4cfd-918b-51f85927160f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/a0bc78e7-39b4-4cfd-918b-51f85927160f=
%40isocpp.org</a>.<br />
------=_Part_2179_1107751520.1456652666797--
------=_Part_2178_1498793676.1456652666797--
.
Author: =?UTF-8?Q?Daniel_Kr=C3=BCgler?= <daniel.kruegler@gmail.com>
Date: Sun, 28 Feb 2016 19:57:45 +0100
Raw View
2016-02-28 10:44 GMT+01:00 T. C. <rs2740@gmail.com>:
> Not the one in OP's code, though, because you can't deduce
> std::initializer_list out of {a, b, c}. For that to work, you'll need an
> overload taking a std::initializer_list<T>.
Agreed, I didn't look careful enough at the OP's code.
- Daniel
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAGNvRgAh%2BJS%2B1tdZnNCokuGX0%3DQLyBb%2BLELHbjNDOC2oaEcYLQ%40mail.gmail.com.
.