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
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
18namespace SI::detail {
19
21template <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
30template <typename _ratio> struct ratio_prefix : std::false_type {};
31
32template <>
33struct ratio_prefix<std::atto> : std::integral_constant<char, 'a'> {};
34template <>
35struct ratio_prefix<std::femto> : std::integral_constant<char, 'f'> {};
36template <>
37struct ratio_prefix<std::pico> : std::integral_constant<char, 'p'> {};
38template <>
39struct ratio_prefix<std::nano> : std::integral_constant<char, 'n'> {};
40template <>
41struct ratio_prefix<std::micro> : std::integral_constant<char, 'u'> {};
42template <>
43struct ratio_prefix<std::milli> : std::integral_constant<char, 'm'> {};
44template <>
45struct ratio_prefix<std::centi> : std::integral_constant<char, 'c'> {};
46template <>
47struct ratio_prefix<std::kilo> : std::integral_constant<char, 'k'> {};
48template <>
49struct ratio_prefix<std::mega> : std::integral_constant<char, 'M'> {};
50template <>
51struct ratio_prefix<std::giga> : std::integral_constant<char, 'G'> {};
52template <>
53struct ratio_prefix<std::tera> : std::integral_constant<char, 'T'> {};
54template <>
55struct ratio_prefix<std::peta> : std::integral_constant<char, 'P'> {};
56template <>
57struct ratio_prefix<std::exa> : std::integral_constant<char, 'E'> {};
58
59} // namespace SI::detail
60namespace SI {
62template <char _dimension_symbol, typename _ratio,
63 typename _exponent = std::ratio<1>>
64struct 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