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.
length.h
Go to the documentation of this file.
1 
12 #pragma once
13 #include <limits>
14 #include <ratio>
15 #include <stdexcept>
16 
17 #include "detail/number_parser.h"
18 #include "detail/unit.h"
19 #include "detail/unit_symbol.h"
20 
21 namespace SI {
22 
23 template <typename _type, typename _ratio>
25 
26 template <typename _type> using atto_metre_t = length_t<_type, std::atto>;
27 template <typename _type> using femto_metre_t = length_t<_type, std::femto>;
28 template <typename _type> using pico_metre_t = length_t<_type, std::pico>;
29 template <typename _type> using nano_metre_t = length_t<_type, std::nano>;
30 template <typename _type> using micro_metre_t = length_t<_type, std::micro>;
31 template <typename _type> using milli_metre_t = length_t<_type, std::milli>;
32 template <typename _type> using centi_metre_t = length_t<_type, std::centi>;
33 template <typename _type> using metre_t = length_t<_type, std::ratio<1>>;
34 template <typename _type> using kilo_metre_t = length_t<_type, std::kilo>;
35 template <typename _type> using mega_metre_t = length_t<_type, std::mega>;
36 template <typename _type> using giga_metre_t = length_t<_type, std::giga>;
37 template <typename _type> using tera_metre_t = length_t<_type, std::tera>;
38 template <typename _type> using peta_metre_t = length_t<_type, std::peta>;
39 template <typename _type> using exa_metre_t = length_t<_type, std::exa>;
40 
41 // specialize unit_symbol for usage with stream operators
42 template <>
43 struct unit_symbol<'L', std::ratio<1>> : SI::detail::unit_symbol_impl<'m'> {};
44 
45 template <typename _ratio>
46 struct unit_symbol<'L', _ratio>
47  : SI::detail::unit_symbol_impl<SI::detail::ratio_prefix<_ratio>::value,
48  'm'> {};
49 
50 inline namespace literals {
51 template <char... _digits> constexpr atto_metre_t<int64_t> operator""_am() {
52  return atto_metre_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
53 }
54 
55 template <char... _digits> constexpr femto_metre_t<int64_t> operator""_fm() {
56  return femto_metre_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
57 }
58 
59 template <char... _digits> constexpr pico_metre_t<int64_t> operator""_pm() {
60  return pico_metre_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
61 }
62 
63 template <char... _digits> constexpr nano_metre_t<int64_t> operator""_nm() {
64  return nano_metre_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
65 }
66 
67 template <char... _digits> constexpr micro_metre_t<int64_t> operator""_um() {
68  return micro_metre_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
69 }
70 
71 template <char... _digits> constexpr milli_metre_t<int64_t> operator""_mm() {
72  return milli_metre_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
73 }
74 
75 template <char... _digits> constexpr centi_metre_t<int64_t> operator""_cm() {
76  return centi_metre_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
77 }
78 
79 template <char... _digits> constexpr metre_t<int64_t> operator""_m() {
80  return metre_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
81 }
82 
83 template <char... _digits> constexpr kilo_metre_t<int64_t> operator""_km() {
84  return kilo_metre_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
85 }
86 
87 template <char... _digits> constexpr mega_metre_t<int64_t> operator""_Mm() {
88  return mega_metre_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
89 }
90 
91 template <char... _digits> constexpr giga_metre_t<int64_t> operator""_Gm() {
92  return giga_metre_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
93 }
94 
95 template <char... _digits> constexpr tera_metre_t<int64_t> operator""_Tm() {
96  return tera_metre_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
97 }
98 
99 template <char... _digits> constexpr peta_metre_t<int64_t> operator""_Pm() {
100  return peta_metre_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
101 }
102 
103 template <char... _digits> constexpr exa_metre_t<int64_t> operator""_Em() {
104  return exa_metre_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
105 }
106 
107 constexpr atto_metre_t<long double> operator""_am(long double value) {
108  return atto_metre_t<long double>{value};
109 }
110 
111 constexpr femto_metre_t<long double> operator""_fm(long double value) {
112  return femto_metre_t<long double>{value};
113 }
114 
115 constexpr pico_metre_t<long double> operator""_pm(long double value) {
116  return pico_metre_t<long double>{value};
117 }
118 
119 constexpr nano_metre_t<long double> operator""_nm(long double value) {
120  return nano_metre_t<long double>{value};
121 }
122 
123 constexpr micro_metre_t<long double> operator""_um(long double value) {
124  return micro_metre_t<long double>{value};
125 }
126 
127 constexpr milli_metre_t<long double> operator""_mm(long double value) {
128  return milli_metre_t<long double>{value};
129 }
130 
131 constexpr centi_metre_t<long double> operator""_cm(long double value) {
132  return centi_metre_t<long double>{value};
133 }
134 
135 constexpr metre_t<long double> operator""_m(long double value) {
136  return metre_t<long double>{value};
137 }
138 
139 constexpr kilo_metre_t<long double> operator""_km(long double value) {
140  return kilo_metre_t<long double>{value};
141 }
142 
143 constexpr mega_metre_t<long double> operator""_Mm(long double value) {
144  return mega_metre_t<long double>{value};
145 }
146 
147 constexpr giga_metre_t<long double> operator""_Gm(long double value) {
148  return giga_metre_t<long double>{value};
149 }
150 
151 constexpr tera_metre_t<long double> operator""_Tm(long double value) {
152  return tera_metre_t<long double>{value};
153 }
154 
155 constexpr peta_metre_t<long double> operator""_Pm(long double value) {
156  return peta_metre_t<long double>{value};
157 }
158 
159 constexpr exa_metre_t<long double> operator""_Em(long double value) {
160  return exa_metre_t<long double>{value};
161 }
162 
163 } // namespace literals
164 } // 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