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.
cross_unit_operations.h
Go to the documentation of this file.
1 
12 #pragma once
13 
14 #include "detail.h"
15 
16 namespace SI::detail {
17 // forward declaration
18 template <char _symbol, typename _exponent, typename _type, typename _ratio>
19 struct unit_t;
20 
25 template <template <typename...> typename _resulting_unit, typename _unit_lhs,
26  typename _unit_rhs>
27 constexpr auto cross_unit_divide(const _unit_lhs &lhs, const _unit_rhs &rhs) {
28  // do not use for the same unit as this should result in decreasing the
29  // exponent
30  static_assert(!std::is_same<_unit_lhs, _unit_rhs>::value);
31  static_assert(is_unit_t_v<_unit_lhs>, "lhs parameter is a unit_t");
32  static_assert(is_unit_t_v<_unit_rhs>, "rhs parameter is a unit_t");
33 
34  using resulting_ratio = typename std::ratio_divide<typename _unit_lhs::ratio,
35  typename _unit_rhs::ratio>;
36  return _resulting_unit<typename _unit_lhs::internal_type, resulting_ratio>(
37  lhs.value() / rhs.value());
38 }
44 
45 template <template <typename...> typename _resulting_unit, typename _unit_lhs,
46  typename _unit_rhs>
47 constexpr auto cross_unit_multiply(const _unit_lhs &lhs, const _unit_rhs &rhs) {
48  // do not use for the same unit as this should result in increasing the
49  // exponent
50  static_assert(!std::is_same<_unit_lhs, _unit_rhs>::value);
51  static_assert(is_unit_t_v<_unit_lhs>, "lhs parameter is a unit_t");
52  static_assert(is_unit_t_v<_unit_rhs>, "rhs parameter is a unit_t");
53  using resulting_ratio =
54  typename std::ratio_multiply<typename _unit_lhs::ratio,
55  typename _unit_rhs::ratio>;
56  return _resulting_unit<typename _unit_lhs::internal_type, resulting_ratio>(
57  lhs.value() * rhs.value());
58 }
59 
60 } // namespace SI::detail
Namespace containing implementation details for SI.
Definition: acceleration.h:34
constexpr auto cross_unit_divide(const _unit_lhs &lhs, const _unit_rhs &rhs)
Definition: cross_unit_operations.h:27
constexpr auto cross_unit_multiply(const _unit_lhs &lhs, const _unit_rhs &rhs)
Definition: cross_unit_operations.h:47