]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/hana/one.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / hana / one.hpp
1 /*!
2 @file
3 Defines `boost::hana::one`.
4
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)
8 */
9
10 #ifndef BOOST_HANA_ONE_HPP
11 #define BOOST_HANA_ONE_HPP
12
13 #include <boost/hana/fwd/one.hpp>
14
15 #include <boost/hana/concept/constant.hpp>
16 #include <boost/hana/concept/ring.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 template <typename R>
27 struct one_t {
28 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
29 static_assert(hana::Ring<R>::value,
30 "hana::one<R>() requires 'R' to be a Ring");
31 #endif
32
33 constexpr decltype(auto) operator()() const {
34 using One = BOOST_HANA_DISPATCH_IF(one_impl<R>,
35 hana::Ring<R>::value
36 );
37
38 return One::apply();
39 }
40 };
41
42 template <typename R, bool condition>
43 struct one_impl<R, when<condition>> : default_ {
44 template <typename ...Args>
45 static constexpr auto apply(Args&& ...) = delete;
46 };
47
48 //////////////////////////////////////////////////////////////////////////
49 // Model for non-boolean arithmetic data types
50 //////////////////////////////////////////////////////////////////////////
51 template <typename T>
52 struct one_impl<T, when<std::is_arithmetic<T>::value &&
53 !std::is_same<bool, T>::value>> {
54 static constexpr T apply()
55 { return static_cast<T>(1); }
56 };
57
58 //////////////////////////////////////////////////////////////////////////
59 // Model for Constants over a Ring
60 //////////////////////////////////////////////////////////////////////////
61 namespace detail {
62 template <typename C>
63 struct constant_from_one {
64 static constexpr auto value = hana::one<typename C::value_type>();
65 using hana_tag = detail::CanonicalConstant<typename C::value_type>;
66 };
67 }
68
69 template <typename C>
70 struct one_impl<C, when<
71 hana::Constant<C>::value &&
72 Ring<typename C::value_type>::value
73 >> {
74 static constexpr decltype(auto) apply()
75 { return hana::to<C>(detail::constant_from_one<C>{}); }
76 };
77 BOOST_HANA_NAMESPACE_END
78
79 #endif // !BOOST_HANA_ONE_HPP