/*! @file Defines `boost::hana::div`. @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_DIV_HPP #define BOOST_HANA_DIV_HPP #include #include #include #include #include #include #include #include #include #include BOOST_HANA_NAMESPACE_BEGIN //! @cond template constexpr decltype(auto) div_t::operator()(X&& x, Y&& y) const { using T = typename hana::tag_of::type; using U = typename hana::tag_of::type; using Div = BOOST_HANA_DISPATCH_IF(decltype(div_impl{}), hana::EuclideanRing::value && hana::EuclideanRing::value && !is_default>::value ); #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS static_assert(hana::EuclideanRing::value, "hana::div(x, y) requires 'x' to be an EuclideanRing"); static_assert(hana::EuclideanRing::value, "hana::div(x, y) requires 'y' to be an EuclideanRing"); static_assert(!is_default>::value, "hana::div(x, y) requires 'x' and 'y' to be embeddable " "in a common EuclideanRing"); #endif return Div::apply(static_cast(x), static_cast(y)); } //! @endcond template struct div_impl> : default_ { template static constexpr auto apply(Args&& ...) = delete; }; // Cross-type overload template struct div_impl::value >> { using C = typename common::type; template static constexpr decltype(auto) apply(X&& x, Y&& y) { return hana::div(hana::to(static_cast(x)), hana::to(static_cast(y))); } }; ////////////////////////////////////////////////////////////////////////// // Model for integral data types ////////////////////////////////////////////////////////////////////////// template struct div_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_div { static constexpr auto value = hana::div(hana::value(), hana::value()); using hana_tag = detail::CanonicalConstant; }; } template struct div_impl::value && EuclideanRing::value >> { template static constexpr decltype(auto) apply(X const&, Y const&) { return hana::to(detail::constant_from_div{}); } }; BOOST_HANA_NAMESPACE_END #endif // !BOOST_HANA_DIV_HPP