You definitely want SFINAE to be in your solution. Generally speaking, the result will look something like this:
template<
typename Functor
, typename std::enable_if<
special_test<Functor>::value
, int
>::type = 0
>
return_type
my_magic_func(Functor f);
template<
typename Functor
, typename std::enable_if<
!special_test<Functor>::value
, int
>::type = 0
>
return_type
my_magic_func(Functor f);
- , , , special_test . , , ; . . (, lombdas? Monomorphic functors? Polymorphic functors?), , value_type, double .
, , , Callable ( ) bool(value_type); .. :
template<typename Functor, typename ValueType>
struct is_unary_predicate {
typedef char (&accepted)[1];
typedef char (&refused)[2];
void consume(bool);
template<
typename X
, typename Y
, typename = decltype( consume(std::declval<X>()(std::declval<Y>())) )
>
accepted
test(X&&, Y&&);
refused test(...);
static constexpr bool value =
sizeof test(std::declval<Functor>(), std::declval<ValueType>())
== sizeof(accepted);
};
is_callable<F, Signature>, - template<typename Functor, typename ValueType> using is_unary_predicate = is_callable<Functor, bool(ValueType)>; ( is_binary_predicate , my_magic_func ). , SFINAE ( ).