File indexing completed on 2025-01-30 09:43:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_CONTAINS_HPP
0011 #define BOOST_HANA_CONTAINS_HPP
0012
0013 #include <boost/hana/fwd/contains.hpp>
0014
0015 #include <boost/hana/any_of.hpp>
0016 #include <boost/hana/concept/searchable.hpp>
0017 #include <boost/hana/config.hpp>
0018 #include <boost/hana/core/dispatch.hpp>
0019 #include <boost/hana/equal.hpp>
0020
0021
0022 namespace boost { namespace hana {
0023
0024 template <typename Xs, typename Key>
0025 constexpr auto contains_t::operator()(Xs&& xs, Key&& key) const {
0026 using S = typename hana::tag_of<Xs>::type;
0027 using Contains = BOOST_HANA_DISPATCH_IF(contains_impl<S>,
0028 hana::Searchable<S>::value
0029 );
0030
0031 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0032 static_assert(hana::Searchable<S>::value,
0033 "hana::contains(xs, key) requires 'xs' to be a Searchable");
0034 #endif
0035
0036 return Contains::apply(static_cast<Xs&&>(xs),
0037 static_cast<Key&&>(key));
0038 }
0039
0040
0041 template <typename S, bool condition>
0042 struct contains_impl<S, when<condition>> : default_ {
0043 template <typename Xs, typename X>
0044 static constexpr auto apply(Xs&& xs, X&& x) {
0045 return hana::any_of(static_cast<Xs&&>(xs),
0046 hana::equal.to(static_cast<X&&>(x)));
0047 }
0048 };
0049 }}
0050
0051 #endif