/*! @file Defines `boost::hana::plus`. @copyright Louis Dionne 2013-2017 Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) */ #ifndef BOOST_HANA_PLUS_HPP #define BOOST_HANA_PLUS_HPP #include #include #include #include #include #include #include #include #include #include namespace boost { namespace hana { //! @cond template constexpr decltype(auto) plus_t::operator()(X&& x, Y&& y) const { using T = typename hana::tag_of::type; using U = typename hana::tag_of::type; using Plus = BOOST_HANA_DISPATCH_IF(decltype(plus_impl{}), hana::Monoid::value && hana::Monoid::value && !is_default>::value ); #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS static_assert(hana::Monoid::value, "hana::plus(x, y) requires 'x' to be a Monoid"); static_assert(hana::Monoid::value, "hana::plus(x, y) requires 'y' to be a Monoid"); static_assert(!is_default>::value, "hana::plus(x, y) requires 'x' and 'y' to be embeddable " "in a common Monoid"); #endif return Plus::apply(static_cast(x), static_cast(y)); } //! @endcond template struct plus_impl> : default_ { template static constexpr auto apply(Args&& ...) = delete; }; // Cross-type overload template struct plus_impl::value >> { using C = typename common::type; template static constexpr decltype(auto) apply(X&& x, Y&& y) { return hana::plus(hana::to(static_cast(x)), hana::to(static_cast(y))); } }; ////////////////////////////////////////////////////////////////////////// // Model for non-boolean arithmetic data types ////////////////////////////////////////////////////////////////////////// template struct plus_impl::value && !std::is_same::value >> { template static constexpr decltype(auto) apply(X&& x, Y&& y) { return static_cast(x) + static_cast(y); } }; ////////////////////////////////////////////////////////////////////////// // Model for Constants over a Monoid ////////////////////////////////////////////////////////////////////////// namespace detail { template struct constant_from_plus { static constexpr auto value = hana::plus(hana::value(), hana::value()); using hana_tag = detail::CanonicalConstant; }; } template struct plus_impl::value && Monoid::value >> { template static constexpr decltype(auto) apply(X const&, Y const&) { return hana::to(detail::constant_from_plus{}); } }; }} // end namespace boost::hana #endif // !BOOST_HANA_PLUS_HPP