/*! @file Adapts `std::ratio` for use with Hana. @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_EXT_STD_RATIO_HPP #define BOOST_HANA_EXT_STD_RATIO_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef BOOST_HANA_DOXYGEN_INVOKED namespace std { //! @ingroup group-ext-std //! Adaptation of `std::ratio` for Hana. //! //! //! Modeled concepts //! ---------------- //! 1. `Comparable`\n //! `std::ratio`s are compared for equality using `std::ratio_equal`. //! @include example/ext/std/ratio/comparable.cpp //! //! 2. `Orderable`\n //! `std::ratio`s are ordered using `std::ratio_less`. //! @include example/ext/std/ratio/orderable.cpp //! //! 3. `Monoid`, `Group`, `Ring`, and `EuclideanRing`\n //! `std::ratio`s are added, subtracted, multiplied and divided using //! `std::ratio_add`, `std::ratio_subtract`, `std::ratio_multiply` and //! `std::ratio_divide`, respectively. Furthermore, the neutral element //! for the additive operation is `std::ratio<0, 1>{}`, and the neutral //! element for the multiplicative operation is `std::ratio<1, 1>{}`. //! @include example/ext/std/ratio/arithmetic.cpp template class ratio { }; } #endif BOOST_HANA_NAMESPACE_BEGIN namespace ext { namespace std { struct ratio_tag; }} template struct tag_of> { using type = ext::std::ratio_tag; }; ////////////////////////////////////////////////////////////////////////// // Conversion from IntegralConstants ////////////////////////////////////////////////////////////////////////// template struct to_impl::value >> { template static constexpr auto apply(N const&) { return std::ratio{}; } }; ////////////////////////////////////////////////////////////////////////// // Comparable ////////////////////////////////////////////////////////////////////////// template <> struct equal_impl { template static constexpr auto apply(R1 const&, R2 const&) { return hana::bool_c::value>; } }; ////////////////////////////////////////////////////////////////////////// // Orderable ////////////////////////////////////////////////////////////////////////// template <> struct less_impl { template static constexpr auto apply(R1 const&, R2 const&) { return hana::bool_c::value>; } }; ////////////////////////////////////////////////////////////////////////// // Monoid ////////////////////////////////////////////////////////////////////////// template <> struct plus_impl { template static constexpr std::ratio_add apply(R1 const&, R2 const&) { return {}; } }; template <> struct zero_impl { static constexpr std::ratio<0> apply() { return {}; } }; ////////////////////////////////////////////////////////////////////////// // Group ////////////////////////////////////////////////////////////////////////// template <> struct minus_impl { template static constexpr std::ratio_subtract apply(R1 const&, R2 const&) { return {}; } }; ////////////////////////////////////////////////////////////////////////// // Ring ////////////////////////////////////////////////////////////////////////// template <> struct mult_impl { template static constexpr std::ratio_multiply apply(R1 const&, R2 const&) { return {}; } }; template <> struct one_impl { static constexpr std::ratio<1> apply() { return {}; } }; ////////////////////////////////////////////////////////////////////////// // EuclideanRing ////////////////////////////////////////////////////////////////////////// template <> struct div_impl { template static constexpr std::ratio_divide apply(R1 const&, R2 const&) { return {}; } }; template <> struct mod_impl { template static constexpr std::ratio<0> apply(R1 const&, R2 const&) { return {}; } }; BOOST_HANA_NAMESPACE_END #endif // !BOOST_HANA_EXT_STD_RATIO_HPP