Topic: Extension to std::function to allow binding a object
Author: Mikhail Semenov <mikhailsemenov1957@gmail.com>
Date: Mon, 27 May 2013 06:21:48 -0700 (PDT)
Raw View
------=_Part_2772_15000942.1369660908154
Content-Type: text/plain; charset=ISO-8859-1
Is anybody interested in the following extension to *std::function*? I
propose to add a constructor with
two arguments:
*template<class T>
function(T* obj1, R (T::*fx)(Arg ... ));*
Consider the following class:
*class A
{
double x;
public:
A(double x1):x(x1) {}
double get() const { return x; }
void add1(double& c) { x+= c; c = x;}
};*
It will be possible to write as follows:
*A a(10);*
*{
function<void(double&)> a_add1(&a,&A::add1); // to create a delegate: to
bind an object with its member function.*
*
double z;
a_add1(z);
}*
First of all, the standard function + bind will not allow to do this.
It is also easier to use then bind (when using bind is possible);
especially in case when function has many parameters.
If the following definition is available
*template<class T, class R, class ... Arg>
function<R(Arg ...)> member_delegate(T* obj,R (T::*f)(Arg ... ))
{
return function<R(Arg ...)>(obj, f);
}*
then we can even write shorter:
*auto a_add1 = member_delegate(&a, &A::add1);*
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.
------=_Part_2772_15000942.1369660908154
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<p>Is anybody interested in the following extension to <strong>std::functio=
n</strong>? I propose to add a constructor with <br>two arguments:</p><p><s=
trong>template<class T><br>function(T* obj1, R (T::*fx)(Arg ... ));</=
strong></p><p>Consider the following class:<br><strong>class A<br>{<br>&nbs=
p; double x;<br>public:<br> A(double x1):x(x1=
) {}<br> double get() const { return x; }<br> =
void add1(double& c) { x+=3D c; c =3D x;}<br>};</strong></p><p>I=
t will be possible to write as follows:</p><p><strong>A a(10);</strong></p>=
<div><strong>{<br> function<void(double&)> a_add1(&am=
p;a,&A::add1); // to create a delegate: to bind an object with its memb=
er function.</strong></div><div><strong><br> double z;<br> =
; a_add1(z);<br>}</strong></div><p><br>First of all, the standard fun=
ction + bind will not allow to do this. <br>It is also easier to use then b=
ind (when using bind is possible); especially in case when function has man=
y parameters.</p><p>If the following definition is available<br><strong>tem=
plate<class T, class R, class ... Arg><br>function<R(Arg ...)> =
member_delegate(T* obj,R (T::*f)(Arg ... ))<br>{<br> retu=
rn function<R(Arg ...)>(obj, f);<br>}</strong></p><p>then we can even=
write shorter:</p><div><strong>auto a_add1 =3D member_delegate(&a, &am=
p;A::add1);</strong><br></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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
<br />
<br />
------=_Part_2772_15000942.1369660908154--
.