Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:37:40

0001 /*!
0002 @file
0003 Defines arithmetic operators.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0008  */
0009 
0010 #ifndef BOOST_HANA_DETAIL_OPERATORS_ARITHMETIC_HPP
0011 #define BOOST_HANA_DETAIL_OPERATORS_ARITHMETIC_HPP
0012 
0013 #include <boost/hana/config.hpp>
0014 #include <boost/hana/core/tag_of.hpp>
0015 #include <boost/hana/fwd/div.hpp>
0016 #include <boost/hana/fwd/minus.hpp>
0017 #include <boost/hana/fwd/mod.hpp>
0018 #include <boost/hana/fwd/mult.hpp>
0019 #include <boost/hana/fwd/negate.hpp>
0020 #include <boost/hana/fwd/plus.hpp>
0021 
0022 #include <type_traits>
0023 
0024 
0025 namespace boost { namespace hana { namespace detail {
0026     template <typename Tag>
0027     struct arithmetic_operators {
0028         static constexpr bool value = false;
0029     };
0030 
0031     namespace operators {
0032         template <typename X, typename Y, typename = typename std::enable_if<
0033             detail::arithmetic_operators<typename hana::tag_of<X>::type>::value ||
0034             detail::arithmetic_operators<typename hana::tag_of<Y>::type>::value
0035         >::type>
0036         constexpr auto operator+(X&& x, Y&& y)
0037         { return hana::plus(static_cast<X&&>(x), static_cast<Y&&>(y)); }
0038 
0039 
0040         template <typename X, typename Y, typename = typename std::enable_if<
0041             detail::arithmetic_operators<typename hana::tag_of<X>::type>::value ||
0042             detail::arithmetic_operators<typename hana::tag_of<Y>::type>::value
0043         >::type>
0044         constexpr auto operator-(X&& x, Y&& y)
0045         { return hana::minus(static_cast<X&&>(x), static_cast<Y&&>(y)); }
0046 
0047         template <typename X, typename = typename std::enable_if<
0048             detail::arithmetic_operators<typename hana::tag_of<X>::type>::value
0049         >::type>
0050         constexpr auto operator-(X&& x)
0051         { return hana::negate(static_cast<X&&>(x)); }
0052 
0053 
0054         template <typename X, typename Y, typename = typename std::enable_if<
0055             detail::arithmetic_operators<typename hana::tag_of<X>::type>::value ||
0056             detail::arithmetic_operators<typename hana::tag_of<Y>::type>::value
0057         >::type>
0058         constexpr auto operator*(X&& x, Y&& y)
0059         { return hana::mult(static_cast<X&&>(x), static_cast<Y&&>(y)); }
0060 
0061 
0062         template <typename X, typename Y, typename = typename std::enable_if<
0063             detail::arithmetic_operators<typename hana::tag_of<X>::type>::value ||
0064             detail::arithmetic_operators<typename hana::tag_of<Y>::type>::value
0065         >::type>
0066         constexpr auto operator/(X&& x, Y&& y)
0067         { return hana::div(static_cast<X&&>(x), static_cast<Y&&>(y)); }
0068 
0069         template <typename X, typename Y, typename = typename std::enable_if<
0070             detail::arithmetic_operators<typename hana::tag_of<X>::type>::value ||
0071             detail::arithmetic_operators<typename hana::tag_of<Y>::type>::value
0072         >::type>
0073         constexpr auto operator%(X&& x, Y&& y)
0074         { return hana::mod(static_cast<X&&>(x), static_cast<Y&&>(y)); }
0075     } // end namespace operators
0076 } }} // end namespace boost::hana
0077 
0078 #endif // !BOOST_HANA_DETAIL_OPERATORS_ARITHMETIC_HPP