Let's say I have 2 tuples that are not created. Is there an idiomatic way to check if one set is a subset of another?
If this requires a different type instead of hana::tuple_c , this is also good. In fact, my current input consists of std::tuple , but I could not get it to work anyway.
Code that does NOT work (but I feel there should be something similar):
#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 ), "" );
In my current workaround, boost::mpl is used to perform the intersection and then compare the results. This works, but I'm interested in a clean 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, "");
source share