Topic: Using templated variables to upgrade std::placeholders
Author: martin.molzer@gmx.de
Date: Mon, 14 Sep 2015 09:52:55 -0700 (PDT)
Raw View
------=_Part_701_1131883267.1442249575205
Content-Type: multipart/alternative;
boundary="----=_Part_702_599764755.1442249575205"
------=_Part_702_599764755.1442249575205
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Currently std::placeholders lacks a bit of standardization:
namespace placeholders {
// M is the implementation-defined number of placeholders
extern unspecified _1;
extern unspecified _2;
....
extern unspecified _M;
}
Annex B specifies (2.41) =E2=80=94 Number of placeholders (20.9.10.4) [10].=
as=20
recommended minimum. With templated variables however one can easily=20
improve this to
namespace placeholders {
template<size_t N>
extern unspecified _; // _<0> behaves as _1, or make it 1-based
}
and it would be used like
int func(int a, int b)
{
return a + b;
}
// ...
auto call =3D std::bind(func, std::placeholders::_<0>, 3);
call(2); // Returns 5
--=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/.
------=_Part_702_599764755.1442249575205
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Currently std::placeholders lacks a bit of standardization=
:<br><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 25=
0); border-color: rgb(187, 187, 187); border-style: solid; border-width: 1p=
x; word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subpre=
ttyprint"><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">namespace</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> placeholders =
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span st=
yle=3D"color: #800;" class=3D"styled-by-prettify">// M is the implementatio=
n-defined number of placeholders</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">extern</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> unspecified _1</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">extern</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
unspecified _2</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">;</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><span =
style=3D"color: #008;" class=3D"styled-by-prettify">extern</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> unspecified _M</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br></span></div></code></div><br>Annex B spec=
ifies (2.41) =E2=80=94 Number of placeholders (20.9.10.4) [10]. as recommen=
ded minimum. With templated variables however one can easily improve this t=
o<br><br><div class=3D"prettyprint" style=3D"background-color: rgb(250, 250=
, 250); border-color: rgb(187, 187, 187); border-style: solid; border-width=
: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"su=
bprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">nam=
espace</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> pla=
ceholders </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">template</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify">size_t N</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">></span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">extern</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> unspecified _</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: #800;" class=3D"=
styled-by-prettify">// _<0> behaves as _1, or make it 1-based</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><br=
>and it would be used like<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: #008;" class=
=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> func</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> a</=
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: #008;" class=3D"styled-by-prettify">int</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> b</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br>=C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">return</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><=
span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #800;" cl=
ass=3D"styled-by-prettify">// ...</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">auto</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> call </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">bind</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">func</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000=
;" 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">placeholders</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">_</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y"><</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 style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #066;" class=3D"styled-by-prettify">3</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br>call</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">(</span><span style=3D"color: #066;" class=3D=
"styled-by-prettify">2</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #800;" class=3D"styled-by-prettify">// Re=
turns 5</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
></span></div></code></div><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_702_599764755.1442249575205--
------=_Part_701_1131883267.1442249575205--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Mon, 14 Sep 2015 11:58:18 -0700 (PDT)
Raw View
------=_Part_3703_532588735.1442257098813
Content-Type: multipart/alternative;
boundary="----=_Part_3704_1181596992.1442257098814"
------=_Part_3704_1181596992.1442257098814
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Monday, September 14, 2015 at 12:52:55 PM UTC-4, martin...@gmx.de wrote:
>
> Currently std::placeholders lacks a bit of standardization:
>
> namespace placeholders {
> // M is the implementation-defined number of placeholders
> extern unspecified _1;
> extern unspecified _2;
> ...
> extern unspecified _M;
> }
>
> Annex B specifies (2.41) =E2=80=94 Number of placeholders (20.9.10.4) [10=
]. as=20
> recommended minimum. With templated variables however one can easily=20
> improve this to
>
> namespace placeholders {
> template<size_t N>
> extern unspecified _; // _<0> behaves as _1, or make it 1-based
> }
>
> and it would be used like
>
> int func(int a, int b)
> {
> return a + b;
> }
> // ...
> auto call =3D std::bind(func, std::placeholders::_<0>, 3);
> call(2); // Returns 5
>
>
>
A better question: why are you using std::bind often enough to need this? I=
=20
thought C++14 and polymorphic lambdas basically killed 99% of the uses for=
=20
std::bind?
auto call =3D [](const auto &x) {return func(x, 3);}
call(2);
Not only is that shorter, it's also clearer as to exactly what it is doing.=
=20
It also preserves function overloading, unlike std::bind.
--=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/.
------=_Part_3704_1181596992.1442257098814
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<br><br>On Monday, September 14, 2015 at 12:52:55 PM UTC-4, martin...@gmx.d=
e wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0=
..8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Curre=
ntly std::placeholders lacks a bit of standardization:<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=
:#000"><br></span><span style=3D"color:#008">namespace</span><span style=3D=
"color:#000"> placeholders </span><span style=3D"color:#660">{</span><span =
style=3D"color:#000"><br></span><span style=3D"color:#800">// M is the impl=
ementation-defined number of placeholders</span><span style=3D"color:#000">=
<br></span><span style=3D"color:#008">extern</span><span style=3D"color:#00=
0"> unspecified _1</span><span style=3D"color:#660">;</span><span style=3D"=
color:#000"><br></span><span style=3D"color:#008">extern</span><span style=
=3D"color:#000"> unspecified _2</span><span style=3D"color:#660">;</span><s=
pan style=3D"color:#000"><br></span><span style=3D"color:#660">...</span><s=
pan style=3D"color:#000"><br></span><span style=3D"color:#008">extern</span=
><span style=3D"color:#000"> unspecified _M</span><span style=3D"color:#660=
">;</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">=
}</span><span style=3D"color:#000"><br></span></div></code></div><br>Annex =
B specifies (2.41) =E2=80=94 Number of placeholders (20.9.10.4) [10]. as re=
commended minimum. With templated variables however one can easily improve =
this to<br><br><div style=3D"background-color:rgb(250,250,250);border-color=
:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:break-word"=
><code><div><span style=3D"color:#008">namespace</span><span style=3D"color=
:#000"> placeholders </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"><br></span><span style=3D"color:#008">template</span><span =
style=3D"color:#660"><</span><span style=3D"color:#000">size_t N</span><=
span style=3D"color:#660">></span><span style=3D"color:#000"><br></span>=
<span style=3D"color:#008">extern</span><span style=3D"color:#000"> unspeci=
fied _</span><span style=3D"color:#660">;</span><span style=3D"color:#000">=
</span><span style=3D"color:#800">// _<0> behaves as _1, or make it =
1-based</span><span style=3D"color:#000"><br></span><span style=3D"color:#6=
60">}</span><span style=3D"color:#000"><br></span></div></code></div><br>an=
d it would be used like<br><br><div style=3D"background-color:rgb(250,250,2=
50);border-color:rgb(187,187,187);border-style:solid;border-width:1px;word-=
wrap:break-word"><code><div><span style=3D"color:#008">int</span><span styl=
e=3D"color:#000"> func</span><span style=3D"color:#660">(</span><span style=
=3D"color:#008">int</span><span style=3D"color:#000"> a</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#008">int</span><span style=3D"color:#000"> b</span><span style=3D"col=
or:#660">)</span><span style=3D"color:#000"><br></span><span style=3D"color=
:#660">{</span><span style=3D"color:#000"><br>=C2=A0 </span><span style=3D"=
color:#008">return</span><span style=3D"color:#000"> a </span><span style=
=3D"color:#660">+</span><span style=3D"color:#000"> b</span><span style=3D"=
color:#660">;</span><span style=3D"color:#000"><br></span><span style=3D"co=
lor:#660">}</span><span style=3D"color:#000"><br></span><span style=3D"colo=
r:#800">// ...</span><span style=3D"color:#000"><br></span><span style=3D"c=
olor:#008">auto</span><span style=3D"color:#000"> call </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">bind</span><span style=
=3D"color:#660">(</span><span style=3D"color:#000">func</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> std</span><span style=
=3D"color:#660">::</span><span style=3D"color:#000">placeholders</span><spa=
n style=3D"color:#660">::</span><span style=3D"color:#000">_</span><span st=
yle=3D"color:#660"><</span><span style=3D"color:#066">0</span><span styl=
e=3D"color:#660">>,</span><span style=3D"color:#000"> </span><span style=
=3D"color:#066">3</span><span style=3D"color:#660">);</span><span style=3D"=
color:#000"><br>call</span><span style=3D"color:#660">(</span><span style=
=3D"color:#066">2</span><span style=3D"color:#660">);</span><span style=3D"=
color:#000"> </span><span style=3D"color:#800">// Returns 5</span><span sty=
le=3D"color:#000"><br></span></div></code></div><br><br></div></blockquote>=
<div><br>A better question: why are you using std::bind often enough to nee=
d this? I thought C++14 and polymorphic lambdas basically killed 99% of the=
uses for std::bind?<br><br><div class=3D"prettyprint" style=3D"background-=
color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: =
solid; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprin=
t"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> call </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">=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: #008;" class=3D"styled-by-prettify">const</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">auto</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">x</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">return</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> func</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">x</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">3</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">);}</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br>call</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">(</span><span style=3D"color: #066;" class=3D"styled-by-prettify">2</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">);</span></div><=
/code></div><br>Not only is that shorter, it's also clearer as to exact=
ly what it is doing. It also preserves function overloading, unlike std::bi=
nd.<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_3704_1181596992.1442257098814--
------=_Part_3703_532588735.1442257098813--
.
Author: Tomasz <tomaszkam@gmail.com>
Date: Mon, 14 Sep 2015 12:55:07 -0700 (PDT)
Raw View
------=_Part_921_2106375911.1442260507900
Content-Type: multipart/alternative;
boundary="----=_Part_922_8287726.1442260507900"
------=_Part_922_8287726.1442260507900
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
W dniu poniedzia=C5=82ek, 14 wrze=C5=9Bnia 2015 20:58:19 UTC+2 u=C5=BCytkow=
nik Nicol Bolas=20
napisa=C5=82:
>
>
>
> On Monday, September 14, 2015 at 12:52:55 PM UTC-4, martin...@gmx.de=20
> wrote:
>>
>> Currently std::placeholders lacks a bit of standardization:
>>
>> namespace placeholders {
>> // M is the implementation-defined number of placeholders
>> extern unspecified _1;
>> extern unspecified _2;
>> ...
>> extern unspecified _M;
>> }
>>
>> Annex B specifies (2.41) =E2=80=94 Number of placeholders (20.9.10.4) [1=
0]. as=20
>> recommended minimum. With templated variables however one can easily=20
>> improve this to
>>
>> namespace placeholders {
>> template<size_t N>
>> extern unspecified _; // _<0> behaves as _1, or make it 1-based
>> }
>>
>> and it would be used like
>>
>> int func(int a, int b)
>> {
>> return a + b;
>> }
>> // ...
>> auto call =3D std::bind(func, std::placeholders::_<0>, 3);
>> call(2); // Returns 5
>>
>>
>>
> A better question: why are you using std::bind often enough to need this?=
=20
> I thought C++14 and polymorphic lambdas basically killed 99% of the uses=
=20
> for std::bind?
>
> auto call =3D [](const auto &x) {return func(x, 3);}
> call(2);
>
> Not only is that shorter, it's also clearer as to exactly what it is=20
> doing. It also preserves function overloading, unlike std::bind.
>
Why we need bind when we have a generic lambda?=20
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4171.html#appendi=
x.bind_vs_lambda>
--=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/.
------=_Part_922_8287726.1442260507900
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<br><br>W dniu poniedzia=C5=82ek, 14 wrze=C5=9Bnia 2015 20:58:19 UTC+2 u=C5=
=BCytkownik Nicol Bolas napisa=C5=82:<blockquote class=3D"gmail_quote" styl=
e=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left:=
1ex;"><br><br>On Monday, September 14, 2015 at 12:52:55 PM UTC-4, <a>marti=
n...@gmx.de</a> wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;m=
argin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"l=
tr">Currently std::placeholders lacks a bit of standardization:<br><div sty=
le=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);borde=
r-style:solid;border-width:1px;word-wrap:break-word"><code><div><span style=
=3D"color:#000"><br></span><span style=3D"color:#008">namespace</span><span=
style=3D"color:#000"> placeholders </span><span style=3D"color:#660">{</sp=
an><span style=3D"color:#000"><br></span><span style=3D"color:#800">// M is=
the implementation-defined number of placeholders</span><span style=3D"col=
or:#000"><br></span><span style=3D"color:#008">extern</span><span style=3D"=
color:#000"> unspecified _1</span><span style=3D"color:#660">;</span><span =
style=3D"color:#000"><br></span><span style=3D"color:#008">extern</span><sp=
an style=3D"color:#000"> unspecified _2</span><span style=3D"color:#660">;<=
/span><span style=3D"color:#000"><br></span><span style=3D"color:#660">...<=
/span><span style=3D"color:#000"><br></span><span style=3D"color:#008">exte=
rn</span><span style=3D"color:#000"> unspecified _M</span><span style=3D"co=
lor:#660">;</span><span style=3D"color:#000"><br></span><span style=3D"colo=
r:#660">}</span><span style=3D"color:#000"><br></span></div></code></div><b=
r>Annex B specifies (2.41) =E2=80=94 Number of placeholders (20.9.10.4) [10=
]. as recommended minimum. With templated variables however one can easily =
improve this to<br><br><div style=3D"background-color:rgb(250,250,250);bord=
er-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:bre=
ak-word"><code><div><span style=3D"color:#008">namespace</span><span style=
=3D"color:#000"> placeholders </span><span style=3D"color:#660">{</span><sp=
an style=3D"color:#000"><br></span><span style=3D"color:#008">template</spa=
n><span style=3D"color:#660"><</span><span style=3D"color:#000">size_t N=
</span><span style=3D"color:#660">></span><span style=3D"color:#000"><br=
></span><span style=3D"color:#008">extern</span><span style=3D"color:#000">=
unspecified _</span><span style=3D"color:#660">;</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#800">// _<0> behaves as _1, or =
make it 1-based</span><span style=3D"color:#000"><br></span><span style=3D"=
color:#660">}</span><span style=3D"color:#000"><br></span></div></code></di=
v><br>and it would be used like<br><br><div style=3D"background-color:rgb(2=
50,250,250);border-color:rgb(187,187,187);border-style:solid;border-width:1=
px;word-wrap:break-word"><code><div><span style=3D"color:#008">int</span><s=
pan style=3D"color:#000"> func</span><span style=3D"color:#660">(</span><sp=
an style=3D"color:#008">int</span><span style=3D"color:#000"> a</span><span=
style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#008">int</span><span style=3D"color:#000"> b</span><span style=
=3D"color:#660">)</span><span style=3D"color:#000"><br></span><span style=
=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 </span><span =
style=3D"color:#008">return</span><span style=3D"color:#000"> a </span><spa=
n style=3D"color:#660">+</span><span style=3D"color:#000"> b</span><span st=
yle=3D"color:#660">;</span><span style=3D"color:#000"><br></span><span styl=
e=3D"color:#660">}</span><span style=3D"color:#000"><br></span><span style=
=3D"color:#800">// ...</span><span style=3D"color:#000"><br></span><span st=
yle=3D"color:#008">auto</span><span style=3D"color:#000"> call </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">bind</span><span =
style=3D"color:#660">(</span><span style=3D"color:#000">func</span><span st=
yle=3D"color:#660">,</span><span style=3D"color:#000"> std</span><span styl=
e=3D"color:#660">::</span><span style=3D"color:#000">placeholders</span><sp=
an style=3D"color:#660">::</span><span style=3D"color:#000">_</span><span s=
tyle=3D"color:#660"><</span><span style=3D"color:#066">0</span><span sty=
le=3D"color:#660">>,</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#066">3</span><span style=3D"color:#660">);</span><span style=3D=
"color:#000"><br>call</span><span style=3D"color:#660">(</span><span style=
=3D"color:#066">2</span><span style=3D"color:#660">);</span><span style=3D"=
color:#000"> </span><span style=3D"color:#800">// Returns 5</span><span sty=
le=3D"color:#000"><br></span></div></code></div><br><br></div></blockquote>=
<div><br>A better question: why are you using std::bind often enough to nee=
d this? I thought C++14 and polymorphic lambdas basically killed 99% of the=
uses for std::bind?<br><br><div style=3D"background-color:rgb(250,250,250)=
;border-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wra=
p:break-word"><code><div><span style=3D"color:#008">auto</span><span style=
=3D"color:#000"> call </span><span style=3D"color:#660">=3D</span><span sty=
le=3D"color:#000"> </span><span style=3D"color:#660">[](</span><span style=
=3D"color:#008">const</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">auto</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">&</span><span style=3D"color:#000">x</span><span style=
=3D"color:#660">)</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#660">{</span><span style=3D"color:#008">return</span><span style=3D"c=
olor:#000"> func</span><span style=3D"color:#660">(</span><span style=3D"co=
lor:#000">x</span><span style=3D"color:#660">,</span><span style=3D"color:#=
000"> </span><span style=3D"color:#066">3</span><span style=3D"color:#660">=
);}</span><span style=3D"color:#000"><br>call</span><span style=3D"color:#6=
60">(</span><span style=3D"color:#066">2</span><span style=3D"color:#660">)=
;</span></div></code></div><br>Not only is that shorter, it's also clea=
rer as to exactly what it is doing. It also preserves function overloading,=
unlike std::bind.<br></div></blockquote><div><br><code><a href=3D"http://w=
ww.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4171.html#appendix.bind_vs=
_lambda">Why we need bind when we have a generic lambda?</a><span style=3D"=
color:#000"><br></span></code></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_922_8287726.1442260507900--
------=_Part_921_2106375911.1442260507900--
.