]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*! |
2 | @file | |
3 | Defines `boost::hana::not_`. | |
4 | ||
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) | |
8 | */ | |
9 | ||
10 | #ifndef BOOST_HANA_NOT_HPP | |
11 | #define BOOST_HANA_NOT_HPP | |
12 | ||
13 | #include <boost/hana/fwd/not.hpp> | |
14 | ||
15 | #include <boost/hana/concept/constant.hpp> | |
16 | #include <boost/hana/concept/logical.hpp> | |
17 | #include <boost/hana/config.hpp> | |
18 | #include <boost/hana/core/to.hpp> | |
19 | #include <boost/hana/core/dispatch.hpp> | |
20 | #include <boost/hana/detail/canonical_constant.hpp> | |
21 | ||
22 | #include <type_traits> | |
23 | ||
24 | ||
25 | BOOST_HANA_NAMESPACE_BEGIN | |
26 | //! @cond | |
27 | template <typename X> | |
28 | constexpr decltype(auto) not_t::operator()(X&& x) const { | |
29 | using Bool = typename hana::tag_of<X>::type; | |
30 | using Not = BOOST_HANA_DISPATCH_IF(hana::not_impl<Bool>, | |
31 | hana::Logical<Bool>::value | |
32 | ); | |
33 | ||
34 | #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS | |
35 | static_assert(hana::Logical<Bool>::value, | |
36 | "hana::not_(cond) requires 'cond' to be a Logical"); | |
37 | #endif | |
38 | ||
39 | return Not::apply(static_cast<X&&>(x)); | |
40 | } | |
41 | //! @endcond | |
42 | ||
43 | template <typename L, bool condition> | |
44 | struct not_impl<L, when<condition>> : hana::default_ { | |
45 | template <typename ...Args> | |
46 | static constexpr auto apply(Args&& ...) = delete; | |
47 | }; | |
48 | ||
49 | template <typename L> | |
50 | struct not_impl<L, hana::when<std::is_arithmetic<L>::value>> { | |
51 | template <typename Cond> | |
52 | static constexpr Cond apply(Cond const& cond) | |
53 | { return static_cast<Cond>(cond ? false : true); } | |
54 | }; | |
55 | ||
56 | namespace detail { | |
57 | template <typename C, typename X> | |
58 | struct constant_from_not { | |
59 | static constexpr auto value = hana::not_(hana::value<X>()); | |
60 | using hana_tag = detail::CanonicalConstant<typename C::value_type>; | |
61 | }; | |
62 | } | |
63 | ||
64 | template <typename C> | |
65 | struct not_impl<C, hana::when< | |
66 | hana::Constant<C>::value && | |
67 | hana::Logical<typename C::value_type>::value | |
68 | >> { | |
69 | template <typename Cond> | |
70 | static constexpr auto apply(Cond const&) | |
71 | { return hana::to<C>(detail::constant_from_not<C, Cond>{}); } | |
72 | }; | |
73 | BOOST_HANA_NAMESPACE_END | |
74 | ||
75 | #endif // !BOOST_HANA_NOT_HPP |