SI 2.5.4
A header only c++ library that provides type safety and user defined literals for handling physical values defined in the International System of Units.
Loading...
Searching...
No Matches
time.h
Go to the documentation of this file.
1
12#pragma once
13
14#include <chrono>
15#include <ratio>
16
18#include "detail/unit.h"
19#include "detail/unit_symbol.h"
20
21namespace SI {
22
23namespace detail {
24template <typename _exponent, typename _type, typename _ratio>
25using time_base_t = detail::unit_t<'T', _exponent, _type, _ratio>;
26}
27template <typename _type, typename _ratio>
29
30template <typename _type, typename _ratio>
32
33template <typename _type> using atto_seconds_t = time_t<_type, std::atto>;
34template <typename _type> using femto_seconds_t = time_t<_type, std::femto>;
35template <typename _type> using pico_seconds_t = time_t<_type, std::pico>;
36template <typename _type> using nano_seconds_t = time_t<_type, std::nano>;
37template <typename _type>
39template <typename _type>
41template <typename _type> using seconds_t = time_t<_type, std::ratio<1>>;
42template <typename _type>
44template <typename _type>
46
47// specialize unit_symbol for usage with stream operators
48template <>
49struct unit_symbol<'T', std::ratio<1>> : SI::detail::unit_symbol_impl<'s'> {};
50
51template <>
52struct unit_symbol<'T', std::ratio<60, 1>>
53 : SI::detail::unit_symbol_impl<'m', 'i', 'n'> {};
54
55template <>
56struct unit_symbol<'T', std::ratio<3600, 1>>
58
59template <typename _ratio>
60struct unit_symbol<'T', _ratio>
61 : SI::detail::unit_symbol_impl<SI::detail::ratio_prefix<_ratio>::value,
62 's'> {
63 static_assert(std::ratio_less_equal<_ratio, std::ratio<1>>::value,
64 "Generic streaming only implemented for ratios <=1");
65};
66
67inline namespace literals {
68
69template <char... _digits> constexpr atto_seconds_t<int64_t> operator""_as() {
71 SI::detail::parsing::Number<_digits...>::value};
72}
73
74template <char... _digits> constexpr femto_seconds_t<int64_t> operator""_fs() {
76 SI::detail::parsing::Number<_digits...>::value};
77}
78
79template <char... _digits> constexpr pico_seconds_t<int64_t> operator""_ps() {
81 SI::detail::parsing::Number<_digits...>::value};
82}
83
84template <char... _digits> constexpr nano_seconds_t<int64_t> operator""_ns() {
86 SI::detail::parsing::Number<_digits...>::value};
87}
88
89template <char... _digits>
90constexpr SI::micro_seconds_t<int64_t> operator"" _us() {
92 SI::detail::parsing::Number<_digits...>::value};
93}
94
95template <char... _digits>
96constexpr SI::milli_seconds_t<int64_t> operator"" _ms() {
98 SI::detail::parsing::Number<_digits...>::value};
99}
100template <char... _digits> constexpr SI::seconds_t<int64_t> operator"" _s() {
101 return SI::seconds_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
102}
103
104template <char... _digits> constexpr SI::minutes_t<int64_t> operator"" _min() {
105 return SI::minutes_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
106}
107
108template <char... _digits> constexpr hours_t<int64_t> operator"" _h() {
109 return hours_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
110}
111
112constexpr atto_seconds_t<long double> operator""_as(long double value) {
113 return atto_seconds_t<long double>{value};
114}
115
116constexpr femto_seconds_t<long double> operator""_fs(long double value) {
117 return femto_seconds_t<long double>{value};
118}
119
120constexpr pico_seconds_t<long double> operator""_ps(long double value) {
121 return pico_seconds_t<long double>{value};
122}
123
124constexpr nano_seconds_t<long double> operator""_ns(long double value) {
125 return nano_seconds_t<long double>{value};
126}
127
128constexpr SI::micro_seconds_t<long double> operator"" _us(long double us) {
130}
131
132constexpr SI::milli_seconds_t<long double> operator"" _ms(long double ms) {
134}
135
136constexpr SI::seconds_t<long double> operator"" _s(long double s) {
138}
139
140constexpr SI::minutes_t<long double> operator"" _min(long double min) {
141 return SI::minutes_t<long double>{min};
142}
143
144constexpr SI::hours_t<long double> operator"" _h(long double h) {
145 return SI::hours_t<long double>{h};
146}
147
148} // namespace literals
149} // namespace SI
Definition absorbed_dose.h:18
interface class for number
Definition number_parser.h:111
Compile time string provider for conversion of unit types to strings.
Definition unit_symbol.h:21
base template class for holding values of type _type to be multiplied with a ratio _ratio
Definition unit.h:51
Base struct. Unusable needs template overloading.
Definition unit_symbol.h:64