File indexing completed on 2025-01-18 09:38:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_IS_SUBSET_HPP
0011 #define BOOST_HANA_IS_SUBSET_HPP
0012
0013 #include <boost/hana/fwd/is_subset.hpp>
0014
0015 #include <boost/hana/all_of.hpp>
0016 #include <boost/hana/concept/searchable.hpp>
0017 #include <boost/hana/config.hpp>
0018 #include <boost/hana/contains.hpp>
0019 #include <boost/hana/core/common.hpp>
0020 #include <boost/hana/core/to.hpp>
0021 #include <boost/hana/core/dispatch.hpp>
0022 #include <boost/hana/detail/has_common_embedding.hpp>
0023 #include <boost/hana/functional/partial.hpp>
0024
0025
0026 namespace boost { namespace hana {
0027
0028 template <typename Xs, typename Ys>
0029 constexpr auto is_subset_t::operator()(Xs&& xs, Ys&& ys) const {
0030 using S1 = typename hana::tag_of<Xs>::type;
0031 using S2 = typename hana::tag_of<Ys>::type;
0032 using IsSubset = BOOST_HANA_DISPATCH_IF(
0033 decltype(is_subset_impl<S1, S2>{}),
0034 hana::Searchable<S1>::value &&
0035 hana::Searchable<S2>::value &&
0036 !is_default<is_subset_impl<S1, S2>>::value
0037 );
0038
0039 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0040 static_assert(hana::Searchable<S1>::value,
0041 "hana::is_subset(xs, ys) requires 'xs' to be Searchable");
0042
0043 static_assert(hana::Searchable<S2>::value,
0044 "hana::is_subset(xs, ys) requires 'ys' to be Searchable");
0045
0046 static_assert(!is_default<is_subset_impl<S1, S2>>::value,
0047 "hana::is_subset(xs, ys) requires 'xs' and 'ys' to be embeddable "
0048 "in a common Searchable");
0049 #endif
0050
0051 return IsSubset::apply(static_cast<Xs&&>(xs), static_cast<Ys&&>(ys));
0052 }
0053
0054
0055 template <typename S1, typename S2, bool condition>
0056 struct is_subset_impl<S1, S2, when<condition>> : default_ {
0057 template <typename ...Args>
0058 static constexpr auto apply(Args&& ...) = delete;
0059 };
0060
0061 template <typename S, bool condition>
0062 struct is_subset_impl<S, S, when<condition>> {
0063 template <typename Xs, typename Ys>
0064 static constexpr decltype(auto) apply(Xs&& xs, Ys&& ys) {
0065 return hana::all_of(static_cast<Xs&&>(xs),
0066 hana::partial(hana::contains, static_cast<Ys&&>(ys)));
0067 }
0068 };
0069
0070
0071 template <typename S1, typename S2>
0072 struct is_subset_impl<S1, S2, when<
0073 detail::has_nontrivial_common_embedding<Searchable, S1, S2>::value
0074 >> {
0075 using C = typename common<S1, S2>::type;
0076 template <typename Xs, typename Ys>
0077 static constexpr decltype(auto) apply(Xs&& xs, Ys&& ys) {
0078 return hana::is_subset(hana::to<C>(static_cast<Xs&&>(xs)),
0079 hana::to<C>(static_cast<Ys&&>(ys)));
0080 }
0081 };
0082 }}
0083
0084 #endif