]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/include/boost/hana/negate.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / hana / include / boost / hana / negate.hpp
1 /*!
2 @file
3 Defines `boost::hana::negate`.
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_NEGATE_HPP
11 #define BOOST_HANA_NEGATE_HPP
12
13 #include <boost/hana/fwd/negate.hpp>
14
15 #include <boost/hana/concept/group.hpp>
16 #include <boost/hana/config.hpp>
17 #include <boost/hana/core/dispatch.hpp>
18 #include <boost/hana/fwd/minus.hpp>
19 #include <boost/hana/zero.hpp>
20
21 #include <type_traits>
22
23
24 BOOST_HANA_NAMESPACE_BEGIN
25 //! @cond
26 template <typename X>
27 constexpr decltype(auto) negate_t::operator()(X&& x) const {
28 using G = typename hana::tag_of<X>::type;
29 using Negate = BOOST_HANA_DISPATCH_IF(negate_impl<G>,
30 hana::Group<G>::value
31 );
32
33 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
34 static_assert(hana::Group<G>::value,
35 "hana::negate(x) requires 'x' to be in a Group");
36 #endif
37
38 return Negate::apply(static_cast<X&&>(x));
39 }
40 //! @endcond
41
42 template <typename T, bool condition>
43 struct negate_impl<T, when<condition>> : default_ {
44 template <typename X>
45 static constexpr decltype(auto) apply(X&& x)
46 { return hana::minus(hana::zero<T>(), static_cast<X&&>(x)); }
47 };
48
49 //////////////////////////////////////////////////////////////////////////
50 // Model for arithmetic data types
51 //////////////////////////////////////////////////////////////////////////
52 template <typename T>
53 struct negate_impl<T, when<std::is_arithmetic<T>::value &&
54 !std::is_same<bool, T>::value>> {
55 template <typename X>
56 static constexpr decltype(auto) apply(X&& x)
57 { return -static_cast<X&&>(x); }
58 };
59 BOOST_HANA_NAMESPACE_END
60
61 #endif // !BOOST_HANA_NEGATE_HPP