How do I find out if a tuple contains a type?

后端 未结 7 1797
时光说笑
时光说笑 2020-11-30 08:50

Suppose I want to create a compile-time heterogenous container of unique types from some sequence of non-unique types. In order to do this I need to iterate over th

7条回答
  •  醉酒成梦
    2020-11-30 08:59

    #include 
    #include 
    
    template 
    struct has_type;
    
    template 
    struct has_type> : std::false_type {};
    
    template 
    struct has_type> : has_type> {};
    
    template 
    struct has_type> : std::true_type {};
    

    DEMO

    And an additional alias, if the trait itself should be std::true_type or std::false_type :

    template 
    using tuple_contains_type = typename has_type::type;
    

提交回复
热议问题