1/*!
2@file
3Defines `boost::hana::is_disjoint`.
4
5Copyright Louis Dionne 2013-2022
6Distributed under the Boost Software License, Version 1.0.
7(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
8 */
9
10#ifndef BOOST_HANA_IS_DISJOINT_HPP
11#define BOOST_HANA_IS_DISJOINT_HPP
12
13#include <boost/hana/fwd/is_disjoint.hpp>
14
15#include <boost/hana/concept/searchable.hpp>
16#include <boost/hana/config.hpp>
17#include <boost/hana/contains.hpp>
18#include <boost/hana/core/dispatch.hpp>
19#include <boost/hana/none_of.hpp>
20
21
22namespace boost { namespace hana {
23 //! @cond
24 template <typename Xs, typename Ys>
25 constexpr auto is_disjoint_t::operator()(Xs&& xs, Ys&& ys) const {
26 using S1 = typename hana::tag_of<Xs>::type;
27 using S2 = typename hana::tag_of<Ys>::type;
28 using IsDisjoint = BOOST_HANA_DISPATCH_IF(
29 decltype(is_disjoint_impl<S1, S2>{}),
30 hana::Searchable<S1>::value &&
31 hana::Searchable<S2>::value
32 );
33
34 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
35 static_assert(hana::Searchable<S1>::value,
36 "hana::is_disjoint(xs, ys) requires 'xs' to be Searchable");
37
38 static_assert(hana::Searchable<S2>::value,
39 "hana::is_disjoint(xs, ys) requires 'ys' to be Searchable");
40 #endif
41
42 return IsDisjoint::apply(static_cast<Xs&&>(xs), static_cast<Ys&&>(ys));
43 }
44 //! @endcond
45
46 namespace detail {
47 template <typename Ys>
48 struct in_by_reference {
49 Ys const& ys;
50 template <typename X>
51 constexpr auto operator()(X const& x) const
52 { return hana::contains(ys, x); }
53 };
54 }
55
56 template <typename S1, typename S2, bool condition>
57 struct is_disjoint_impl<S1, S2, when<condition>> : default_ {
58 template <typename Xs, typename Ys>
59 static constexpr auto apply(Xs const& xs, Ys const& ys) {
60 return hana::none_of(xs, detail::in_by_reference<Ys>{ys});
61 }
62 };
63}} // end namespace boost::hana
64
65#endif // !BOOST_HANA_IS_DISJOINT_HPP
66

source code of boost/libs/hana/include/boost/hana/is_disjoint.hpp