mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
A boost::lambda functor is now successfully identified by is_functor
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@10 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
f2f1125a1a
commit
1bee70f758
2 changed files with 87 additions and 27 deletions
|
|
@ -10,35 +10,63 @@
|
|||
#define MOCK_IS_FUNCTOR_HPP_INCLUDED
|
||||
|
||||
#include <boost/function_types/is_callable_builtin.hpp>
|
||||
#include <boost/type_traits/integral_constant.hpp>
|
||||
#include <boost/mpl/or.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
typedef char true_type[2];
|
||||
typedef char false_type[1];
|
||||
typedef char true_type;
|
||||
struct false_type
|
||||
{
|
||||
char padding[8];
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
true_type& has_result_type_helper( T*, BOOST_DEDUCED_TYPENAME T::result_type* = 0 );
|
||||
true_type& has_result_type_tester( T*, BOOST_DEDUCED_TYPENAME T::result_type* = 0 );
|
||||
template< typename T >
|
||||
false_type& has_result_type_helper( T, ... );
|
||||
false_type& has_result_type_tester( T, ... );
|
||||
|
||||
template< typename T >
|
||||
struct has_result_type
|
||||
struct has_result_type_impl
|
||||
{
|
||||
static T* t();
|
||||
enum { value = sizeof( has_result_type_helper( t() ) ) == sizeof( true_type ) };
|
||||
static T* t;
|
||||
enum { value = sizeof( has_result_type_tester( t ) ) == sizeof( true_type ) };
|
||||
};
|
||||
|
||||
template< typename T, bool B = has_result_type< T >::value >
|
||||
template< typename T >
|
||||
struct has_result_type : public boost::integral_constant< bool, has_result_type_impl< T >::value >
|
||||
{
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
true_type& has_sig_tester( T*, BOOST_DEDUCED_TYPENAME T::template sig< void >* = 0 );
|
||||
template< typename T >
|
||||
false_type& has_sig_tester( T, ... );
|
||||
|
||||
template< typename T >
|
||||
struct has_sig_impl
|
||||
{
|
||||
static T* t;
|
||||
enum { value = sizeof( has_sig_tester( t ) ) == sizeof( true_type ) };
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
struct has_sig : public boost::integral_constant< bool, has_sig_impl< T >::value >
|
||||
{
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
struct is_functor
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::function_types::is_callable_builtin< T >::type type;
|
||||
};
|
||||
template< typename T >
|
||||
struct is_functor< T, true >
|
||||
{
|
||||
typedef boost::true_type type;
|
||||
typedef BOOST_DEDUCED_TYPENAME boost::mpl::or_<
|
||||
BOOST_DEDUCED_TYPENAME boost::mpl::or_<
|
||||
BOOST_DEDUCED_TYPENAME boost::function_types::is_callable_builtin< T >::type,
|
||||
BOOST_DEDUCED_TYPENAME has_result_type< T >::type
|
||||
>::type,
|
||||
BOOST_DEDUCED_TYPENAME has_sig< T >::type
|
||||
>::type type;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue