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

前端 未结 9 841
甜味超标
甜味超标 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:30

    constexpr bool any_of() { return false; }
    template
    constexpr bool any_of( bool b, Bools... bools ) {
      return b || any_of(bools...);
    }
    constexpr bool all_of() { return true; }
    template
    constexpr bool all_of( bool b, Bools...bools ) {
      return b && all_of(bools...);
    }
    template
    struct contains_t : std::integral_constant::value... )
    > {};
    
    template
    struct tuple_subset_of;
    
    template
    struct tuple_subset_of< std::tuple, std::tuple >:
      std::integral_constant::value... )
      >
    {};
    

    Live example.

    This is designed to permit easy improvement post C++17 -- replace any_of and all_of recursive implementations with fold expressions.

提交回复
热议问题