diff --git a/src/libraries/turtle/check.hpp b/src/libraries/turtle/check.hpp index 2083e3e..0314036 100644 --- a/src/libraries/turtle/check.hpp +++ b/src/libraries/turtle/check.hpp @@ -13,7 +13,6 @@ #include "constraints.hpp" #include "operators.hpp" #include "format.hpp" -#include "lambda.hpp" #include #include #include @@ -31,8 +30,8 @@ namespace detail BOOST_CONCEPT_USAGE( FunctorCompatible ) { boost::require_boolean_expr( - // if an error is generated by the line below it means - // an argument passed to 'with' was of the wrong type. + // if an error is generated by the line below it means an argument + // passed to 'with' was of the wrong type. functor_accepts( actual_argument_type ) ); } @@ -49,8 +48,8 @@ namespace detail BOOST_CONCEPT_USAGE( EqualityComparable ) { boost::require_boolean_expr( - // if an error is generated by the line below it means - // an argument passed to 'with' was of the wrong type. + // if an error is generated by the line below it means an argument + // passed to 'with' was of the wrong type. actual_argument_type == expected_argument_type ); } @@ -69,7 +68,7 @@ namespace detail BOOST_DEDUCED_TYPENAME boost::enable_if< BOOST_DEDUCED_TYPENAME detail::is_functor< Functor > >::type* = 0 ) - : desc_( bind( &serialize< Functor >, _1, f ) ) + : desc_( mock::format( f ) ) { BOOST_CONCEPT_ASSERT(( FunctorCompatible< Functor, Actual > )); f_ = f; @@ -81,18 +80,18 @@ namespace detail BOOST_DEDUCED_TYPENAME boost::disable_if< BOOST_DEDUCED_TYPENAME detail::is_functor< Expected > >::type* = 0 ) - : desc_( bind( &serialize< Expected >, _1, expected ) ) + : desc_( mock::format( expected ) ) { BOOST_CONCEPT_ASSERT(( EqualityComparable< Expected, Actual > )); f_ = mock::equal( expected ).f_; if( ! f_ ) std::invalid_argument( "invalid constraint" ); } - template< typename Constraint > - explicit check( const constraint< Constraint >& ph ) - : desc_( bind( &serialize< Constraint >, _1, ph.f_ ) ) + template< typename Functor > + explicit check( const constraint< Functor >& ph ) + : desc_( mock::format( ph.f_ ) ) { - BOOST_CONCEPT_ASSERT(( FunctorCompatible< Constraint, Actual > )); + BOOST_CONCEPT_ASSERT(( FunctorCompatible< Functor, Actual > )); f_ = ph.f_; if( ! f_ ) std::invalid_argument( "invalid constraint" ); @@ -105,20 +104,12 @@ namespace detail friend std::ostream& operator<<( std::ostream& s, const check& c ) { - c.desc_( s ); - return s; - } - - private: - template< typename T > - static void serialize( std::ostream& s, T t ) - { - s << mock::format( t ); + return s << c.desc_; } private: boost::function< bool( Actual ) > f_; - boost::function< void( std::ostream& ) > desc_; + std::string desc_; }; } } diff --git a/src/libraries/turtle/lambda.hpp b/src/libraries/turtle/lambda.hpp index 42fac3d..4f9aea7 100644 --- a/src/libraries/turtle/lambda.hpp +++ b/src/libraries/turtle/lambda.hpp @@ -13,8 +13,9 @@ #ifdef MOCK_USE_BOOST_BIND #include #else -#include -#include +#include +#include +#include #endif #include @@ -22,13 +23,8 @@ namespace mock { namespace detail { -#ifdef MOCK_USE_BOOST_BIND - using boost::bind; -#else - using boost::phoenix::bind; - using boost::phoenix::arg_names::_1; -#endif +#ifdef MOCK_USE_BOOST_BIND template< typename Result, typename Signature > struct lambda { @@ -38,21 +34,21 @@ namespace detail template< typename T > static functor_type make_val( T t ) { - return bind( &do_identity< T >, t ); + return boost::bind( &do_identity< T >, t ); } template< typename T > static functor_type make_val( boost::reference_wrapper< T > t ) { - return bind( &do_ref_identity< T >, t.get_pointer() ); + return boost::bind( &do_ref_identity< T >, t.get_pointer() ); } template< typename T > static functor_type make_throw( T t ) { - return bind( &do_throw< T >, t ); + return boost::bind( &do_throw< T >, t ); } static functor_type make_nothing() { - return bind( &do_nothing ); + return boost::bind( &do_nothing ); } template< typename T > @@ -74,6 +70,37 @@ namespace detail { } }; + +#else + + template< typename Result, typename Signature > + struct lambda + { + typedef BOOST_DEDUCED_TYPENAME + boost::function< Signature > functor_type; + + template< typename T > + static functor_type make_val( T t ) + { + return boost::phoenix::val( t ); + } + template< typename T > + static functor_type make_val( boost::reference_wrapper< T > t ) + { + return *boost::phoenix::val( t.get_pointer() ); + } + template< typename T > + static functor_type make_throw( T t ) + { + return boost::phoenix::throw_( t ); + } + static functor_type make_nothing() + { + return boost::phoenix::nothing; + } + }; +#endif + } } diff --git a/src/libraries/turtle/operators.hpp b/src/libraries/turtle/operators.hpp index 562c306..b9193d6 100644 --- a/src/libraries/turtle/operators.hpp +++ b/src/libraries/turtle/operators.hpp @@ -98,9 +98,9 @@ namespace detail template< typename Functor > const constraint< detail::not_< Functor > > - operator!( const constraint< Functor >& c ) + operator!( const constraint< Functor >& ph ) { - return detail::not_< Functor >( c.f_ ); + return detail::not_< Functor >( ph.f_ ); } }