| 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_CHRONO_H |
| 17 |
#define CPPREFERENCE_CHRONO_H |
| 18 |
|
| 19 |
#if CPPREFERENCE_STDVER>= 2011 |
| 20 |
#include <ratio> |
| 21 |
|
| 22 |
namespace std { |
| 23 |
namespace chrono { |
| 24 |
|
| 25 |
template<class Rep, class Period = std::ratio<1>> |
| 26 |
class duration { |
| 27 |
public: |
| 28 |
|
| 29 |
constexpr duration() = default; |
| 30 |
duration(const duration&) = default; |
| 31 |
template<class Rep2> |
| 32 |
constexpr explicit duration(const Rep2& r); |
| 33 |
template<class Rep2, class Period2> |
| 34 |
constexpr duration(const duration<Rep2, Period2>& d); |
| 35 |
|
| 36 |
duration& operator=(const duration& other) = default; |
| 37 |
|
| 38 |
constexpr rep count() const; |
| 39 |
|
| 40 |
static constexpr duration zero(); |
| 41 |
static constexpr duration min(); |
| 42 |
static constexpr duration max(); |
| 43 |
|
| 44 |
constexpr duration operator+() const; |
| 45 |
constexpr duration operator-() const; |
| 46 |
|
| 47 |
duration& operator++(); |
| 48 |
duration operator++(int); |
| 49 |
duration& operator--(); |
| 50 |
duration operator--(int); |
| 51 |
|
| 52 |
duration& operator+=(const duration& d); |
| 53 |
duration& operator-=(const duration& d); |
| 54 |
duration& operator*=(const rep& rhs); |
| 55 |
duration& operator/=(const rep& rhs); |
| 56 |
duration& operator%=(const rep& rhs); |
| 57 |
duration& operator%=(const duration& rhs); |
| 58 |
}; |
| 59 |
|
| 60 |
// SIMPLIFIED: actually returns common_type |
| 61 |
template<class Rep1, class Period1, class Rep2, class Period2> |
| 62 |
duration<Rep1, Period1> |
| 63 |
constexpr operator+(const duration<Rep1, Period1>& lhs, |
| 64 |
const duration<Rep2, Period2>& rhs); |
| 65 |
|
| 66 |
template<class Rep1, class Period1, class Rep2, class Period2> |
| 67 |
duration<Rep1, Period1> |
| 68 |
constexpr operator-(const duration<Rep1, Period1>& lhs, |
| 69 |
const duration<Rep2, Period2>& rhs); |
| 70 |
|
| 71 |
template<class Rep1, class Period, class Rep2> |
| 72 |
duration<Rep1, Period> |
| 73 |
constexpr operator*(const duration<Rep1, Period>& d, |
| 74 |
const Rep2& s); |
| 75 |
|
| 76 |
template<class Rep1, class Rep2, class Period> |
| 77 |
duration<Rep1, Period> |
| 78 |
constexpr operator*(const Rep1& s, |
| 79 |
const duration<Rep2, Period>& d); |
| 80 |
|
| 81 |
template<class Rep1, class Period, class Rep2> |
| 82 |
duration<Rep1, Period> |
| 83 |
constexpr operator/(const duration<Rep1, Period>& d, |
| 84 |
const Rep2& s); |
| 85 |
|
| 86 |
template<class Rep1, class Period1, class Rep2, class Period2> |
| 87 |
duration<Rep1, Period1> |
| 88 |
constexpr operator/(const duration<Rep1, Period1>& lhs, |
| 89 |
const duration<Rep2, Period2>& rhs); |
| 90 |
|
| 91 |
template<class Rep1, class Period, class Rep2> |
| 92 |
duration<Rep1, Period> |
| 93 |
constexpr operator%(const duration<Rep1, Period>& d, |
| 94 |
const Rep2& s); |
| 95 |
|
| 96 |
template<class Rep1, class Period1, class Rep2, class Period2> |
| 97 |
duration<Rep1, Period1> |
| 98 |
constexpr operator%(const duration<Rep1, Period1>& lhs, |
| 99 |
const duration<Rep2, Period2>& rhs); |
| 100 |
|
| 101 |
// comparison operators |
| 102 |
template <class Rep1, class Period1, class Rep2, class Period2> |
| 103 |
constexpr bool operator==(const duration<Rep1, Period1>& lhs, |
| 104 |
const duration<Rep2, Period2>& rhs); |
| 105 |
|
| 106 |
template <class Rep1, class Period1, class Rep2, class Period2> |
| 107 |
constexpr bool operator!=(const duration<Rep1, Period1>& lhs, |
| 108 |
const duration<Rep2, Period2>& rhs); |
| 109 |
|
| 110 |
template <class Rep1, class Period1, class Rep2, class Period2> |
| 111 |
constexpr bool operator<(const duration<Rep1, Period1>& lhs, |
| 112 |
const duration<Rep2, Period2>& rhs); |
| 113 |
|
| 114 |
template <class Rep1, class Period1, class Rep2, class Period2> |
| 115 |
constexpr bool operator<=(const duration<Rep1, Period1>& lhs, |
| 116 |
const duration<Rep2, Period2>& rhs); |
| 117 |
|
| 118 |
template <class Rep1, class Period1, class Rep2, class Period2> |
| 119 |
constexpr bool operator>(const duration<Rep1, Period1>& lhs, |
| 120 |
const duration<Rep2, Period2>& rhs); |
| 121 |
|
| 122 |
template <class Rep1, class Period1, class Rep2, class Period2> |
| 123 |
constexpr bool operator>=(const duration<Rep1, Period1>& lhs, |
| 124 |
const duration<Rep2, Period2>& rhs); |
| 125 |
|
| 126 |
template <class ToDuration, class Rep, class Period> |
| 127 |
constexpr ToDuration duration_cast(const duration<Rep, Period>& d); |
| 128 |
|
| 129 |
typedef duration<int, std::nano> nanoseconds; |
| 130 |
typedef duration<int, std::micro> microseconds; |
| 131 |
typedef duration<int, std::milli> milliseconds; |
| 132 |
typedef duration<int> seconds; |
| 133 |
typedef duration<int, std::ratio<60>> minutes; |
| 134 |
typedef duration<int, std::ratio<3600>> hours; |
| 135 |
|
| 136 |
template <class Rep> |
| 137 |
struct treat_as_floating_point : std::is_floating_point<Rep> {}; |
| 138 |
|
| 139 |
template <class Rep> |
| 140 |
struct duration_values { |
| 141 |
static constexpr Rep zero(); |
| 142 |
static constexpr Rep min(); |
| 143 |
static constexpr Rep max(); |
| 144 |
}; |
| 145 |
|
| 146 |
// fwd decl |
| 147 |
class system_clock; |
| 148 |
|
| 149 |
template<class Clock, class Duration = typename Clock::duration> |
| 150 |
class time_point { |
| 151 |
public: |
| 152 |
#if CPPREFERENCE_SIMPLIFY_TYPEDEFS |
| 153 |
typedef system_clock clock; |
| 154 |
typedef duration<int> duration; |
| 155 |
typedef int rep; |
| 156 |
typedef ratio<1> period; |
| 157 |
#else |
| 158 |
typedef Clock clock; |
| 159 |
typedef Duration duration; |
| 160 |
typedef Duration::rep rep; |
| 161 |
typedef Duration::period period; |
| 162 |
#endif |
| 163 |
|
| 164 |
time_point(); |
| 165 |
explicit time_point(const duration& d); |
| 166 |
template<class Duration2> |
| 167 |
time_point(const time_point<Clock, Duration2>& t); |
| 168 |
|
| 169 |
duration time_since_epoch() const; |
| 170 |
|
| 171 |
time_point& operator+=(const duration& d); |
| 172 |
time_point& operator-=(const duration& d); |
| 173 |
|
| 174 |
static constexpr time_point min(); |
| 175 |
static constexpr time_point max(); |
| 176 |
}; |
| 177 |
|
| 178 |
// time point operators |
| 179 |
// SIMPLIFIED: return type uses common_type |
| 180 |
template<class C, class D1, class R2, class P2> |
| 181 |
time_point<C, D1> |
| 182 |
operator+(const time_point<C, D1>& pt, |
| 183 |
const duration<R2, P2>& d); |
| 184 |
|
| 185 |
template<class R1, class P1, class C, class D2> |
| 186 |
time_point<C, D2> |
| 187 |
operator+(const duration<R1, P1>& d, |
| 188 |
const time_point<C, D2>& pt); |
| 189 |
|
| 190 |
template<class C, class D1, class R2, class P2> |
| 191 |
time_point<C, D1> |
| 192 |
operator-(const time_point<C, D1>& pt, |
| 193 |
const duration<R2, P2>& d); |
| 194 |
|
| 195 |
template<class R1, class P1, class C, class D2> |
| 196 |
time_point<C, D2> |
| 197 |
operator-(const duration<R1, P1>& d, |
| 198 |
const time_point<C, D2>& pt); |
| 199 |
|
| 200 |
template<class Clock, class Dur1, class Dur2> |
| 201 |
bool operator==(const time_point<Clock, Dur1>& lhs, |
| 202 |
const time_point<Clock, Dur2>& rhs); |
| 203 |
template<class Clock, class Dur1, class Dur2> |
| 204 |
bool operator!=(const time_point<Clock, Dur1>& lhs, |
| 205 |
const time_point<Clock, Dur2>& rhs); |
| 206 |
template<class Clock, class Dur1, class Dur2> |
| 207 |
bool operator<(const time_point<Clock, Dur1>& lhs, |
| 208 |
const time_point<Clock, Dur2>& rhs); |
| 209 |
template<class Clock, class Dur1, class Dur2> |
| 210 |
bool operator<=(const time_point<Clock, Dur1>& lhs, |
| 211 |
const time_point<Clock, Dur2>& rhs); |
| 212 |
template<class Clock, class Dur1, class Dur2> |
| 213 |
bool operator>(const time_point<Clock, Dur1>& lhs, |
| 214 |
const time_point<Clock, Dur2>& rhs); |
| 215 |
template<class Clock, class Dur1, class Dur2> |
| 216 |
bool operator>=(const time_point<Clock, Dur1>& lhs, |
| 217 |
const time_point<Clock, Dur2>& rhs); |
| 218 |
|
| 219 |
template <class ToDuration, class Clock, class Duration> |
| 220 |
time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t); |
| 221 |
|
| 222 |
class system_clock { |
| 223 |
public: |
| 224 |
typedef int rep; // SIMPLIFIED: actually unspecified |
| 225 |
typedef std::ratio<1> period; // SIMPLIFIED: actually unspecified |
| 226 |
typedef duration<rep, period> duration; |
| 227 |
typedef time_point<system_clock> time_point; |
| 228 |
|
| 229 |
constexpr static bool is_steady; |
| 230 |
|
| 231 |
static std::chrono::time_point<std::chrono::system_clock> now(); |
| 232 |
static std::time_t to_time_t(const time_point& t); |
| 233 |
static std::chrono::system_clock::time_point from_time_t(std::time_t t); |
| 234 |
}; |
| 235 |
|
| 236 |
class steady_clock { |
| 237 |
public: |
| 238 |
typedef int rep; // SIMPLIFIED: actually unspecified |
| 239 |
typedef std::ratio<1> period; // SIMPLIFIED: actually unspecified |
| 240 |
typedef duration<rep, period> duration; |
| 241 |
typedef time_point<steady_clock> time_point; |
| 242 |
|
| 243 |
constexpr static bool is_steady; |
| 244 |
|
| 245 |
static std::chrono::time_point<std::chrono::steady_clock> now(); |
| 246 |
}; |
| 247 |
|
| 248 |
class high_resolution_clock { |
| 249 |
public: |
| 250 |
typedef int rep; // SIMPLIFIED: actually unspecified |
| 251 |
typedef std::ratio<1> period; // SIMPLIFIED: actually unspecified |
| 252 |
typedef duration<rep, period> duration; |
| 253 |
typedef time_point<high_resolution_clock> time_point; |
| 254 |
|
| 255 |
constexpr static bool is_steady; |
| 256 |
|
| 257 |
static std::chrono::time_point<std::chrono::high_resolution_clock> now(); |
| 258 |
}; |
| 259 |
|
| 260 |
} // namespace chrono |
| 261 |
} // namespace std |
| 262 |
|
| 263 |
#endif // CPPREFERENCE_STDVER>= 2011 |
| 264 |
|
| 265 |
#endif // CPPREFERENCE_CHRONO_H |