]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/hana/include/boost/hana/mult.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / hana / include / boost / hana / mult.hpp
CommitLineData
7c673cae
FG
1/*!
2@file
3Defines `boost::hana::mult`.
4
5@copyright Louis Dionne 2013-2016
6Distributed 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_MULT_HPP
11#define BOOST_HANA_MULT_HPP
12
13#include <boost/hana/fwd/mult.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#include <boost/hana/detail/has_common_embedding.hpp>
22#include <boost/hana/value.hpp>
23
24#include <type_traits>
25
26
27BOOST_HANA_NAMESPACE_BEGIN
28 //! @cond
29 template <typename X, typename Y>
30 constexpr decltype(auto) mult_t::operator()(X&& x, Y&& y) const {
31 using T = typename hana::tag_of<X>::type;
32 using U = typename hana::tag_of<Y>::type;
33 using Mult = BOOST_HANA_DISPATCH_IF(decltype(mult_impl<T, U>{}),
34 hana::Ring<T>::value &&
35 hana::Ring<U>::value &&
36 !is_default<mult_impl<T, U>>::value
37 );
38
39 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
40 static_assert(hana::Ring<T>::value,
41 "hana::mult(x, y) requires 'x' to be in a Ring");
42
43 static_assert(hana::Ring<U>::value,
44 "hana::mult(x, y) requires 'y' to be in a Ring");
45
46 static_assert(!is_default<mult_impl<T, U>>::value,
47 "hana::mult(x, y) requires 'x' and 'y' to be embeddable "
48 "in a common Ring");
49 #endif
50
51 return Mult::apply(static_cast<X&&>(x), static_cast<Y&&>(y));
52 }
53 //! @endcond
54
55 template <typename T, typename U, bool condition>
56 struct mult_impl<T, U, when<condition>> : default_ {
57 template <typename ...Args>
58 static constexpr auto apply(Args&& ...) = delete;
59 };
60
61 // Cross-type overload
62 template <typename T, typename U>
63 struct mult_impl<T, U, when<
64 detail::has_nontrivial_common_embedding<Ring, T, U>::value
65 >> {
66 using C = typename common<T, U>::type;
67 template <typename X, typename Y>
68 static constexpr decltype(auto) apply(X&& x, Y&& y) {
69 return hana::mult(hana::to<C>(static_cast<X&&>(x)),
70 hana::to<C>(static_cast<Y&&>(y)));
71 }
72 };
73
74 //////////////////////////////////////////////////////////////////////////
75 // Model for non-boolean arithmetic data types
76 //////////////////////////////////////////////////////////////////////////
77 template <typename T>
78 struct mult_impl<T, T, when<std::is_arithmetic<T>::value &&
79 !std::is_same<bool, T>::value>> {
80 template <typename X, typename Y>
81 static constexpr decltype(auto) apply(X&& x, Y&& y)
82 { return static_cast<X&&>(x) * static_cast<Y&&>(y); }
83 };
84
85 //////////////////////////////////////////////////////////////////////////
86 // Model for Constants over a Ring
87 //////////////////////////////////////////////////////////////////////////
88 namespace detail {
89 template <typename C, typename X, typename Y>
90 struct constant_from_mult {
91 static constexpr auto value = hana::mult(hana::value<X>(), hana::value<Y>());
92 using hana_tag = detail::CanonicalConstant<typename C::value_type>;
93 };
94 }
95
96 template <typename C>
97 struct mult_impl<C, C, when<
98 hana::Constant<C>::value &&
99 Ring<typename C::value_type>::value
100 >> {
101 template <typename X, typename Y>
102 static constexpr decltype(auto) apply(X const&, Y const&)
103 { return hana::to<C>(detail::constant_from_mult<C, X, Y>{}); }
104 };
105BOOST_HANA_NAMESPACE_END
106
107#endif // !BOOST_HANA_MULT_HPP