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
detail.h
Go to the documentation of this file.
1
12#pragma once
13
14#include "number_parser.h"
15#include <cstdint>
16#include <numeric>
17#include <ratio>
18
20namespace SI::detail {
21
23template <typename _type> struct is_ratio : std::false_type {};
24
25template <intmax_t _num, intmax_t _den>
26struct is_ratio<std::ratio<_num, _den>> : std::true_type {};
27
28template <typename _type>
29inline constexpr bool is_ratio_v = is_ratio<_type>::value;
30
32template <typename _ratio_lhs, typename _ratio_rhs> struct ratio_gcd {
33private:
34 using gcd_num = std::integral_constant<std::intmax_t,
35 std::gcd<std::intmax_t, std::intmax_t>(
36 _ratio_lhs::num, _ratio_rhs::num)>;
37
38 using gcd_den = std::integral_constant<std::intmax_t,
39 std::gcd<std::intmax_t, std::intmax_t>(
40 _ratio_lhs::den, _ratio_rhs::den)>;
41
42public:
43 using ratio = std::ratio<gcd_num::value, (_ratio_lhs::den / gcd_den::value) *
44 _ratio_rhs::den>;
45};
46
47// forward declaration
48template <char _symbol, typename _exponent, typename _type, typename _ratio>
49struct unit_t;
50
53template <typename _unit> struct is_unit_t : std::false_type {};
54
56template <char _symbol, typename _exponent, typename _ratio, typename _type>
57struct is_unit_t<const unit_t<_symbol, _exponent, _type, _ratio>>
58 : std::true_type {};
59
61template <char _symbol, typename _exponent, typename _ratio, typename _type>
62struct is_unit_t<unit_t<_symbol, _exponent, _type, _ratio>> : std::true_type {};
63
64template <typename _type>
65inline constexpr bool is_unit_t_v = is_unit_t<_type>::value;
66
67} // namespace SI::detail
Namespace containing implementation details for SI.
Definition acceleration.h:34
constexpr bool is_ratio_v
Definition detail.h:29
constexpr bool is_unit_t_v
Definition detail.h:65
to check if a template is an instantiation of std::ratio
Definition detail.h:23
Definition detail.h:53
calculate gcd for rations
Definition detail.h:32
std::ratio< gcd_num::value,(_ratio_lhs::den/gcd_den::value) *_ratio_rhs::den > ratio
Definition detail.h:44
base template class for holding values of type _type to be multiplied with a ratio _ratio
Definition unit.h:51