Topic: Overloading std::mem_fn to bind `this`
Author: Jim Porter <jvp4846@g.rit.edu>
Date: Thu, 18 Sep 2014 03:21:11 -0500
Raw View
Often, I find myself using std::bind (or, more lately, generic lambdas)
to bind `this` to a member function so I can pass it along somewhere
else, e.g.:
[this](auto &&...t) {
return do_something(std::forward<decltype(t)>(t)...);
}
While this is nice, it seems common enough to me that it would be useful
for the standard library to provide a helper function for it, especially
since the std::forward notation is moderately verbose. I'd like to
propose that the standard add an overload of std::mem_fn that takes
`this` and makes the following line roughly equivalent to the above:
std::mem_fn(&my_class::do_something, this);
This is (usually) shorter than the generic lambda version, and in my
opinion makes it clearer that all you're doing is binding `this` to a
member function. Does this sound like something worth considering?
- Jim
--
---
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: Roman Perepelitsa <roman.perepelitsa@gmail.com>
Date: Thu, 18 Sep 2014 10:29:40 +0200
Raw View
--089e014946f45fbb58050352ca40
Content-Type: text/plain; charset=UTF-8
2014-09-18 10:21 GMT+02:00 Jim Porter <jvp4846@g.rit.edu>:
> Often, I find myself using std::bind (or, more lately, generic lambdas) to
> bind `this` to a member function so I can pass it along somewhere else,
> e.g.:
>
> [this](auto &&...t) {
> return do_something(std::forward<decltype(t)>(t)...);
> }
>
> While this is nice, it seems common enough to me that it would be useful
> for the standard library to provide a helper function for it, especially
> since the std::forward notation is moderately verbose. I'd like to propose
> that the standard add an overload of std::mem_fn that takes `this` and
> makes the following line roughly equivalent to the above:
>
> std::mem_fn(&my_class::do_something, this);
>
The generalization of this facility is partial application
<http://en.wikipedia.org/wiki/Partial_application>.
std::partial_apply(&my_class::do_something, this)
std::partial_apply(&my_class::do_something, this, first_argument)
std::partial_apply(free_function, first_argument, second_argument)
std::mem_fn(arg) would be equivalent to std::partial_apply(arg).
std::partial_apply(), without arguments, also makes sense and is
occasionally useful.
Roman.
--
---
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/.
--089e014946f45fbb58050352ca40
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">2014=
-09-18 10:21 GMT+02:00 Jim Porter <span dir=3D"ltr"><<a href=3D"mailto:j=
vp4846@g.rit.edu" target=3D"_blank">jvp4846@g.rit.edu</a>></span>:<br><b=
lockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-le=
ft-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;pad=
ding-left:1ex">Often, I find myself using std::bind (or, more lately, gener=
ic lambdas) to bind `this` to a member function so I can pass it along some=
where else, e.g.:<br>
<br>
=C2=A0 [this](auto &&...t) {<br>
=C2=A0 =C2=A0 return do_something(std::forward<<u></u>decltype(t)>(t)=
....);<br>
=C2=A0 }<br>
<br>
While this is nice, it seems common enough to me that it would be useful fo=
r the standard library to provide a helper function for it, especially sinc=
e the std::forward notation is moderately verbose. I'd like to propose =
that the standard add an overload of std::mem_fn that takes `this` and make=
s the following line roughly equivalent to the above:<br>
<br>
=C2=A0 std::mem_fn(&my_class::do_<u></u>something, this);<br></blockquo=
te><div><br></div><div>The generalization of this facility is <a href=3D"ht=
tp://en.wikipedia.org/wiki/Partial_application">partial application</a>.</d=
iv><div><br></div><div>=C2=A0 std::partial_apply(&my_class::do_somethin=
g, this)</div><div>=C2=A0 std::partial_apply(&my_class::do_something, t=
his, first_argument)<br></div><div>=C2=A0 std::partial_apply(free_function,=
first_argument, second_argument)<br></div><div><br></div><div>std::mem_fn(=
arg) would be equivalent to std::partial_apply(arg). std::partial_apply(), =
without arguments, also makes sense and is occasionally useful.</div><div><=
br></div><div>Roman.</div></div></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 />
--089e014946f45fbb58050352ca40--
.
Author: Jim Porter <jvp4846@g.rit.edu>
Date: Fri, 19 Sep 2014 14:00:50 -0500
Raw View
On 9/18/2014 3:29 AM, Roman Perepelitsa wrote:
> The generalization of this facility is partial application
> <http://en.wikipedia.org/wiki/Partial_application>.
>
> std::partial_apply(&my_class::do_something, this)
> std::partial_apply(&my_class::do_something, this, first_argument)
> std::partial_apply(free_function, first_argument, second_argument)
>
> std::mem_fn(arg) would be equivalent to std::partial_apply(arg).
> std::partial_apply(), without arguments, also makes sense and is
> occasionally useful.
Yeah, I'd mentioned partial_apply the last time I brought this up, but
perhaps it would make sense to propose partial_apply in place of
std::mem_fn(func, this) (or maybe in addition to).
I suppose std::partial_apply(&my_class::do_something) would be
equivalent to the existing std::mem_fn function, so maybe there's an
argument for replacing std::mem_fn with std::partial_apply entirely. On
the other hand, std::mem_fn has the benefit of having a clearer name for
some uses...
- Jim
--
---
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: Mikhail Semenov <mikhailsemenov1957@gmail.com>
Date: Sat, 20 Sep 2014 07:08:27 -0700 (PDT)
Raw View
------=_Part_3119_2025482167.1411222107422
Content-Type: text/plain; charset=UTF-8
I made a proposal over a year ago, but it was rejected:
http://isocpp.org/blog/2013/07/new-paper-n3702-introducing-an-optional-parameter-for-mem-fn-mikhail-semeno
Here is a revised version that I tried to submit in September 2013:
https://dl.dropboxusercontent.com/u/35715999/mem_fn_revised_proposal.htm
The advice was to use a generalized lambda expression.
The issue is that you can easily define the member_delegate macro as shown
in the following program:
#include <iostream>
class A
{
double x;
public:
A(double x1) : x(x1){}
void sqr(double z) { x = z*z; }
explicit operator double() { return x; }
};
#define member_delegate(_a, _f) [&_a](auto&& ... x) { return (_a._f)(std::
forward<decltype(x)>(x) ...);}
int main()
{
A a(10);
auto f = member_delegate(a, A::sqr);
f(7);
std::cout << (double)a << std::endl;
int k;
std::cin >> k;
return 0;
}
On Friday, September 19, 2014 8:01:18 PM UTC+1, Jim Porter wrote:
> On 9/18/2014 3:29 AM, Roman Perepelitsa wrote:
> > The generalization of this facility is partial application
> > <http://en.wikipedia.org/wiki/Partial_application>.
> >
> > std::partial_apply(&my_class::do_something, this)
> > std::partial_apply(&my_class::do_something, this, first_argument)
> > std::partial_apply(free_function, first_argument, second_argument)
> >
> > std::mem_fn(arg) would be equivalent to std::partial_apply(arg).
> > std::partial_apply(), without arguments, also makes sense and is
> > occasionally useful.
>
> Yeah, I'd mentioned partial_apply the last time I brought this up, but
> perhaps it would make sense to propose partial_apply in place of
> std::mem_fn(func, this) (or maybe in addition to).
>
> I suppose std::partial_apply(&my_class::do_something) would be
> equivalent to the existing std::mem_fn function, so maybe there's an
> argument for replacing std::mem_fn with std::partial_apply entirely. On
> the other hand, std::mem_fn has the benefit of having a clearer name for
> some uses...
>
> - Jim
>
>
--
---
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_3119_2025482167.1411222107422
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>I made a proposal over a year ago, but it was rejecte=
d:</div><div><a href=3D"http://isocpp.org/blog/2013/07/new-paper-n3702-intr=
oducing-an-optional-parameter-for-mem-fn-mikhail-semeno">http://isocpp.org/=
blog/2013/07/new-paper-n3702-introducing-an-optional-parameter-for-mem-fn-m=
ikhail-semeno</a></div><div>Here is a revised version that I tried to submi=
t in September 2013:</div><div><a href=3D"https://dl.dropboxusercontent.com=
/u/35715999/mem_fn_revised_proposal.htm">https://dl.dropboxusercontent.com/=
u/35715999/mem_fn_revised_proposal.htm</a></div><div><br></div><div>The adv=
ice was to use a generalized lambda expression.</div><div><br></div><div>Th=
e issue is that you can easily define the member_delegate macro as shown in=
the following program:</div><div><br></div><div class=3D"prettyprint" styl=
e=3D"border: 1px solid rgb(187, 187, 187); border-image: none; -ms-word-wra=
p: break-word; background-color: rgb(250, 250, 250);"><code class=3D"pretty=
print"><div class=3D"subprettyprint"><span class=3D"styled-by-prettify" sty=
le=3D"color: rgb(136, 0, 0);">#include</span><span class=3D"styled-by-prett=
ify" style=3D"color: rgb(0, 0, 0);"> </span><span class=3D"styled-by-pretti=
fy" style=3D"color: rgb(0, 136, 0);"><iostream></span><span class=3D"=
styled-by-prettify" style=3D"color: rgb(0, 0, 0);"><br></span><span class=
=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 136);">class</span><span =
class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"> A<br></span><s=
pan class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">{</span=
><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"><br>&nbs=
p;</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 136);=
">double</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0,=
0);"> x</span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, =
102, 0);">;</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0,=
0, 0);"><br></span><span class=3D"styled-by-prettify" style=3D"color: rgb(=
0, 0, 136);">public</span><span class=3D"styled-by-prettify" style=3D"color=
: rgb(102, 102, 0);">:</span><span class=3D"styled-by-prettify" style=3D"co=
lor: rgb(0, 0, 0);"><br> A</span><span class=3D"styled-by-prettify" st=
yle=3D"color: rgb(102, 102, 0);">(</span><span class=3D"styled-by-prettify"=
style=3D"color: rgb(0, 0, 136);">double</span><span class=3D"styled-by-pre=
ttify" style=3D"color: rgb(0, 0, 0);"> x1</span><span class=3D"styled-by-pr=
ettify" style=3D"color: rgb(102, 102, 0);">)</span><span class=3D"styled-by=
-prettify" style=3D"color: rgb(0, 0, 0);"> </span><span class=3D"styled-by-=
prettify" style=3D"color: rgb(102, 102, 0);">:</span><span class=3D"styled-=
by-prettify" style=3D"color: rgb(0, 0, 0);"> x</span><span class=3D"styled-=
by-prettify" style=3D"color: rgb(102, 102, 0);">(</span><span class=3D"styl=
ed-by-prettify" style=3D"color: rgb(0, 0, 0);">x1</span><span class=3D"styl=
ed-by-prettify" style=3D"color: rgb(102, 102, 0);">){}</span><span class=3D=
"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"><br> </span><span =
class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 136);">void</span><s=
pan class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"> sqr</span>=
<span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">(</sp=
an><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 136);">doub=
le</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);">=
z</span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0=
);">)</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0)=
;"> </span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102,=
0);">{</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, =
0);"> x </span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, =
102, 0);">=3D</span><span class=3D"styled-by-prettify" style=3D"color: rgb(=
0, 0, 0);"> z</span><span class=3D"styled-by-prettify" style=3D"color: rgb(=
102, 102, 0);">*</span><span class=3D"styled-by-prettify" style=3D"color: r=
gb(0, 0, 0);">z</span><span class=3D"styled-by-prettify" style=3D"color: rg=
b(102, 102, 0);">;</span><span class=3D"styled-by-prettify" style=3D"color:=
rgb(0, 0, 0);"> </span><span class=3D"styled-by-prettify" style=3D"c=
olor: rgb(102, 102, 0);">}</span><span class=3D"styled-by-prettify" style=
=3D"color: rgb(0, 0, 0);"><br> </span><span class=3D"styled-by-prettif=
y" style=3D"color: rgb(0, 0, 136);">explicit</span><span class=3D"styled-by=
-prettify" style=3D"color: rgb(0, 0, 0);"> </span><span class=3D"styled-by-=
prettify" style=3D"color: rgb(0, 0, 136);">operator</span><span class=3D"st=
yled-by-prettify" style=3D"color: rgb(0, 0, 0);"> </span><span class=3D"sty=
led-by-prettify" style=3D"color: rgb(0, 0, 136);">double</span><span class=
=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">()</span><span c=
lass=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"> </span><span cl=
ass=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">{</span><span=
class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"> </span><span =
class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 136);">return</span>=
<span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"> x</span>=
<span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">;</sp=
an><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);">  =
;</span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0)=
;">}</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);=
"><br></span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 10=
2, 0);">};</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, =
0, 0);"><br><br></span><span class=3D"styled-by-prettify" style=3D"color: r=
gb(136, 0, 0);">#define</span><span class=3D"styled-by-prettify" style=3D"c=
olor: rgb(0, 0, 0);"> member_delegate</span><span class=3D"styled-by-pretti=
fy" style=3D"color: rgb(102, 102, 0);">(</span><span class=3D"styled-by-pre=
ttify" style=3D"color: rgb(0, 0, 0);">_a</span><span class=3D"styled-by-pre=
ttify" style=3D"color: rgb(102, 102, 0);">,</span><span class=3D"styled-by-=
prettify" style=3D"color: rgb(0, 0, 0);"> _f</span><span class=3D"styled-by=
-prettify" style=3D"color: rgb(102, 102, 0);">)</span><span class=3D"styled=
-by-prettify" style=3D"color: rgb(0, 0, 0);"> </span><span class=3D"styled-=
by-prettify" style=3D"color: rgb(102, 102, 0);">[&</span><span class=3D=
"styled-by-prettify" style=3D"color: rgb(0, 0, 0);">_a</span><span class=3D=
"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">](</span><span clas=
s=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 136);">auto</span><span =
class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">&&<=
/span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"> </=
span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">=
....</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"=
> x</span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, =
0);">)</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0=
);"> </span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102=
, 0);">{</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0,=
0);"> </span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, =
136);">return</span><span class=3D"styled-by-prettify" style=3D"color: rgb(=
0, 0, 0);"> </span><span class=3D"styled-by-prettify" style=3D"color: rgb(1=
02, 102, 0);">(</span><span class=3D"styled-by-prettify" style=3D"color: rg=
b(0, 0, 0);">_a</span><span class=3D"styled-by-prettify" style=3D"color: rg=
b(102, 102, 0);">.</span><span class=3D"styled-by-prettify" style=3D"color:=
rgb(0, 0, 0);">_f</span><span class=3D"styled-by-prettify" style=3D"color:=
rgb(102, 102, 0);">)(</span><span class=3D"styled-by-prettify" style=3D"co=
lor: rgb(0, 0, 0);">std</span><span class=3D"styled-by-prettify" style=3D"c=
olor: rgb(102, 102, 0);">::</span><span class=3D"styled-by-prettify" style=
=3D"color: rgb(0, 0, 0);">forward</span><span class=3D"styled-by-prettify" =
style=3D"color: rgb(102, 102, 0);"><</span><span class=3D"styled-by-pret=
tify" style=3D"color: rgb(0, 0, 136);">decltype</span><span class=3D"styled=
-by-prettify" style=3D"color: rgb(102, 102, 0);">(</span><span class=3D"sty=
led-by-prettify" style=3D"color: rgb(0, 0, 0);">x</span><span class=3D"styl=
ed-by-prettify" style=3D"color: rgb(102, 102, 0);">)>(</span><span class=
=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);">x</span><span class=
=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">)</span><span cl=
ass=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"> </span><span cla=
ss=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">...);}</span><=
span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"><br><br></=
span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 136);">in=
t</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"> =
main</span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102,=
0);">()</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0,=
0);"><br></span><span class=3D"styled-by-prettify" style=3D"color: rgb(102=
, 102, 0);">{</span><span class=3D"styled-by-prettify" style=3D"color: rgb(=
0, 0, 0);"><br> A a</span><span class=3D"styled-by-prettify" style=3D"=
color: rgb(102, 102, 0);">(</span><span class=3D"styled-by-prettify" style=
=3D"color: rgb(0, 102, 102);">10</span><span class=3D"styled-by-prettify" s=
tyle=3D"color: rgb(102, 102, 0);">);</span><span class=3D"styled-by-prettif=
y" style=3D"color: rgb(0, 0, 0);"><br> </span><span class=3D"styled-by=
-prettify" style=3D"color: rgb(0, 0, 136);">auto</span><span class=3D"style=
d-by-prettify" style=3D"color: rgb(0, 0, 0);"> f </span><span class=3D"styl=
ed-by-prettify" style=3D"color: rgb(102, 102, 0);">=3D</span><span class=3D=
"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"> member_delegate</span>=
<span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">(</sp=
an><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);">a</spa=
n><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">,</=
span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"> A</=
span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">=
::</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);">=
sqr</span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, =
0);">);</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, =
0);"><br> f</span><span class=3D"styled-by-prettify" style=3D"color: r=
gb(102, 102, 0);">(</span><span class=3D"styled-by-prettify" style=3D"color=
: rgb(0, 102, 102);">7</span><span class=3D"styled-by-prettify" style=3D"co=
lor: rgb(102, 102, 0);">);</span><span class=3D"styled-by-prettify" style=
=3D"color: rgb(0, 0, 0);"><br> std</span><span class=3D"styled-by-pret=
tify" style=3D"color: rgb(102, 102, 0);">::</span><span class=3D"styled-by-=
prettify" style=3D"color: rgb(0, 0, 0);">cout </span><span class=3D"styled-=
by-prettify" style=3D"color: rgb(102, 102, 0);"><<</span><span class=
=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"> </span><span class=
=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">(</span><span cl=
ass=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 136);">double</span><s=
pan class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">)</span=
><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);">a </span=
><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);"><=
<</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);=
"> std</span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 10=
2, 0);">::</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, =
0, 0);">endl</span><span class=3D"styled-by-prettify" style=3D"color: rgb(1=
02, 102, 0);">;</span><span class=3D"styled-by-prettify" style=3D"color: rg=
b(0, 0, 0);"><br> </span><span class=3D"styled-by-prettify" style=3D"c=
olor: rgb(0, 0, 136);">int</span><span class=3D"styled-by-prettify" style=
=3D"color: rgb(0, 0, 0);"> k</span><span class=3D"styled-by-prettify" style=
=3D"color: rgb(102, 102, 0);">;</span><span class=3D"styled-by-prettify" st=
yle=3D"color: rgb(0, 0, 0);"><br> std</span><span class=3D"styled-by-p=
rettify" style=3D"color: rgb(102, 102, 0);">::</span><span class=3D"styled-=
by-prettify" style=3D"color: rgb(0, 0, 0);">cin </span><span class=3D"style=
d-by-prettify" style=3D"color: rgb(102, 102, 0);">>></span><span clas=
s=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"> k</span><span clas=
s=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">;</span><span c=
lass=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"><br> </span=
><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 136);">return=
</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"> <=
/span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 102, 102);"=
>0</span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0=
);">;</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0)=
;"><br></span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 1=
02, 0);">}</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, =
0, 0);"><br><br><br><br><div class=3D"prettyprint" style=3D"border: 1px sol=
id rgb(187, 187, 187); border-image: none; -ms-word-wrap: break-word; backg=
round-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D=
"subprettyprint"><div class=3D"prettyprint" style=3D"border: 1px solid rgb(=
187, 187, 187); border-image: none; -ms-word-wrap: break-word; background-c=
olor: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"subpre=
ttyprint"><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 0, 10=
2);"><br></span></div></code></div><span class=3D"styled-by-prettify" style=
=3D"color: rgb(102, 102, 0);"><br></span></div></code></div><br><br></span>=
</div></code></div><div><br><br>On Friday, September 19, 2014 8:01:18 PM UT=
C+1, Jim Porter wrote:</div><blockquote class=3D"gmail_quote" style=3D"marg=
in: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, =
204); border-left-width: 1px; border-left-style: solid;">On 9/18/2014 3:29 =
AM, Roman Perepelitsa wrote:
<br>> The generalization of this facility is partial application
<br>> <<a onmousedown=3D"this.href=3D'http://www.google.com/url?q\75h=
ttp%3A%2F%2Fen.wikipedia.org%2Fwiki%2FPartial_application\46sa\75D\46sntz\0=
751\46usg\75AFQjCNF66V2DcfymtX4131R6c6cN4_eFbg';return true;" onclick=3D"th=
is.href=3D'http://www.google.com/url?q\75http%3A%2F%2Fen.wikipedia.org%2Fwi=
ki%2FPartial_application\46sa\75D\46sntz\0751\46usg\75AFQjCNF66V2DcfymtX413=
1R6c6cN4_eFbg';return true;" href=3D"http://en.wikipedia.org/wiki/Partial_a=
pplication" target=3D"_blank">http://en.wikipedia.org/wiki/<wbr>Partial_app=
lication</a>>.
<br>>
<br>> std::partial_apply(&my_class:<wbr>:do_something, =
this)
<br>> std::partial_apply(&my_class:<wbr>:do_something, =
this, first_argument)
<br>> std::partial_apply(free_<wbr>function, first_argument=
, second_argument)
<br>>
<br>> std::mem_fn(arg) would be equivalent to std::partial_apply(arg).
<br>> std::partial_apply(), without arguments, also makes sense and is
<br>> occasionally useful.
<br>
<br>Yeah, I'd mentioned partial_apply the last time I brought this up, but=
=20
<br>perhaps it would make sense to propose partial_apply in place of=20
<br>std::mem_fn(func, this) (or maybe in addition to).
<br>
<br>I suppose std::partial_apply(&my_class::<wbr>do_something) would be=
=20
<br>equivalent to the existing std::mem_fn function, so maybe there's an=20
<br>argument for replacing std::mem_fn with std::partial_apply entirely. On=
=20
<br>the other hand, std::mem_fn has the benefit of having a clearer name fo=
r=20
<br>some uses...
<br>
<br>- Jim
<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_3119_2025482167.1411222107422--
.
Author: Mikhail Semenov <mikhailsemenov1957@gmail.com>
Date: Sat, 20 Sep 2014 15:17:38 +0100
Raw View
--089e013d1b2a46a7be05037fe1e5
Content-Type: text/plain; charset=UTF-8
I wonder where I can find the std::partial_apply proposal or implementation?
On 18 September 2014 09:29, Roman Perepelitsa <roman.perepelitsa@gmail.com>
wrote:
> 2014-09-18 10:21 GMT+02:00 Jim Porter <jvp4846@g.rit.edu>:
>
>> Often, I find myself using std::bind (or, more lately, generic lambdas)
>> to bind `this` to a member function so I can pass it along somewhere else,
>> e.g.:
>>
>> [this](auto &&...t) {
>> return do_something(std::forward<decltype(t)>(t)...);
>> }
>>
>> While this is nice, it seems common enough to me that it would be useful
>> for the standard library to provide a helper function for it, especially
>> since the std::forward notation is moderately verbose. I'd like to propose
>> that the standard add an overload of std::mem_fn that takes `this` and
>> makes the following line roughly equivalent to the above:
>>
>> std::mem_fn(&my_class::do_something, this);
>>
>
> The generalization of this facility is partial application
> <http://en.wikipedia.org/wiki/Partial_application>.
>
> std::partial_apply(&my_class::do_something, this)
> std::partial_apply(&my_class::do_something, this, first_argument)
> std::partial_apply(free_function, first_argument, second_argument)
>
> std::mem_fn(arg) would be equivalent to std::partial_apply(arg).
> std::partial_apply(), without arguments, also makes sense and is
> occasionally useful.
>
> Roman.
>
> --
>
> ---
> 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/.
>
--
---
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/.
--089e013d1b2a46a7be05037fe1e5
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I wonder where I can find the std::partial_apply proposal =
or implementation?</div><div class=3D"gmail_extra"><br><div class=3D"gmail_=
quote">On 18 September 2014 09:29, Roman Perepelitsa <span dir=3D"ltr"><=
<a href=3D"mailto:roman.perepelitsa@gmail.com" target=3D"_blank">roman.pere=
pelitsa@gmail.com</a>></span> wrote:<br><blockquote class=3D"gmail_quote=
" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><=
div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote"><span=
>2014-09-18 10:21 GMT+02:00 Jim Porter <span dir=3D"ltr"><<a href=3D"mai=
lto:jvp4846@g.rit.edu" target=3D"_blank">jvp4846@g.rit.edu</a>></span>:<=
br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;padd=
ing-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;borde=
r-left-style:solid">Often, I find myself using std::bind (or, more lately, =
generic lambdas) to bind `this` to a member function so I can pass it along=
somewhere else, e.g.:<br>
<br>
=C2=A0 [this](auto &&...t) {<br>
=C2=A0 =C2=A0 return do_something(std::forward<<u></u>decltype(t)>(t)=
....);<br>
=C2=A0 }<br>
<br>
While this is nice, it seems common enough to me that it would be useful fo=
r the standard library to provide a helper function for it, especially sinc=
e the std::forward notation is moderately verbose. I'd like to propose =
that the standard add an overload of std::mem_fn that takes `this` and make=
s the following line roughly equivalent to the above:<br>
<br>
=C2=A0 std::mem_fn(&my_class::do_<u></u>something, this);<br></blockquo=
te><div><br></div></span><div>The generalization of this facility is <a hre=
f=3D"http://en.wikipedia.org/wiki/Partial_application" target=3D"_blank">pa=
rtial application</a>.</div><div><br></div><div>=C2=A0 std::partial_apply(&=
amp;my_class::do_something, this)</div><div>=C2=A0 std::partial_apply(&=
my_class::do_something, this, first_argument)<br></div><div>=C2=A0 std::par=
tial_apply(free_function, first_argument, second_argument)<br></div><div><b=
r></div><div>std::mem_fn(arg) would be equivalent to std::partial_apply(arg=
). std::partial_apply(), without arguments, also makes sense and is occasio=
nally useful.</div><span class=3D"HOEnZb"><font color=3D"#888888"><div><br>=
</div><div>Roman.</div></font></span></div></div></div><div class=3D"HOEnZb=
"><div class=3D"h5">
<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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><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 />
--089e013d1b2a46a7be05037fe1e5--
.