AngelCriss
2017-11-27 00:11:04 +08:00
template<typename F, typename Arg>
struct is_type_match
{
private:
template<typename Func> struct extract;
template<typename R, typename A>
struct extract<R(A)>
{
using ires = R;
using iarg = A;
};
template<typename R, typename A>
struct extract<R(*)(A)> : extract<R(A)> {};
template<typename R, typename A>
struct extract<std::function<R(A)>> : extract<R(A)> {};
template<typename R, typename Class, typename A>
struct extract<R(Class::*)(A)> : extract<R(A)> {};
template<typename R, typename Class, typename A>
struct extract<R(Class::*)(A) const> : extract<R(A)> {};
template<typename R, typename Class, typename A>
struct extract<R(Class::*)(A) volatile> : extract<R(A)> {};
template<typename R, typename Class, typename A>
struct extract<R(Class::*)(A) const volatile> : extract<R(A)> {};
template<typename lambda>
struct extract : extract<decltype(&lambda::operator())> {};
template<typename lambda>
struct extract<lambda&> : extract<decltype(&lambda::operator())> {};
template<typename lambda>
struct extract<lambda&&> : extract<lambda&> {};
public:
using arg = typename std::remove_cv<
typename std::remove_reference<Arg>::type>::type;
using iarg = typename std::remove_cv<
typename std::remove_reference<typename extract<F>::iarg>::type>::type;
constexpr static bool arg_same = std::is_same<arg, iarg>::value;
};
-------------------
比如这里面 F 代表 function,A,Arg 代表参数,R 代表返回值,Class 代表类,lambda 代表匿名类。。