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.
operator_helpers.h
Go to the documentation of this file.
1 
12 #pragma once
13 
14 #include "cross_unit_operations.h"
15 #include "detail.h"
16 
22 #define BUILD_UNIT_FROM_DIVISION(RESULTING_UNIT_T, DIVIDEND_UNIT_T, \
23  DIVISOR_UNIT_T) \
24  template <typename _type, typename _ratio_lhs, typename _type_rhs, \
25  typename _ratio_rhs> \
26  constexpr auto operator/(const DIVIDEND_UNIT_T<_type, _ratio_lhs> &lhs, \
27  const DIVISOR_UNIT_T<_type_rhs, _ratio_rhs> &rhs) { \
28  return detail::cross_unit_divide<RESULTING_UNIT_T>(lhs, rhs); \
29  } \
30  \
31  template <typename _type, typename _ratio_lhs, typename _type_rhs, \
32  typename _ratio_rhs> \
33  constexpr auto operator*(const RESULTING_UNIT_T<_type, _ratio_lhs> &lhs, \
34  const DIVISOR_UNIT_T<_type_rhs, _ratio_rhs> &rhs) { \
35  return detail::cross_unit_multiply<DIVIDEND_UNIT_T>(lhs, rhs); \
36  } \
37  \
38  template <typename _type, typename _ratio_lhs, typename _type_rhs, \
39  typename _ratio_rhs> \
40  constexpr auto operator*( \
41  const DIVISOR_UNIT_T<_type, _ratio_lhs> &lhs, \
42  const RESULTING_UNIT_T<_type_rhs, _ratio_rhs> &rhs) { \
43  return rhs * lhs; \
44  } \
45  \
46  template <typename _type, typename _ratio_lhs, typename _type_rhs, \
47  typename _ratio_rhs> \
48  constexpr auto operator/( \
49  const DIVIDEND_UNIT_T<_type, _ratio_lhs> &lhs, \
50  const RESULTING_UNIT_T<_type_rhs, _ratio_rhs> &rhs) { \
51  return detail::cross_unit_divide<DIVISOR_UNIT_T>(lhs, rhs); \
52  }
53 
54 #define BUILD_UNIT_FROM_MULTIPLICATION(RESULTING_UNIT, UNIT_LHS, UNIT_RHS) \
55  \
56  template <typename _type, typename _ratio_lhs, typename _type_rhs, \
57  typename _ratio_rhs> \
58  constexpr auto operator*(const UNIT_LHS<_type, _ratio_lhs> &lhs, \
59  const UNIT_RHS<_type_rhs, _ratio_rhs> &rhs) { \
60  \
61  return detail::cross_unit_multiply<RESULTING_UNIT>(lhs, rhs); \
62  } \
63  \
64  template <typename _type, typename _ratio_lhs, typename _type_rhs, \
65  typename _ratio_rhs> \
66  constexpr auto operator*(const UNIT_RHS<_type, _ratio_lhs> &lhs, \
67  const UNIT_LHS<_type_rhs, _ratio_rhs> &rhs) { \
68  return rhs * lhs; \
69  } \
70  \
71  template <typename _type, typename _ratio_lhs, typename _type_rhs, \
72  typename _ratio_rhs> \
73  constexpr auto operator/(const RESULTING_UNIT<_type, _ratio_lhs> &lhs, \
74  const UNIT_LHS<_type_rhs, _ratio_rhs> &rhs) { \
75  return detail::cross_unit_divide<UNIT_RHS>(lhs, rhs); \
76  } \
77  \
78  template <typename _type, typename _ratio_lhs, typename _type_rhs, \
79  typename _ratio_rhs> \
80  constexpr auto operator/(const RESULTING_UNIT<_type, _ratio_lhs> &lhs, \
81  const UNIT_RHS<_type_rhs, _ratio_rhs> &rhs) { \
82  return detail::cross_unit_divide<UNIT_LHS>(lhs, rhs); \
83  }