Is an is_functor C++ trait class possible?

后端 未结 3 1772
一生所求
一生所求 2020-12-28 09:40

How can I deduce statically if an argument is a C++ function object (functor)?

template 
void test(F f) {}

I tried

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-28 09:58

    Although this does not work for overloaded functions, for all other cases (free functions, classes implementing operator(), and lambdas) this short solutions works in C++11:

    template 
    struct is_callable: std::is_convertible> { };
    

    Note: std::is_invocable is available since C++17.

提交回复
热议问题