diff --git a/build/vc80/turtle.vcproj b/build/vc80/turtle.vcproj
index 1b25b0a..549e207 100644
--- a/build/vc80/turtle.vcproj
+++ b/build/vc80/turtle.vcproj
@@ -200,6 +200,10 @@
RelativePath="..\..\src\libraries\turtle\is_functor.hpp"
>
+
+
diff --git a/src/libraries/turtle/action.hpp b/src/libraries/turtle/action.hpp
index c87a3aa..9f05608 100644
--- a/src/libraries/turtle/action.hpp
+++ b/src/libraries/turtle/action.hpp
@@ -9,14 +9,12 @@
#ifndef MOCK_ACTION_HPP_INCLUDED
#define MOCK_ACTION_HPP_INCLUDED
-#include "config.hpp"
-#include
-#include
-#include
+#include "lambda.hpp"
+#include
+#include
#include
#include
#include
-#include
namespace mock
{
@@ -32,17 +30,20 @@ namespace detail
BOOST_DEDUCED_TYPENAME boost::remove_const< Result >::type
>::type result_type;
+ typedef BOOST_DEDUCED_TYPENAME
+ lambda< Signature > lambda;
+
public:
template< typename Value >
void returns( Value v )
{
r_.reset( new result_type( v ) );
- f_ = boost::phoenix::val( boost::ref( *r_ ) );
+ f_ = lambda::make_val( boost::ref( *r_ ) );
}
template< typename Y >
void returns( const boost::reference_wrapper< Y >& r )
{
- f_ = *boost::phoenix::val( r.get_pointer() );
+ f_ = lambda::make_val( r );
}
void calls( const functor_type& f )
@@ -55,7 +56,7 @@ namespace detail
template< typename Exception >
void throws( Exception e )
{
- f_ = boost::phoenix::throw_( e );
+ f_ = lambda::make_throw( e );
}
const functor_type& functor() const
@@ -74,15 +75,18 @@ namespace detail
typedef BOOST_DEDUCED_TYPENAME
boost::function< Signature > functor_type;
+ typedef BOOST_DEDUCED_TYPENAME
+ lambda< Signature > lambda;
+
public:
void returns( Result* r )
{
- f_ = boost::phoenix::val( r );
+ f_ = lambda::make_val( r );
}
template< typename Y >
void returns( const boost::reference_wrapper< Y >& r )
{
- f_ = boost::phoenix::val( r );
+ f_ = lambda::make_val( r );
}
void calls( const functor_type& f )
@@ -95,7 +99,7 @@ namespace detail
template< typename Exception >
void throws( Exception e )
{
- f_ = boost::phoenix::throw_( e );
+ f_ = lambda::make_throw( e );
}
const functor_type& functor() const
@@ -113,9 +117,12 @@ namespace detail
typedef BOOST_DEDUCED_TYPENAME
boost::function< Signature > functor_type;
+ typedef BOOST_DEDUCED_TYPENAME
+ lambda< Signature > lambda;
+
public:
action()
- : f_( boost::phoenix::nothing )
+ : f_( lambda::make_nothing() )
{}
void calls( const functor_type& f )
@@ -128,7 +135,7 @@ namespace detail
template< typename Exception >
void throws( Exception e )
{
- f_ = boost::phoenix::throw_( e );
+ f_ = lambda::make_throw( e );
}
const functor_type& functor() const
@@ -146,6 +153,9 @@ namespace detail
typedef BOOST_DEDUCED_TYPENAME
boost::function< Signature > functor_type;
+ typedef BOOST_DEDUCED_TYPENAME
+ lambda< Signature > lambda;
+
public:
action()
: r_()
@@ -153,7 +163,7 @@ namespace detail
{}
action( const action& rhs )
: r_( const_cast< action& >( rhs ).r_.release() )
- , f_( r_.get() ? boost::phoenix::val( boost::ref( r_ ) ) : rhs.f_ )
+ , f_( r_.get() ? lambda::make_val( boost::ref( r_ ) ) : rhs.f_ )
{}
template< typename Value >
@@ -172,7 +182,7 @@ namespace detail
template< typename Exception >
void throws( Exception e )
{
- f_ = boost::phoenix::throw_( e );
+ f_ = lambda::make_throw( e );
r_.reset();
}
@@ -186,19 +196,19 @@ namespace detail
void set( std::auto_ptr< Y > r )
{
r_ = r;
- f_ = boost::phoenix::val( boost::ref( r_ ) );
+ f_ = lambda::make_val( boost::ref( r_ ) );
}
template< typename Y >
void set( const boost::reference_wrapper< Y >& r )
{
- f_ = boost::phoenix::val( r );
+ f_ = lambda::make_val( r );
r_.reset();
}
template< typename Y >
void set( Y* r )
{
r_.reset( r );
- f_ = boost::phoenix::val( boost::ref( r_ ) );
+ f_ = lambda::make_val( boost::ref( r_ ) );
}
mutable std::auto_ptr< Result > r_;
diff --git a/src/libraries/turtle/config.hpp b/src/libraries/turtle/config.hpp
index beae072..73875df 100644
--- a/src/libraries/turtle/config.hpp
+++ b/src/libraries/turtle/config.hpp
@@ -12,14 +12,18 @@
#include
#ifndef MOCK_MAX_ARGS
-# define MOCK_MAX_ARGS 10
+# define MOCK_MAX_ARGS 9
#endif
#define MOCK_NUM_ARGS BOOST_PP_INC(MOCK_MAX_ARGS)
-#ifndef PHOENIX_LIMIT
-# define PHOENIX_LIMIT MOCK_MAX_ARGS
-#elif (PHOENIX_LIMIT < MOCK_MAX_ARGS)
-# error "PHOENIX_LIMIT is set too low"
+#if defined(MOCK_USE_BOOST_PHOENIX) || (MOCK_MAX_ARGS > 9)
+# ifndef PHOENIX_LIMIT
+# define PHOENIX_LIMIT MOCK_MAX_ARGS
+# elif (PHOENIX_LIMIT < MOCK_MAX_ARGS)
+# error "PHOENIX_LIMIT is set too low"
+# endif
+#else
+# define MOCK_USE_BOOST_BIND
#endif
#ifndef BOOST_FUNCTION_MAX_ARGS
diff --git a/src/libraries/turtle/lambda.hpp b/src/libraries/turtle/lambda.hpp
new file mode 100644
index 0000000..4b0802e
--- /dev/null
+++ b/src/libraries/turtle/lambda.hpp
@@ -0,0 +1,107 @@
+//
+// Copyright Mathieu Champlon 2011
+//
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#ifndef MOCK_LAMBDA_HPP_INCLUDED
+#define MOCK_LAMBDA_HPP_INCLUDED
+
+#include "config.hpp"
+#ifdef MOCK_USE_BOOST_BIND
+# include
+#else
+# include
+# include
+# include
+#endif
+#include
+
+namespace mock
+{
+namespace detail
+{
+
+#ifdef MOCK_USE_BOOST_BIND
+ template< 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::bind( &do_identity< T >, t );
+ }
+ template< typename T >
+ static functor_type make_val( boost::reference_wrapper< T > t )
+ {
+ return boost::bind( &do_ref_identity< T >, t.get_pointer() );
+ }
+ template< typename T >
+ static functor_type make_throw( T t )
+ {
+ return boost::bind( &do_throw< T >, t );
+ }
+ static functor_type make_nothing()
+ {
+ return boost::bind( &do_nothing );
+ }
+
+ template< typename T >
+ static T do_identity( T t )
+ {
+ return t;
+ }
+ template< typename T >
+ static T& do_ref_identity( T* t )
+ {
+ return *t;
+ }
+ template< typename T >
+ static void do_throw( T t )
+ {
+ throw t;
+ }
+ static void do_nothing()
+ {
+ }
+ };
+
+#else
+
+ template< 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
+
+}
+}
+
+#endif // #ifndef MOCK_LAMBDA_HPP_INCLUDED
diff --git a/src/tests/turtle_test/integration_test.cpp b/src/tests/turtle_test/integration_test.cpp
index 0513a78..373d7d1 100644
--- a/src/tests/turtle_test/integration_test.cpp
+++ b/src/tests/turtle_test/integration_test.cpp
@@ -24,7 +24,8 @@ namespace
struct my_custom_mock
{
MOCK_METHOD_EXT( my_method, 0, void(), my_method )
- MOCK_METHOD_EXT( my_method_with_max_number_of_args, MOCK_MAX_ARGS, void( int, int, int, int, int, int, int, int, int, int ), my_method_with_max_number_of_args )
+ BOOST_STATIC_ASSERT( MOCK_MAX_ARGS == 9 );
+ MOCK_METHOD_EXT( my_method_with_max_number_of_args, MOCK_MAX_ARGS, void( int, int, int, int, int, int, int, int, int ), my_method_with_max_number_of_args )
};
}