|
Boost : |
Subject: [boost] 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 list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk