Check if one set of types is a subset of the other

前端 未结 9 820
甜味超标
甜味超标 2021-01-01 17:54

How can one check if one parameter pack (interpreted as a set) is a subset of another one?

So far I only have the frame (using std::tuple), but no functionality.

9条回答
  •  情话喂你
    2021-01-01 18:17

    is_subset_of version of an answer from your previous question:

    #include 
    #include 
    
    template 
    struct tag { };
    
    template 
    struct is_subset_of_helper: tag... { };
    
    template 
    struct is_subset_of: std::false_type { };
    
    template 
    struct bool_pack { };
    
    template 
    using my_and = std::is_same, bool_pack>;
    
    template 
    struct is_subset_of, std::tuple, typename std::enable_if< my_and< std::is_base_of, is_subset_of_helper>::value...  >::value  >::type  >:
       std::true_type { };
    
    int main() {    
        using t1 = std::tuple;
        using t2 = std::tuple;
        using t3 = std::tuple;
    
        static_assert(is_subset_of::value, "err");
        static_assert(is_subset_of::value, "err");
        static_assert(is_subset_of::value, "err");
        static_assert(is_subset_of::value, "err");
        static_assert(!is_subset_of::value, "err");
    }
    

    [live demo]

提交回复
热议问题