From 6e8ed29462dcd62d5f315c86289a264f04df59f6 Mon Sep 17 00:00:00 2001 From: mat007 Date: Sat, 15 Jan 2011 11:24:52 +0000 Subject: [PATCH] Fix git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@191 860be788-9bd5-4423-9f1e-828f051e677b --- src/libraries/turtle/action.hpp | 34 +++++++++++++++---------- src/libraries/turtle/lambda.hpp | 6 ++--- src/tests/turtle_test/function_test.cpp | 2 +- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/libraries/turtle/action.hpp b/src/libraries/turtle/action.hpp index 3f019b7..e6fc929 100644 --- a/src/libraries/turtle/action.hpp +++ b/src/libraries/turtle/action.hpp @@ -30,17 +30,19 @@ namespace detail BOOST_DEDUCED_TYPENAME boost::remove_const< Result >::type >::type result_type; + typedef lambda< Result, Signature > lambda; + public: template< typename Value > void returns( Value v ) { r_.reset( new result_type( v ) ); - f_ = lambda< Signature >::make_val( boost::ref( *r_ ) ); + f_ = lambda::make_val( boost::ref( *r_ ) ); } template< typename Y > void returns( const boost::reference_wrapper< Y >& r ) { - f_ = lambda< Signature >::make_val( r ); + f_ = lambda::make_val( r ); } void calls( const functor_type& f ) @@ -53,7 +55,7 @@ namespace detail template< typename Exception > void throws( Exception e ) { - f_ = lambda< Signature >::make_throw( e ); + f_ = lambda::make_throw( e ); } const functor_type& functor() const @@ -72,15 +74,17 @@ namespace detail typedef BOOST_DEDUCED_TYPENAME boost::function< Signature > functor_type; + typedef lambda< Result*, Signature > lambda; + public: void returns( Result* r ) { - f_ = lambda< Signature >::make_val( r ); + f_ = lambda::make_val( r ); } template< typename Y > void returns( const boost::reference_wrapper< Y >& r ) { - f_ = lambda< Signature >::make_val( r ); + f_ = lambda::make_val( r ); } void calls( const functor_type& f ) @@ -93,7 +97,7 @@ namespace detail template< typename Exception > void throws( Exception e ) { - f_ = lambda< Signature >::make_throw( e ); + f_ = lambda::make_throw( e ); } const functor_type& functor() const @@ -111,9 +115,11 @@ namespace detail typedef BOOST_DEDUCED_TYPENAME boost::function< Signature > functor_type; + typedef lambda< void, Signature > lambda; + public: action() - : f_( lambda< Signature >::make_nothing() ) + : f_( lambda::make_nothing() ) {} void calls( const functor_type& f ) @@ -126,7 +132,7 @@ namespace detail template< typename Exception > void throws( Exception e ) { - f_ = lambda< Signature >::make_throw( e ); + f_ = lambda::make_throw( e ); } const functor_type& functor() const @@ -144,6 +150,8 @@ namespace detail typedef BOOST_DEDUCED_TYPENAME boost::function< Signature > functor_type; + typedef lambda< std::auto_ptr< Result >, Signature > lambda; + public: action() : r_() @@ -151,7 +159,7 @@ namespace detail {} action( const action& rhs ) : r_( const_cast< action& >( rhs ).r_.release() ) - , f_( r_.get() ? lambda< Signature >::make_val( boost::ref( r_ ) ) : rhs.f_ ) + , f_( r_.get() ? lambda::make_val( boost::ref( r_ ) ) : rhs.f_ ) {} template< typename Value > @@ -170,7 +178,7 @@ namespace detail template< typename Exception > void throws( Exception e ) { - f_ = lambda< Signature >::make_throw( e ); + f_ = lambda::make_throw( e ); r_.reset(); } @@ -184,19 +192,19 @@ namespace detail void set( std::auto_ptr< Y > r ) { r_ = r; - f_ = lambda< Signature >::make_val( boost::ref( r_ ) ); + f_ = lambda::make_val( boost::ref( r_ ) ); } template< typename Y > void set( const boost::reference_wrapper< Y >& r ) { - f_ = lambda< Signature >::make_val( r ); + f_ = lambda::make_val( r ); r_.reset(); } template< typename Y > void set( Y* r ) { r_.reset( r ); - f_ = lambda< Signature >::make_val( boost::ref( r_ ) ); + f_ = lambda::make_val( boost::ref( r_ ) ); } mutable std::auto_ptr< Result > r_; diff --git a/src/libraries/turtle/lambda.hpp b/src/libraries/turtle/lambda.hpp index 4b0802e..5ddd33e 100644 --- a/src/libraries/turtle/lambda.hpp +++ b/src/libraries/turtle/lambda.hpp @@ -25,7 +25,7 @@ namespace detail { #ifdef MOCK_USE_BOOST_BIND - template< typename Signature > + template< typename Result, typename Signature > struct lambda { typedef BOOST_DEDUCED_TYPENAME @@ -62,7 +62,7 @@ namespace detail return *t; } template< typename T > - static void do_throw( T t ) + static Result do_throw( T t ) { throw t; } @@ -73,7 +73,7 @@ namespace detail #else - template< typename Signature > + template< typename Result, typename Signature > struct lambda { typedef BOOST_DEDUCED_TYPENAME diff --git a/src/tests/turtle_test/function_test.cpp b/src/tests/turtle_test/function_test.cpp index edf7fe5..d587a06 100644 --- a/src/tests/turtle_test/function_test.cpp +++ b/src/tests/turtle_test/function_test.cpp @@ -557,7 +557,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_calls_the_custom_functor_with BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_throws_the_set_exception, error_fixture ) { - mock::function< void() > f; + mock::function< int() > f; f.expect().throws( std::runtime_error( "some exception" ) ); try {