/*! @file Defines `boost::hana::mult`. Copyright Louis Dionne 2013-2022 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_MULT_HPP #define BOOST_HANA_MULT_HPP #include #include #include #include #include #include #include #include #include #include namespace boost { namespace hana { //! @cond template constexpr decltype(auto) mult_t::operator()(X&& x, Y&& y) const { using T = typename hana::tag_of::type; using U = typename hana::tag_of::type; using Mult = BOOST_HANA_DISPATCH_IF(decltype(mult_impl{}), hana::Ring::value && hana::Ring::value && !is_default>::value ); #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS static_assert(hana::Ring::value, "hana::mult(x, y) requires 'x' to be in a Ring"); static_assert(hana::Ring::value, "hana::mult(x, y) requires 'y' to be in a Ring"); static_assert(!is_default>::value, "hana::mult(x, y) requires 'x' and 'y' to be embeddable " "in a common Ring"); #endif return Mult::apply(static_cast(x), static_cast(y)); } //! @endcond template struct mult_impl> : default_ { template static constexpr auto apply(Args&& ...) = delete; }; // Cross-type overload template struct mult_impl::value >> { using C = typename common::type; template static constexpr decltype(auto) apply(X&& x, Y&& y) { return hana::mult(hana::to(static_cast(x)), hana::to(static_cast(y))); } }; ////////////////////////////////////////////////////////////////////////// // Model for non-boolean arithmetic data types ////////////////////////////////////////////////////////////////////////// template struct mult_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 Ring ////////////////////////////////////////////////////////////////////////// namespace detail { template struct constant_from_mult { static constexpr auto value = hana::mult(hana::value(), hana::value()); using hana_tag = detail::CanonicalConstant; }; } template struct mult_impl::value && Ring::value >> { template static constexpr decltype(auto) apply(X const&, Y const&) { return hana::to(detail::constant_from_mult{}); } }; }} // end namespace boost::hana #endif // !BOOST_HANA_MULT_HPP