|
Boost Users : |
Subject: [Boost-users] correct usage of bind (pls ignore last email)
From: Sandeep Gupta (gupta.sandeep_at_[hidden])
Date: 2009-03-17 18:22:20
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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net