During testing when using c++ 11 I have used the following construct:
std::for_each( coll.begin(), coll.end(),
[ &obj, expRes ]( const value_type& val )
{
BOOST_CHECK_EQUAL( expRes, obj.someFunc( val ) );
} );
I am currently working on a project where C++11 is not used and am I a looking for a way to generate a similar lambda expression, without having to create separate a function / functor.
I understand basic use of boost::phoenix
to create lambdas, but I cannot think of a way to create a phoenix lambda that is capable of calling a boost::test
macro.
The best I can come up with is:
template< typename T >
void MakeCheck( const T& lhs, const T& rhs )
{
BOOST_CHECK_EQUAL( lhs, rhs );
}
/// inside some other function...
std::for_each( coll.begin(), coll.end(),
ph::bind( MakeCheck<bool>, true,
ph::bind( &MyClass::someFunc, obj, ph::arg_names::arg1 ) ) );
Unfortunately this approach looses the line number information of failed checks, since the macro BOOST_CHECK_EQUAL reports the line number of the macro, not the line number of the std::for_each
call.
Is there a better way of creating a lambda that involves a macro call using 'boost::phoenix`?