Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:03

0001 /*!
0002 @file
0003 Defines `boost::hana::is_disjoint`.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0008  */
0009 
0010 #ifndef BOOST_HANA_IS_DISJOINT_HPP
0011 #define BOOST_HANA_IS_DISJOINT_HPP
0012 
0013 #include <boost/hana/fwd/is_disjoint.hpp>
0014 
0015 #include <boost/hana/concept/searchable.hpp>
0016 #include <boost/hana/config.hpp>
0017 #include <boost/hana/contains.hpp>
0018 #include <boost/hana/core/dispatch.hpp>
0019 #include <boost/hana/none_of.hpp>
0020 
0021 
0022 namespace boost { namespace hana {
0023     //! @cond
0024     template <typename Xs, typename Ys>
0025     constexpr auto is_disjoint_t::operator()(Xs&& xs, Ys&& ys) const {
0026         using S1 = typename hana::tag_of<Xs>::type;
0027         using S2 = typename hana::tag_of<Ys>::type;
0028         using IsDisjoint = BOOST_HANA_DISPATCH_IF(
0029             decltype(is_disjoint_impl<S1, S2>{}),
0030             hana::Searchable<S1>::value &&
0031             hana::Searchable<S2>::value
0032         );
0033 
0034     #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0035         static_assert(hana::Searchable<S1>::value,
0036         "hana::is_disjoint(xs, ys) requires 'xs' to be Searchable");
0037 
0038         static_assert(hana::Searchable<S2>::value,
0039         "hana::is_disjoint(xs, ys) requires 'ys' to be Searchable");
0040     #endif
0041 
0042         return IsDisjoint::apply(static_cast<Xs&&>(xs), static_cast<Ys&&>(ys));
0043     }
0044     //! @endcond
0045 
0046     namespace detail {
0047         template <typename Ys>
0048         struct in_by_reference {
0049             Ys const& ys;
0050             template <typename X>
0051             constexpr auto operator()(X const& x) const
0052             { return hana::contains(ys, x); }
0053         };
0054     }
0055 
0056     template <typename S1, typename S2, bool condition>
0057     struct is_disjoint_impl<S1, S2, when<condition>> : default_ {
0058         template <typename Xs, typename Ys>
0059         static constexpr auto apply(Xs const& xs, Ys const& ys) {
0060             return hana::none_of(xs, detail::in_by_reference<Ys>{ys});
0061         }
0062     };
0063 }} // end namespace boost::hana
0064 
0065 #endif // !BOOST_HANA_IS_DISJOINT_HPP