Possible to use type_traits / SFINAE to find if a class defines a member TYPE?

前端 未结 3 1736
甜味超标
甜味超标 2020-12-29 09:19

I have seen this question which allows one to check for the existence of a member function, but I\'m trying to find out whether a class has a member

3条回答
  •  一向
    一向 (楼主)
    2020-12-29 09:46

    Try this

    template
    struct Void {
      typedef void type;
    };
    
    template
    struct has_bar {
        enum { value = 0 };
    };
    
    template
    struct has_bar::type > {
        enum { value = 1 };
    };
    

提交回复
热议问题