我有像这样定义的is_callable trait:
#ifndef IS_CALLABLE_HPP
#define IS_CALLABLE_HPP
#include <type_traits>
namespace is_callable_detail
{
struct no {};
struct yes { no x[2]; };
template<bool CallableArgs, typename Callable, typename ReturnType, typename ...Args>
struct check_return
{
static const bool value = std::is_convertible<decltype(std::declval<Callable>()(std::declval<Args>()...)), ReturnType>::value;
};
template<typename Callable, typename ReturnType, typename ...Args>
struct check_return<false, Callable, ReturnType, Args...>
{
static const bool value = false;
};
}
template<typename Callable, typename Function>
struct is_callable;
template<typename Callable, typename ReturnType, typename ...Args>
struct is_callable<Callable, ReturnType(Args...)>
{
private:
template<typename T>
static is_callable_detail::yes …Run Code Online (Sandbox Code Playgroud)