3 Defines `boost::hana::not_`.
5 @copyright Louis Dionne 2013-2017
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_NOT_HPP
11 #define BOOST_HANA_NOT_HPP
13 #include <boost/hana/fwd/not.hpp>
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>
22 #include <type_traits>
25 namespace boost { namespace hana {
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
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");
39 return Not::apply(static_cast<X&&>(x));
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;
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); }
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>;
65 struct not_impl<C, hana::when<
66 hana::Constant<C>::value &&
67 hana::Logical<typename C::value_type>::value
69 template <typename Cond>
70 static constexpr auto apply(Cond const&)
71 { return hana::to<C>(detail::constant_from_not<C, Cond>{}); }
73 }} // end namespace boost::hana
75 #endif // !BOOST_HANA_NOT_HPP