File: ratio

package info (click to toggle)
cppreference-doc 20170409-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 259,872 kB
  • sloc: xml: 570,184; python: 1,923; php: 520; makefile: 168; sh: 25; cpp: 9; ansic: 9
file content (84 lines) | stat: -rw-r--r-- 3,140 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*  Copyright (C) 2015  Povilas Kanapickas <povilas@radix.lt>

    This file is part of cppreference-doc

    This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
    Unported License. To view a copy of this license, visit
    http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
    Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

    Permission is granted to copy, distribute and/or modify this document
    under the terms of the GNU Free Documentation License, Version 1.3 or
    any later version published by the Free Software Foundation; with no
    Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
*/

#ifndef CPPREFERENCE_RATIO_H
#define CPPREFERENCE_RATIO_H

#if CPPREFERENCE_STDVER>= 2011
#include <cstdint>
#include <type_traits>

namespace std {

template<std::intmax_t Num,
         std::intmax_t Denom = 1>
struct ratio {
public:
    typedef ratio<Num, Denom> type;
    static constexpr intmax_t num;
    static constexpr intmax_t den;
};

typedef ratio<1, 1000000000000000000000000> yocto;
typedef ratio<1,    1000000000000000000000> zepto;
typedef ratio<1,       1000000000000000000> atto;
typedef ratio<1,          1000000000000000> femto;
typedef ratio<1,             1000000000000> pico;
typedef ratio<1,                1000000000> nano;
typedef ratio<1,                   1000000> micro;
typedef ratio<1,                      1000> milli;
typedef ratio<1,                       100> centi;
typedef ratio<1,                        10> deci;
typedef ratio<                       10, 1> deca;
typedef ratio<                      100, 1> hecto;
typedef ratio<                     1000, 1> kilo;
typedef ratio<                  1000000, 1> mega;
typedef ratio<               1000000000, 1> giga;
typedef ratio<            1000000000000, 1> tera;
typedef ratio<         1000000000000000, 1> peta;
typedef ratio<      1000000000000000000, 1> exa;
typedef ratio<   1000000000000000000000, 1> zetta;
typedef ratio<1000000000000000000000000, 1> yotta;

// SIMPLIFIED: the following are alias templates
template<class R1, class R2>
class ratio_add : public ratio<1, 1> {};
template<class R1, class R2>
class ratio_subtract : public ratio<1, 1> {};
template<class R1, class R2>
class ratio_divide : public ratio<1, 1> {};
template<class R1, class R2>
class ratio_multiply : public ratio<1, 1> {};

// SIMPLIFIED: the following inherit from different specialization
// of std::integral_constant
template<class R1, class R2>
struct ratio_equal : std::integral_constant<bool, true> {};
template<class R1, class R2>
struct ratio_not_equal : std::integral_constant<bool, true> {};
template<class R1, class R2>
struct ratio_less : std::integral_constant<bool, true> {};
template<class R1, class R2>
struct ratio_less_equal : std::integral_constant<bool, true> {};
template<class R1, class R2>
struct ratio_greater : std::integral_constant<bool, true> {};
template<class R1, class R2>
struct ratio_greater_equal : std::integral_constant<bool, true> {};

} // namespace std

#endif // CPPREFERENCE_STDVER>= 2011

#endif // CPPREFERENCE_RATIO_H