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.
time.h
Go to the documentation of this file.
1 
12 #pragma once
13 
14 #include <chrono>
15 #include <ratio>
16 
17 #include "detail/number_parser.h"
18 #include "detail/unit.h"
19 #include "detail/unit_symbol.h"
20 
21 namespace SI {
22 
23 namespace detail {
24 template <typename _exponent, typename _type, typename _ratio>
26 }
27 template <typename _type, typename _ratio>
28 using time_t = detail::time_base_t<std::ratio<1>, _type, _ratio>;
29 
30 template <typename _type, typename _ratio>
32 
33 template <typename _type> using atto_seconds_t = time_t<_type, std::atto>;
34 template <typename _type> using femto_seconds_t = time_t<_type, std::femto>;
35 template <typename _type> using pico_seconds_t = time_t<_type, std::pico>;
36 template <typename _type> using nano_seconds_t = time_t<_type, std::nano>;
37 template <typename _type>
39 template <typename _type>
41 template <typename _type> using seconds_t = time_t<_type, std::ratio<1>>;
42 template <typename _type>
44 template <typename _type>
46 
47 // specialize unit_symbol for usage with stream operators
48 template <>
49 struct unit_symbol<'T', std::ratio<1>> : SI::detail::unit_symbol_impl<'s'> {};
50 
51 template <>
52 struct unit_symbol<'T', std::ratio<60, 1>>
53  : SI::detail::unit_symbol_impl<'m', 'i', 'n'> {};
54 
55 template <>
56 struct unit_symbol<'T', std::ratio<3600, 1>>
58 
59 template <typename _ratio>
60 struct 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 
67 inline namespace literals {
68 
69 template <char... _digits> constexpr atto_seconds_t<int64_t> operator""_as() {
71  SI::detail::parsing::Number<_digits...>::value};
72 }
73 
74 template <char... _digits> constexpr femto_seconds_t<int64_t> operator""_fs() {
76  SI::detail::parsing::Number<_digits...>::value};
77 }
78 
79 template <char... _digits> constexpr pico_seconds_t<int64_t> operator""_ps() {
81  SI::detail::parsing::Number<_digits...>::value};
82 }
83 
84 template <char... _digits> constexpr nano_seconds_t<int64_t> operator""_ns() {
86  SI::detail::parsing::Number<_digits...>::value};
87 }
88 
89 template <char... _digits>
90 constexpr SI::micro_seconds_t<int64_t> operator"" _us() {
92  SI::detail::parsing::Number<_digits...>::value};
93 }
94 
95 template <char... _digits>
96 constexpr SI::milli_seconds_t<int64_t> operator"" _ms() {
98  SI::detail::parsing::Number<_digits...>::value};
99 }
100 template <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 
104 template <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 
108 template <char... _digits> constexpr hours_t<int64_t> operator"" _h() {
109  return hours_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
110 }
111 
112 constexpr atto_seconds_t<long double> operator""_as(long double value) {
113  return atto_seconds_t<long double>{value};
114 }
115 
116 constexpr femto_seconds_t<long double> operator""_fs(long double value) {
117  return femto_seconds_t<long double>{value};
118 }
119 
120 constexpr pico_seconds_t<long double> operator""_ps(long double value) {
121  return pico_seconds_t<long double>{value};
122 }
123 
124 constexpr nano_seconds_t<long double> operator""_ns(long double value) {
125  return nano_seconds_t<long double>{value};
126 }
127 
128 constexpr SI::micro_seconds_t<long double> operator"" _us(long double us) {
130 }
131 
132 constexpr SI::milli_seconds_t<long double> operator"" _ms(long double ms) {
134 }
135 
136 constexpr SI::seconds_t<long double> operator"" _s(long double s) {
137  return SI::seconds_t<long double>{s};
138 }
139 
140 constexpr SI::minutes_t<long double> operator"" _min(long double min) {
141  return SI::minutes_t<long double>{min};
142 }
143 
144 constexpr 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