I have to check if given two tuples one is the subset of another. I found this elegant solution Check if one set of types is a subset of the other.
But the issue with this solution is that it does not consider subtypes for example
using t1 = std::tuple<int, double>;
using t2 = std::tuple<double, int>;
using t3 = std::tuple<t1, t2>;
This would fail the subset test.
#include <tuple>
#include <type_traits>
template <typename T, typename... Ts>
constexpr bool contains = (std::is_same<T, Ts>{} || ...);
template <typename Subset, typename Set>
constexpr bool is_subset_of = false;
template <typename... Ts, typename... Us>
constexpr bool is_subset_of<std::tuple<Ts...>, std::tuple<Us...>>
= (contains<Ts, Us...> && ...);
The reason being that if we do subset on t1 and t3, the contains expression compares int with t1 which fails. So the change needed is for contains function to search subtypes.
P.S This code would only work in C++17