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.
unit_symbol.h
Go to the documentation of this file.
1 
12 #pragma once
13 #include <array>
14 #include <ratio>
15 #include <string_view>
16 #include <type_traits>
17 
18 namespace SI::detail {
19 
21 template <char... Cs> struct unit_symbol_impl {
22  static_assert(sizeof...(Cs) > 0, "Empty strings are disallowed");
23  // using double curly braces to because of a bug in clang5
24  // See https://bugs.llvm.org/show_bug.cgi?id=21629
25  static constexpr const std::array<char, sizeof...(Cs)> value{{Cs...}};
26  static constexpr const std::string_view str{value.data(), value.size()};
27 };
28 
30 template <typename _ratio> struct ratio_prefix : std::false_type {};
31 
32 template <>
33 struct ratio_prefix<std::atto> : std::integral_constant<char, 'a'> {};
34 template <>
35 struct ratio_prefix<std::femto> : std::integral_constant<char, 'f'> {};
36 template <>
37 struct ratio_prefix<std::pico> : std::integral_constant<char, 'p'> {};
38 template <>
39 struct ratio_prefix<std::nano> : std::integral_constant<char, 'n'> {};
40 template <>
41 struct ratio_prefix<std::micro> : std::integral_constant<char, 'u'> {};
42 template <>
43 struct ratio_prefix<std::milli> : std::integral_constant<char, 'm'> {};
44 template <>
45 struct ratio_prefix<std::centi> : std::integral_constant<char, 'c'> {};
46 template <>
47 struct ratio_prefix<std::kilo> : std::integral_constant<char, 'k'> {};
48 template <>
49 struct ratio_prefix<std::mega> : std::integral_constant<char, 'M'> {};
50 template <>
51 struct ratio_prefix<std::giga> : std::integral_constant<char, 'G'> {};
52 template <>
53 struct ratio_prefix<std::tera> : std::integral_constant<char, 'T'> {};
54 template <>
55 struct ratio_prefix<std::peta> : std::integral_constant<char, 'P'> {};
56 template <>
57 struct ratio_prefix<std::exa> : std::integral_constant<char, 'E'> {};
58 
59 } // namespace SI::detail
60 namespace SI {
62 template <char _dimension_symbol, typename _ratio,
63  typename _exponent = std::ratio<1>>
64 struct unit_symbol : public std::false_type {};
65 
66 } // namespace SI
Namespace containing implementation details for SI.
Definition: acceleration.h:34
Definition: absorbed_dose.h:18
base template for ratio prefix, unusable
Definition: unit_symbol.h:30
Compile time string provider for conversion of unit types to strings.
Definition: unit_symbol.h:21
static constexpr const std::array< char, sizeof...(Cs)> value
Definition: unit_symbol.h:25
static constexpr const std::string_view str
Definition: unit_symbol.h:26
Base struct. Unusable needs template overloading.
Definition: unit_symbol.h:64