Debian Codegraph @

headers/ratio

raw
1 /* Copyright (C) 2015 Povilas Kanapickas <[email protected]>
2
3 This file is part of cppreference-doc
4
5 This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
6 Unported License. To view a copy of this license, visit
7 http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
8 Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
9
10 Permission is granted to copy, distribute and/or modify this document
11 under the terms of the GNU Free Documentation License, Version 1.3 or
12 any later version published by the Free Software Foundation; with no
13 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
14 */
15
16 #ifndef CPPREFERENCE_RATIO_H
17 #define CPPREFERENCE_RATIO_H
18
19 #if CPPREFERENCE_STDVER>= 2011
20 #include <cstdint>
21 #include <type_traits>
22
23 namespace std {
24
25 template<std::intmax_t Num,
26 std::intmax_t Denom = 1>
27 struct ratio {
28 public:
29 typedef ratio<Num, Denom> type;
30 static constexpr intmax_t num;
31 static constexpr intmax_t den;
32 };
33
34 typedef ratio<1, 1000000000000000000000000> yocto;
35 typedef ratio<1, 1000000000000000000000> zepto;
36 typedef ratio<1, 1000000000000000000> atto;
37 typedef ratio<1, 1000000000000000> femto;
38 typedef ratio<1, 1000000000000> pico;
39 typedef ratio<1, 1000000000> nano;
40 typedef ratio<1, 1000000> micro;
41 typedef ratio<1, 1000> milli;
42 typedef ratio<1, 100> centi;
43 typedef ratio<1, 10> deci;
44 typedef ratio< 10, 1> deca;
45 typedef ratio< 100, 1> hecto;
46 typedef ratio< 1000, 1> kilo;
47 typedef ratio< 1000000, 1> mega;
48 typedef ratio< 1000000000, 1> giga;
49 typedef ratio< 1000000000000, 1> tera;
50 typedef ratio< 1000000000000000, 1> peta;
51 typedef ratio< 1000000000000000000, 1> exa;
52 typedef ratio< 1000000000000000000000, 1> zetta;
53 typedef ratio<1000000000000000000000000, 1> yotta;
54
55 // SIMPLIFIED: the following are alias templates
56 template<class R1, class R2>
57 class ratio_add : public ratio<1, 1> {};
58 template<class R1, class R2>
59 class ratio_subtract : public ratio<1, 1> {};
60 template<class R1, class R2>
61 class ratio_divide : public ratio<1, 1> {};
62 template<class R1, class R2>
63 class ratio_multiply : public ratio<1, 1> {};
64
65 // SIMPLIFIED: the following inherit from different specialization
66 // of std::integral_constant
67 template<class R1, class R2>
68 struct ratio_equal : std::integral_constant<bool, true> {};
69 template<class R1, class R2>
70 struct ratio_not_equal : std::integral_constant<bool, true> {};
71 template<class R1, class R2>
72 struct ratio_less : std::integral_constant<bool, true> {};
73 template<class R1, class R2>
74 struct ratio_less_equal : std::integral_constant<bool, true> {};
75 template<class R1, class R2>
76 struct ratio_greater : std::integral_constant<bool, true> {};
77 template<class R1, class R2>
78 struct ratio_greater_equal : std::integral_constant<bool, true> {};
79
80 } // namespace std
81
82 #endif // CPPREFERENCE_STDVER>= 2011
83
84 #endif // CPPREFERENCE_RATIO_H