Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*!
0002 @file
0003 Defines `boost::hana::not_`.
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_NOT_HPP
0011 #define BOOST_HANA_NOT_HPP
0012 
0013 #include <boost/hana/fwd/not.hpp>
0014 
0015 #include <boost/hana/concept/constant.hpp>
0016 #include <boost/hana/concept/logical.hpp>
0017 #include <boost/hana/config.hpp>
0018 #include <boost/hana/core/to.hpp>
0019 #include <boost/hana/core/dispatch.hpp>
0020 #include <boost/hana/detail/canonical_constant.hpp>
0021 
0022 #include <type_traits>
0023 
0024 
0025 namespace boost { namespace hana {
0026     //! @cond
0027     template <typename X>
0028     constexpr decltype(auto) not_t::operator()(X&& x) const {
0029         using Bool = typename hana::tag_of<X>::type;
0030         using Not = BOOST_HANA_DISPATCH_IF(hana::not_impl<Bool>,
0031             hana::Logical<Bool>::value
0032         );
0033 
0034     #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0035         static_assert(hana::Logical<Bool>::value,
0036         "hana::not_(cond) requires 'cond' to be a Logical");
0037     #endif
0038 
0039         return Not::apply(static_cast<X&&>(x));
0040     }
0041     //! @endcond
0042 
0043     template <typename L, bool condition>
0044     struct not_impl<L, when<condition>> : hana::default_ {
0045         template <typename ...Args>
0046         static constexpr auto apply(Args&& ...) = delete;
0047     };
0048 
0049     template <typename L>
0050     struct not_impl<L, hana::when<std::is_arithmetic<L>::value>> {
0051         template <typename Cond>
0052         static constexpr Cond apply(Cond const& cond)
0053         { return static_cast<Cond>(cond ? false : true); }
0054     };
0055 
0056     namespace detail {
0057         template <typename C, typename X>
0058         struct constant_from_not {
0059             static constexpr auto value = hana::not_(hana::value<X>());
0060             using hana_tag = detail::CanonicalConstant<typename C::value_type>;
0061         };
0062     }
0063 
0064     template <typename C>
0065     struct not_impl<C, hana::when<
0066         hana::Constant<C>::value &&
0067         hana::Logical<typename C::value_type>::value
0068     >> {
0069         template <typename Cond>
0070         static constexpr auto apply(Cond const&)
0071         { return hana::to<C>(detail::constant_from_not<C, Cond>{}); }
0072     };
0073 }} // end namespace boost::hana
0074 
0075 #endif // !BOOST_HANA_NOT_HPP