Added support for C++11 lambdas as constraints

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@620 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2013-04-11 16:24:26 +00:00
parent c5861a744d
commit 4afe1d32d4
6 changed files with 77 additions and 10 deletions

View file

@ -9,6 +9,7 @@
#ifndef MOCK_CONFIG_HPP_INCLUDED
#define MOCK_CONFIG_HPP_INCLUDED
#include <boost/config.hpp>
#include <boost/preprocessor/arithmetic/inc.hpp>
#include <boost/preprocessor/comparison/less.hpp>
@ -48,4 +49,8 @@
# endif
#endif
#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_DECLTYPE)
# define MOCK_DECLTYPE
#endif
#endif // MOCK_CONFIG_HPP_INCLUDED

View file

@ -9,9 +9,11 @@
#ifndef MOCK_IS_FUNCTOR_HPP_INCLUDED
#define MOCK_IS_FUNCTOR_HPP_INCLUDED
#include "../config.hpp"
#include <boost/function_types/is_callable_builtin.hpp>
#include <boost/type_traits/detail/yes_no_type.hpp>
#include <boost/utility/declval.hpp>
#include <boost/mpl/has_xxx.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/or.hpp>
namespace mock
@ -22,10 +24,33 @@ namespace detail
BOOST_MPL_HAS_XXX_TEMPLATE_DEF( sig )
BOOST_MPL_HAS_XXX_TEMPLATE_DEF( result )
template< typename T >
#ifdef MOCK_DECLTYPE
template< typename T, typename P >
struct is_callable
{
typedef boost::type_traits::yes_type yes_type;
typedef boost::type_traits::no_type no_type;
template< typename T >
static yes_type check(
decltype( boost::declval< T >()( boost::declval< P >() ) )* );
template< typename T >
static no_type check( ... );
typedef boost::mpl::bool_<
sizeof( check< T >( 0 ) ) == sizeof( yes_type ) > type;
};
#endif // MOCK_DECLTYPE
template< typename T, typename P >
struct is_functor
: boost::mpl::or_<
boost::function_types::is_callable_builtin< T >,
#ifdef MOCK_DECLTYPE
is_callable< T, P >,
#endif
has_result_type< T >,
has_result< T >,
has_sig< T >

View file

@ -84,7 +84,7 @@ namespace mock
template< typename Actual, typename Functor >
class matcher< Actual, Functor,
BOOST_DEDUCED_TYPENAME boost::enable_if<
detail::is_functor< Functor >
detail::is_functor< Functor, Actual >
>::type
> : public detail::matcher_base< Actual >
{