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.
angle.h
Go to the documentation of this file.
1 
12 #pragma once
13 
14 #include "detail/number_parser.h"
15 #include "detail/unit.h"
16 #include "detail/unit_symbol.h"
17 
18 namespace SI {
20 template <typename _type, typename _ratio>
22 
23 template <typename _type> using atto_radian_t = angle_t<_type, std::atto>;
24 template <typename _type> using femto_radian_t = angle_t<_type, std::femto>;
25 template <typename _type> using pico_radian_t = angle_t<_type, std::pico>;
26 template <typename _type> using nano_radian_t = angle_t<_type, std::nano>;
27 template <typename _type> using micro_radian_t = angle_t<_type, std::micro>;
28 template <typename _type> using milli_radian_t = angle_t<_type, std::milli>;
29 template <typename _type> using radian_t = angle_t<_type, std::ratio<1>>;
30 
31 template <typename _type>
33 template <typename _type>
36 template <typename _type>
38 
39 // specialize unit_symbol for usage with stream operators
40 template <>
41 struct unit_symbol<'r', std::ratio<1>>
42  : SI::detail::unit_symbol_impl<'r', 'a', 'd'> {};
43 
44 template <>
45 struct unit_symbol<'r', std::ratio<100000000, 5729577951308232>>
46  : SI::detail::unit_symbol_impl<'u', 'd', 'e', 'g'> {};
47 
48 template <>
49 struct unit_symbol<'r', std::ratio<100000000000, 5729577951308232>>
50  : SI::detail::unit_symbol_impl<'m', 'd', 'e', 'g'> {};
51 
52 template <>
53 struct unit_symbol<'r', std::ratio<100000000000000, 5729577951308232>>
54  : SI::detail::unit_symbol_impl<'d', 'e', 'g'> {};
55 
56 template <typename _ratio>
57 struct unit_symbol<'r', _ratio>
58  : SI::detail::unit_symbol_impl<SI::detail::ratio_prefix<_ratio>::value, 'r',
59  'a', 'd'> {
60  static_assert(std::ratio_less_equal<_ratio, std::ratio<1>>::value,
61  "Generic streaming only implemented for ratios <=1");
62 };
63 
64 inline namespace literals {
65 
66 template <char... _digits> constexpr atto_radian_t<int64_t> operator""_arad() {
67  return atto_radian_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
68 }
69 
70 template <char... _digits> constexpr femto_radian_t<int64_t> operator""_frad() {
72  SI::detail::parsing::Number<_digits...>::value};
73 }
74 
75 template <char... _digits> constexpr pico_radian_t<int64_t> operator""_prad() {
76  return pico_radian_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
77 }
78 
79 template <char... _digits> constexpr nano_radian_t<int64_t> operator""_nrad() {
80  return nano_radian_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
81 }
82 
83 template <char... _digits> constexpr micro_radian_t<int64_t> operator""_urad() {
85  SI::detail::parsing::Number<_digits...>::value};
86 }
87 
88 template <char... _digits> constexpr milli_radian_t<int64_t> operator""_mrad() {
90  SI::detail::parsing::Number<_digits...>::value};
91 }
92 
93 template <char... _digits> constexpr radian_t<int64_t> operator""_rad() {
94  return radian_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
95 }
96 
97 constexpr atto_radian_t<long double> operator""_arad(long double value) {
98  return atto_radian_t<long double>{value};
99 }
100 
101 constexpr femto_radian_t<long double> operator""_frad(long double value) {
102  return femto_radian_t<long double>{value};
103 }
104 
105 constexpr pico_radian_t<long double> operator""_prad(long double value) {
106  return pico_radian_t<long double>{value};
107 }
108 
109 constexpr nano_radian_t<long double> operator""_nrad(long double value) {
110  return nano_radian_t<long double>{value};
111 }
112 
113 constexpr micro_radian_t<long double> operator""_urad(long double value) {
114  return micro_radian_t<long double>{value};
115 }
116 
117 constexpr milli_radian_t<long double> operator""_mrad(long double value) {
118  return milli_radian_t<long double>{value};
119 }
120 
121 constexpr radian_t<long double> operator""_rad(long double value) {
122  return radian_t<long double>{value};
123 }
124 
125 template <char... _digits> constexpr micro_degree_t<int64_t> operator""_udeg() {
127  SI::detail::parsing::Number<_digits...>::value};
128 }
129 
130 template <char... _digits> constexpr milli_degree_t<int64_t> operator""_mdeg() {
132  SI::detail::parsing::Number<_digits...>::value};
133 }
134 
135 template <char... _digits> constexpr degree_t<int64_t> operator""_deg() {
136  return degree_t<int64_t>{SI::detail::parsing::Number<_digits...>::value};
137 }
138 
139 constexpr micro_degree_t<long double> operator""_udeg(long double value) {
140  return micro_degree_t<long double>{value};
141 }
142 
143 constexpr milli_degree_t<long double> operator""_mdeg(long double value) {
144  return milli_degree_t<long double>{value};
145 }
146 
147 constexpr degree_t<long double> operator""_deg(long double value) {
148  return degree_t<long double>{value};
149 }
150 
151 } // namespace literals
152 
153 } // 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