Replace Boost.Bind by std::bind and lambdas

This commit is contained in:
Alexander Grund 2020-07-09 21:02:10 +02:00
parent 35e43d58a6
commit a426e02759
No known key found for this signature in database
GPG key ID: AA48A0760367A42B
9 changed files with 28 additions and 41 deletions

View file

@ -64,10 +64,10 @@ BOOST_AUTO_TEST_CASE( method_is_called )
// Note: Boost 1.57 introduced a bug preventing usage of the lambda with clang in C++98
// See: https://svn.boost.org/trac10/ticket/10785
#if defined(BOOST_CLANG) && (BOOST_VERSION >= 105700)
MOCK_EXPECT( m.method ).once().calls( boost::bind(&set_bool, done) );
MOCK_EXPECT( m.method ).once().calls( std::bind(&set_bool, done) );
#else
MOCK_EXPECT( m.method ).once().calls( boost::lambda::var( done ) = true );
#endif
check( done, boost::bind( &my_class::flush, &c ) ); // just wait on done, flushing from time to time
check( done, std::bind( &my_class::flush, &c ) ); // just wait on done, flushing from time to time
}
//]

View file

@ -24,8 +24,8 @@ namespace
//[ invoke_functor_solution
#define BOOST_AUTO_TEST_MAIN
#include <boost/test/auto_unit_test.hpp>
#include <boost/bind/apply.hpp>
#include <turtle/mock.hpp>
#include <functional>
namespace
{
@ -38,7 +38,7 @@ namespace
BOOST_AUTO_TEST_CASE( how_to_invoke_a_functor_passed_as_parameter_of_a_mock_method )
{
mock_class mock;
MOCK_EXPECT( mock.method ).calls( boost::bind( boost::apply< void >(), _1, 42 ) ); // whenever 'method' is called, invoke the functor with 42
MOCK_EXPECT( mock.method ).calls( [](const auto &functor){ functor(42); } ); // whenever 'method' is called, invoke the functor with 42
function( mock );
}
//]

View file

@ -572,7 +572,7 @@ bool custom_constraint( int expected, int actual )
BOOST_AUTO_TEST_CASE( demonstrates_adding_a_custom_constraint_with_boost_bind )
{
mock_class c;
MOCK_EXPECT( c.method ).with( boost::bind( &custom_constraint, 42, _1 ) );
MOCK_EXPECT( c.method ).with( std::bind( &custom_constraint, 42, _1 ) );
}
//]
}
@ -722,7 +722,7 @@ BOOST_AUTO_TEST_CASE( demonstrates_configuring_actions )
MOCK_EXPECT( c.method ).moves( 42 ); // returns by moving the value
MOCK_EXPECT( c.method ).throws( std::runtime_error( "error !" ) );
MOCK_EXPECT( c.method ).calls( &function ); // forwards 'method' parameter to 'function'
MOCK_EXPECT( c.method ).calls( boost::bind( &function, 42 ) ); // drops 'method' parameter and binds 42 as parameter to 'function'
MOCK_EXPECT( c.method ).calls( std::bind( &function, 42 ) ); // drops 'method' parameter and binds 42 as parameter to 'function'
MOCK_EXPECT( c.method ).calls( []( int i ) { return i; } ); // uses a C++11 lambda
}
//]