Howto check a type for the existence of parameterless operator()

前端 未结 2 1523
北荒
北荒 2021-02-06 09:33

I\'m trying to check whether a functor is compatible with a given set of parametertypes and a given return type (that is, the given parametertypes can be implicitely converted t

2条回答
  •  佛祖请我去吃肉
    2021-02-06 10:21

    When I want to test if a given expression is valid for a type, I use a structure similar to this one:

    template 
    struct is_callable_without_parameters {
    private:
        template 
        static decltype(std::declval()(), void(), 0) test(int);
        template 
        static void test(...);
    public:
        enum { value = !std::is_void(0))>::value };
    };
    

提交回复
热议问题