I want to convert this simple code:
void setZComp(Imath::V3f& pt)
{
pt.z = 0.0;
}
int myfunc()
{
...
std::vector<Imath::V3f> vec(5,Imath::V3f(1.0,1.0,1.0));
std::for_each(vec.begin(),vec.end(),boost::bind(&setZComp,_1));
...
}
to something like that, in order to not have setZComp declared outside but some sort of inline declaration
int myfunc()
{
...
boost::function<double(Imath::V3f&)> f = (boost::lambda::_1 ->* &Imath::V3f::z = 0.0) ;
std::for_each(vec.begin(),vec.end(),boost::bind(&f,_1));
...
}
I'm quite new to Boost Bind and Lambda and I don't know if this can be done in some way. Obviously the code above does not work.
If you have access to a recent version of
g++
with C++11 support, or MSVC 2010, you could do the following: