Doc No: | N4115 |
Date: | 2014-07-04 |
Reply to: | stdbill.h@pobox.com |
Possible implementations of the last two are shown as proof of concept. They both compile to either std::true_type or std::false_type.
And in the spirit of N3854, this paper also adds the “_v” values.
template <class... T> struct packer { };This is inspired by std::tuple, but it lacks members, so it could serve as an empty base class, and an object of the ultimate type could always be instantiated (even if the parameter pack contains void or some type that lacks a default constructor).
template <class T, class... P> struct is_contained_in; template <class T, class... P> constexpr bool is_contained_in_v = is_contained_in<T,P>::value;
template <class T> struct is_contained_in<T> : false_type { }; template <class First, class... Rest> struct is_contained_in<First, First, Rest...> : true_type { }; template <class T, class First, class... Rest> struct is_contained_in<T, First, Rest...> : is_contained_in<T, Rest...> { };
template <class T, class U> struct contains_types; template <class T, class U> constexpr bool contains_types_v = contains_types<T,U>::value;
template <class... TPack> struct contains_types<packer<TPack...>, packer<>> : true_type { }; template <class... TPack, class UFirst, class... URest> struct contains_types<packer<TPack...>, packer<UFirst, URest...>> : integral_constant<bool, is_contained_in<UFirst, TPack...>::value && contains_types<packer<TPack...>, packer<URest...>>::value> { };
// 20.10.3, helper classes:
template<class... T> struct packer;
template <class T, class... P> struct is_contained_in; template <class T, class U> struct contains_types; template <class T, class... P> constexpr bool is_contained_in_v = is_contained_in<T,P>::value; template <class T, class U> constexpr bool contains_types_v = contains_types<T,U>::value;
In 20.10.3 Helper classes [meta.help]:
template<class... T> struct packer { };
The class template packer simply holds a parameter pack.
In 20.10.6 Relationships between types [meta.rel], add to the end of Table 51:
template <class T, class... P>
struct is_contained_in;Type T is contained
in parameter pack Ptemplate <class T, class U>
struct contains_types;T’s parameter pack contains
at least one instance
of each of the types
in U’s parameter packT and U are packers (20.10.3).