3 Defines `boost::hana::is_disjoint`.
5 @copyright Louis Dionne 2013-2016
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_HANA_IS_DISJOINT_HPP
11 #define BOOST_HANA_IS_DISJOINT_HPP
13 #include <boost/hana/fwd/is_disjoint.hpp>
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>
22 BOOST_HANA_NAMESPACE_BEGIN
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
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");
38 static_assert(hana::Searchable<S2>::value,
39 "hana::is_disjoint(xs, ys) requires 'ys' to be Searchable");
42 return IsDisjoint::apply(static_cast<Xs&&>(xs), static_cast<Ys&&>(ys));
47 template <typename Ys>
48 struct in_by_reference {
51 constexpr auto operator()(X const& x) const
52 { return hana::contains(ys, x); }
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});
63 BOOST_HANA_NAMESPACE_END
65 #endif // !BOOST_HANA_IS_DISJOINT_HPP