Say I have 2 tuples that are not instantiated. Is there an idiomatic way to check if one set is the subset of the other?
If this requires another type instead of hana::tuple_c
, this is fine as well. Actually, my current input consists of std::tuple
, but I couldn't get it working either way.
Code that does NOT work (but I feel like there should be something similar possible):
#include <boost/hana.hpp>
using namespace boost;
using SetA = hana::tuple_c<int, char, float>;
using SetB = hana::tuple_c<int, float>;
static_assert(
hana::is_subset( SetB, SetA ),
""
);
My current workaround uses boost::mpl
to do an intersection and then compare the results. This works, but I'm interested in a pure boost::hana
solution:
#include <boost/mpl.hpp>
using namespace boost;
using SetA = mpl::set<int, char, float>;
using SetB = mpl::set<int, float>;
using Intersection = typename mpl::copy_if<
SetA,
mpl::has_key< SetB, mpl::_1 >,
mpl::back_inserter< mpl::vector<> >
>::type;
// since Intersection is a vector, subset also needs vector type
using Subset = typename mpl::copy<
SetB,
mpl::back_inserter< mpl::vector<> >
>::type;
static_assert(std::is_same<Intersection, Subset>::value, "");