correct usage of bind (pls ignore last email)
Hi, The code below tries to chain function ft1 (argument is a pair) with function buildPair (returns a pair). template<typename X, typename Y> std::pair<X, Y> buildPair(X x, Y y) { std::pair<X,Y> apair(x,y); return apair; } int main() { typedef boost::function<void (std::pair<int,int>)> FuncType1_t; std::vector<std::pair<int,int> > myvec; FuncType1_t ft1 = bind(&std::vector<std::pair<int,int> > ::push_back, &myvec, _1); typedef boost::function<void(std::pair<int,int>)> FuncType2_t; FuncType2_t ft2 = bind(ft1, bind(buildPair<int,int>,_1,_2)); //compile fails return 0; } This fails. The problem however vanished if I replace the declaration "FuncType3 ft2..." with bind(ft1, bind(buildPair<int,int>,_1,_2))(3,5); So my question is what is correct type of bind(ft1, bind(buildPair<int,int>,_1,_2)); Thanks sandeep
AMDG Sandeep Gupta wrote:
template<typename X, typename Y> std::pair<X, Y> buildPair(X x, Y y);
int main() { typedef boost::function<void (std::pair<int,int>)> FuncType1_t; FuncType1_t ft1;
typedef boost::function<void(std::pair<int,int>)> FuncType2_t; FuncType2_t ft2 = bind(ft1, bind(buildPair<int,int>,_1,_2)); }
This fails. The problem however vanished if I replace the declaration "FuncType3 ft2..." with bind(ft1, bind(buildPair<int,int>,_1,_2))(3,5);
So my question is what is correct type of bind(ft1, bind(buildPair<int,int>,_1,_2));
Since it is a function which takes two ints, the correct type is boost::function<void(int, int)> In Christ, Steven Watanabe
That is indeed so. Thanks Steve. On Tue, Mar 17, 2009 at 3:40 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Sandeep Gupta wrote:
template<typename X, typename Y> std::pair<X, Y> buildPair(X x, Y y);
int main() { typedef boost::function<void (std::pair<int,int>)> FuncType1_t; FuncType1_t ft1;
typedef boost::function<void(std::pair<int,int>)> FuncType2_t; FuncType2_t ft2 = bind(ft1, bind(buildPair<int,int>,_1,_2)); }
This fails. The problem however vanished if I replace the declaration "FuncType3 ft2..." with bind(ft1, bind(buildPair<int,int>,_1,_2))(3,5);
So my question is what is correct type of bind(ft1, bind(buildPair<int,int>,_1,_2));
Since it is a function which takes two ints, the correct type is
boost::function<void(int, int)>
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Sandeep Gupta
-
Steven Watanabe