摘自CppREST
template <typename _Function> auto _IsCallable(_Function _Func, int) -> decltype(_Func(), std::true_type()) { (_Func); return std::true_type(); }
template <typename _Function> std::false_type _IsCallable(_Function, ...) { return std::false_type(); }
本文通过两个C++模板函数展示了如何使用SFINAE(Substitution Failure Is Not An Error)特性来判断一个函数是否可调用。第一个模板函数尝试调用传入的函数对象并返回`std::true_type`,若编译失败则第二个模板函数生效返回`std::false_type`。
75万+

被折叠的 条评论
为什么被折叠?



