mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Document and improve is_functor
This commit is contained in:
parent
446e70be53
commit
898a5a4524
4 changed files with 18 additions and 19 deletions
|
|
@ -30,7 +30,6 @@
|
||||||
#include <boost/preprocessor/comparison/greater.hpp>
|
#include <boost/preprocessor/comparison/greater.hpp>
|
||||||
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>
|
||||||
#include <boost/test/utils/lazy_ostream.hpp>
|
#include <boost/test/utils/lazy_ostream.hpp>
|
||||||
#include <boost/call_traits.hpp>
|
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,13 @@ namespace mock
|
||||||
{
|
{
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
template< typename F, typename P, class = void >
|
/// Trait to return true if F is a functor that can be called with a single argument Arg
|
||||||
struct is_callable : std::false_type
|
template< typename F, typename Arg, class = void >
|
||||||
|
struct is_functor : std::false_type
|
||||||
{};
|
{};
|
||||||
template< typename F, typename P >
|
template< typename F, typename Arg >
|
||||||
struct is_callable< F, P, boost::void_t<decltype( std::declval<F>()( std::declval<P>() ) )> >: std::true_type
|
struct is_functor< F, Arg, boost::void_t<decltype( std::declval<F>()( std::declval<Arg>() ) )> >: std::true_type
|
||||||
{};
|
{};
|
||||||
|
|
||||||
template< typename T, typename P >
|
|
||||||
using is_functor = is_callable< T, P >;
|
|
||||||
}
|
}
|
||||||
} // mock
|
} // mock
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@
|
||||||
#include "stream.hpp"
|
#include "stream.hpp"
|
||||||
#include "format.hpp"
|
#include "format.hpp"
|
||||||
#include <boost/detail/container_fwd.hpp>
|
#include <boost/detail/container_fwd.hpp>
|
||||||
#include <boost/function_types/is_callable_builtin.hpp>
|
|
||||||
#include <boost/none.hpp>
|
#include <boost/none.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
@ -51,6 +50,15 @@ namespace detail
|
||||||
s << (it == begin ? "" : ",") << mock::format( *it );
|
s << (it == begin ? "" : ",") << mock::format( *it );
|
||||||
s << ')';
|
s << ')';
|
||||||
}
|
}
|
||||||
|
template<typename T>
|
||||||
|
struct is_callable_impl: std::false_type
|
||||||
|
{};
|
||||||
|
template<typename R, typename... Args>
|
||||||
|
struct is_callable_impl<R(Args...)>: std::true_type
|
||||||
|
{};
|
||||||
|
template<typename T>
|
||||||
|
struct is_callable: is_callable_impl< std::remove_cv_t<T> >
|
||||||
|
{};
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MOCK_AUTO_PTR
|
#ifdef MOCK_AUTO_PTR
|
||||||
|
|
@ -182,19 +190,13 @@ namespace detail
|
||||||
}
|
}
|
||||||
|
|
||||||
template< typename T >
|
template< typename T >
|
||||||
std::enable_if_t<
|
std::enable_if_t< detail::is_callable< T >::value, stream& >
|
||||||
boost::function_types::is_callable_builtin< T >::value,
|
|
||||||
stream&
|
|
||||||
>
|
|
||||||
operator<<( stream& s, T* )
|
operator<<( stream& s, T* )
|
||||||
{
|
{
|
||||||
return s << '?';
|
return s << '?';
|
||||||
}
|
}
|
||||||
template< typename T >
|
template< typename T >
|
||||||
std::enable_if_t<
|
std::enable_if_t< !detail::is_callable< T >::value, stream& >
|
||||||
!boost::function_types::is_callable_builtin< T >::value,
|
|
||||||
stream&
|
|
||||||
>
|
|
||||||
operator<<( stream& s, T* t )
|
operator<<( stream& s, T* t )
|
||||||
{
|
{
|
||||||
*s.s_ << t;
|
*s.s_ << t;
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,12 @@ namespace
|
||||||
template< typename T >
|
template< typename T >
|
||||||
void is_functor( T )
|
void is_functor( T )
|
||||||
{
|
{
|
||||||
static_assert( mock::detail::is_functor< T, int >::value, "Should be functor");
|
static_assert( mock::detail::is_functor< T, int >::value, "Should be a functor taking an int");
|
||||||
}
|
}
|
||||||
template< typename T >
|
template< typename T >
|
||||||
void is_not_functor( T )
|
void is_not_functor( T )
|
||||||
{
|
{
|
||||||
static_assert( !mock::detail::is_functor< T, int >::value, "Should not be a functor" );
|
static_assert( !mock::detail::is_functor< T, int >::value, "Should not be a functor taking an int" );
|
||||||
}
|
}
|
||||||
|
|
||||||
void f0() {}
|
void f0() {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue