File indexing completed on 2025-01-18 09:38:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_NEGATE_HPP
0011 #define BOOST_HANA_NEGATE_HPP
0012
0013 #include <boost/hana/fwd/negate.hpp>
0014
0015 #include <boost/hana/concept/group.hpp>
0016 #include <boost/hana/config.hpp>
0017 #include <boost/hana/core/dispatch.hpp>
0018 #include <boost/hana/fwd/minus.hpp>
0019 #include <boost/hana/zero.hpp>
0020
0021 #include <type_traits>
0022
0023
0024 namespace boost { namespace hana {
0025
0026 template <typename X>
0027 constexpr decltype(auto) negate_t::operator()(X&& x) const {
0028 using G = typename hana::tag_of<X>::type;
0029 using Negate = BOOST_HANA_DISPATCH_IF(negate_impl<G>,
0030 hana::Group<G>::value
0031 );
0032
0033 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0034 static_assert(hana::Group<G>::value,
0035 "hana::negate(x) requires 'x' to be in a Group");
0036 #endif
0037
0038 return Negate::apply(static_cast<X&&>(x));
0039 }
0040
0041
0042 template <typename T, bool condition>
0043 struct negate_impl<T, when<condition>> : default_ {
0044 template <typename X>
0045 static constexpr decltype(auto) apply(X&& x)
0046 { return hana::minus(hana::zero<T>(), static_cast<X&&>(x)); }
0047 };
0048
0049
0050
0051
0052 template <typename T>
0053 struct negate_impl<T, when<std::is_arithmetic<T>::value &&
0054 !std::is_same<bool, T>::value>> {
0055 template <typename X>
0056 static constexpr decltype(auto) apply(X&& x)
0057 { return -static_cast<X&&>(x); }
0058 };
0059 }}
0060
0061 #endif