I have a vector of pointers. I would like to call a function for every element, but that function takes a reference. Is there a simple way to dereference the elements?
Example:
MyClass::ReferenceFn( Element & e ) { ... }
MyClass::PointerFn( Element * e ) { ... }
MyClass::Function()
{
std::vector< Element * > elements;
// add some elements...
// This works, as the argument is a pointer type
std::for_each( elements.begin(), elements.end(),
boost::bind( &MyClass::PointerFn, boost::ref(*this), _1 ) );
// This fails (compiler error), as the argument is a reference type
std::for_each( elements.begin(), elements.end(),
boost::bind( &MyClass::ReferenceFn, boost::ref(*this), _1 ) );
}
I could create a dirty little wrapper that takes a pointer, but I figured there had to be a better way?