13 #ifndef TINYMPL_RATIO_HPP
14 #define TINYMPL_RATIO_HPP
18 #include <tinympl/functional.hpp>
26 template<std::
intmax_t Num, std::
intmax_t Den>
struct make_rational
28 typedef std::ratio<Num,Den> ratio_t;
49 template<std::
intmax_t Num,std::
intmax_t Den>
using rational =
typename detail::make_rational<Num,Den>::type;
51 template<std::intmax_t Num1,std::intmax_t Den1,
52 std::intmax_t Num2,std::intmax_t Den2>
struct plus<
53 std::ratio<Num1,Den1>,
54 std::ratio<Num2,Den2> > : std::ratio_add<std::ratio<Num1,Den1>, std::ratio<Num2,Den2> > {};
56 template<std::intmax_t Num1,std::intmax_t Den1,
57 std::intmax_t Num2,std::intmax_t Den2>
struct minus<
58 std::ratio<Num1,Den1>,
59 std::ratio<Num2,Den2> > : std::ratio_subtract<std::ratio<Num1,Den1>, std::ratio<Num2,Den2> > {};
62 template<std::intmax_t Num1,std::intmax_t Den1,
63 std::intmax_t Num2,std::intmax_t Den2>
struct multiplies<
64 std::ratio<Num1,Den1>,
65 std::ratio<Num2,Den2> > : std::ratio_multiply<std::ratio<Num1,Den1>, std::ratio<Num2,Den2> > {};
67 template<std::intmax_t Num1,std::intmax_t Den1,
68 std::intmax_t Num2,std::intmax_t Den2>
struct divides<
69 std::ratio<Num1,Den1>,
70 std::ratio<Num2,Den2> > : std::ratio_divide<std::ratio<Num1,Den1>, std::ratio<Num2,Den2> > {};
72 template<std::
intmax_t Num,std::
intmax_t Den>
struct negate<std::ratio<Num,Den> >
74 typedef std::ratio<-Num,Den> type;
77 template<std::intmax_t Num1,std::intmax_t Den1,
78 std::intmax_t Num2,std::intmax_t Den2>
struct equal_to<
79 std::ratio<Num1,Den1>,
80 std::ratio<Num2,Den2> > :
81 std::integral_constant<bool,
82 std::ratio<Num1,Den1>::num == std::ratio<Num2,Den2>::num &&
83 std::ratio<Num1,Den1>::den == std::ratio<Num2,Den2>::den> {};
85 template<std::intmax_t Num1,std::intmax_t Den1,
86 std::intmax_t Num2,std::intmax_t Den2>
struct less<
87 std::ratio<Num1,Den1>,
88 std::ratio<Num2,Den2> > : std::ratio_less<std::ratio<Num1,Den1>, std::ratio<Num2,Den2> > {};
93 #endif // TINYMPL_RATIO_HPP
Sums its arguments.
Definition: plus.hpp:26
typename detail::make_rational< Num, Den >::type rational
Convenience wrapper around std::ratio to automatically reduce num and den to coprime factors...
Definition: ratio.hpp:49