/*! @file Defines `boost::hana::mod`. @copyright Louis Dionne 2013-2016 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_MOD_HPP #define BOOST_HANA_MOD_HPP #include #include #include #include #include #include #include #include #include #include BOOST_HANA_NAMESPACE_BEGIN //! @cond template constexpr decltype(auto) mod_t::operator()(X&& x, Y&& y) const { using T = typename hana::tag_of::type; using U = typename hana::tag_of::type; using Mod = BOOST_HANA_DISPATCH_IF(decltype(mod_impl{}), hana::EuclideanRing::value && hana::EuclideanRing::value && !is_default>::value ); #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS static_assert(hana::EuclideanRing::value, "hana::mod(x, y) requires 'x' to be an EuclideanRing"); static_assert(hana::EuclideanRing::value, "hana::mod(x, y) requires 'y' to be an EuclideanRing"); static_assert(!is_default>::value, "hana::mod(x, y) requires 'x' and 'y' to be embeddable " "in a common EuclideanRing"); #endif return Mod::apply(static_cast(x), static_cast(y)); } //! @endcond template struct mod_impl> : default_ { template static constexpr auto apply(Args&& ...) = delete; }; // Cross-type overload template struct mod_impl::value >> { using C = typename common::type; template static constexpr decltype(auto) apply(X&& x, Y&& y) { return hana::mod(hana::to(static_cast(x)), hana::to(static_cast(y))); } }; ////////////////////////////////////////////////////////////////////////// // Model for integral data types ////////////////////////////////////////////////////////////////////////// template struct mod_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 an EuclideanRing ////////////////////////////////////////////////////////////////////////// namespace detail { template struct constant_from_mod { static constexpr auto value = hana::mod(hana::value(), hana::value()); using hana_tag = detail::CanonicalConstant; }; } template struct mod_impl::value && EuclideanRing::value >> { template static constexpr decltype(auto) apply(X const&, Y const&) { return hana::to(detail::constant_from_mod{}); } }; BOOST_HANA_NAMESPACE_END #endif // !BOOST_HANA_MOD_HPP