/*! @file Defines `boost::hana::minus`. @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_MINUS_HPP #define BOOST_HANA_MINUS_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include BOOST_HANA_NAMESPACE_BEGIN //! @cond template constexpr decltype(auto) minus_t::operator()(X&& x, Y&& y) const { using T = typename hana::tag_of::type; using U = typename hana::tag_of::type; using Minus = BOOST_HANA_DISPATCH_IF(decltype(minus_impl{}), hana::Group::value && hana::Group::value ); #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS static_assert(hana::Group::value, "hana::minus(x, y) requires 'x' to be in a Group"); static_assert(hana::Group::value, "hana::minus(x, y) requires 'y' to be in a Group"); #endif return Minus::apply(static_cast(x), static_cast(y)); } //! @endcond template struct minus_impl> : default_ { template static constexpr auto apply(Args&& ...) = delete; }; template struct minus_impl> : default_ { template static constexpr decltype(auto) apply(X&& x, Y&& y) { return hana::plus(static_cast(x), hana::negate(static_cast(y))); } }; // Cross-type overload template struct minus_impl::value >> { using C = typename common::type; template static constexpr decltype(auto) apply(X&& x, Y&& y) { return hana::minus(hana::to(static_cast(x)), hana::to(static_cast(y))); } }; ////////////////////////////////////////////////////////////////////////// // Model for arithmetic data types ////////////////////////////////////////////////////////////////////////// template struct minus_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 Group ////////////////////////////////////////////////////////////////////////// namespace detail { template struct constant_from_minus { static constexpr auto value = hana::minus(hana::value(), hana::value()); using hana_tag = detail::CanonicalConstant; }; } template struct minus_impl::value && Group::value >> { template static constexpr decltype(auto) apply(X const&, Y const&) { return hana::to(detail::constant_from_minus{}); } }; BOOST_HANA_NAMESPACE_END #endif // !BOOST_HANA_MINUS_HPP