3 Defines arithmetic operators.
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)
10 #ifndef BOOST_HANA_DETAIL_OPERATORS_ARITHMETIC_HPP
11 #define BOOST_HANA_DETAIL_OPERATORS_ARITHMETIC_HPP
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/core/tag_of.hpp>
15 #include <boost/hana/fwd/div.hpp>
16 #include <boost/hana/fwd/minus.hpp>
17 #include <boost/hana/fwd/mod.hpp>
18 #include <boost/hana/fwd/mult.hpp>
19 #include <boost/hana/fwd/negate.hpp>
20 #include <boost/hana/fwd/plus.hpp>
22 #include <type_traits>
25 BOOST_HANA_NAMESPACE_BEGIN namespace detail {
26 template <typename Tag>
27 struct arithmetic_operators {
28 static constexpr bool value = false;
32 template <typename X, typename Y, typename = typename std::enable_if<
33 detail::arithmetic_operators<typename hana::tag_of<X>::type>::value ||
34 detail::arithmetic_operators<typename hana::tag_of<Y>::type>::value
36 constexpr auto operator+(X&& x, Y&& y)
37 { return hana::plus(static_cast<X&&>(x), static_cast<Y&&>(y)); }
40 template <typename X, typename Y, typename = typename std::enable_if<
41 detail::arithmetic_operators<typename hana::tag_of<X>::type>::value ||
42 detail::arithmetic_operators<typename hana::tag_of<Y>::type>::value
44 constexpr auto operator-(X&& x, Y&& y)
45 { return hana::minus(static_cast<X&&>(x), static_cast<Y&&>(y)); }
47 template <typename X, typename = typename std::enable_if<
48 detail::arithmetic_operators<typename hana::tag_of<X>::type>::value
50 constexpr auto operator-(X&& x)
51 { return hana::negate(static_cast<X&&>(x)); }
54 template <typename X, typename Y, typename = typename std::enable_if<
55 detail::arithmetic_operators<typename hana::tag_of<X>::type>::value ||
56 detail::arithmetic_operators<typename hana::tag_of<Y>::type>::value
58 constexpr auto operator*(X&& x, Y&& y)
59 { return hana::mult(static_cast<X&&>(x), static_cast<Y&&>(y)); }
62 template <typename X, typename Y, typename = typename std::enable_if<
63 detail::arithmetic_operators<typename hana::tag_of<X>::type>::value ||
64 detail::arithmetic_operators<typename hana::tag_of<Y>::type>::value
66 constexpr auto operator/(X&& x, Y&& y)
67 { return hana::div(static_cast<X&&>(x), static_cast<Y&&>(y)); }
69 template <typename X, typename Y, typename = typename std::enable_if<
70 detail::arithmetic_operators<typename hana::tag_of<X>::type>::value ||
71 detail::arithmetic_operators<typename hana::tag_of<Y>::type>::value
73 constexpr auto operator%(X&& x, Y&& y)
74 { return hana::mod(static_cast<X&&>(x), static_cast<Y&&>(y)); }
75 } // end namespace operators
76 } BOOST_HANA_NAMESPACE_END
78 #endif // !BOOST_HANA_DETAIL_OPERATORS_ARITHMETIC_HPP