c++ - how check for member operator(type)? -
this question has answer here:
suppose have types bar , foo. how can construct template class has_call_with_arg<> such has_call_with_arg<bar,foo>::value true if , if
bar b; foo f; b(f); would compile? looked various related questions (including mentioned above) , tried
template<typename func, typename arg> class has_call_with_arg { struct bad {}; struct test : func { template<typename c> bad operator()(c const&r); }; public: static const bool value = !std::is_same<bad, typename std::result_of<test(arg const&)>::type >::value; }; but didn't work (didn't detect correct match). what's wrong?
template<typename sig, typename functor> struct is_callable; template<typename ret, typename... arg, typename functor> struct is_callable<ret(arg...), functor> { // partial spec private: struct no {}; public: template<typename u> static auto f(std::nullptr_t) -> decltype(std::declval<u>()(std::declval<arg>()...)); template<typename u> static no f(...); static const int value = std::is_convertible<decltype(f<functor>(nullptr)), ret>::value; }; i created content for tutorials, explain construction of trait (non-variadic form first).
Comments
Post a Comment