9 #ifndef EAGINE_UNITS_SCALED_UNIT_HPP
10 #define EAGINE_UNITS_SCALED_UNIT_HPP
20 namespace eagine::units {
22 template <
typename Dims,
typename Scales,
typename System>
23 struct scaled_dim_unit_conv {
24 using type = scaled_dim_unit_conv;
26 using _impl = bits::_sc_unit_sc_hlp<Scales, System>;
27 using _ndp = bits::dim_pow<nothing_t, 0>;
30 static constexpr
auto to_base(T v) {
31 return _impl::_hlp(std::true_type(), v, bits::dims<_ndp, Dims>());
35 static constexpr
auto from_base(T v) {
36 return _impl::_hlp(std::false_type(), v, bits::dims<_ndp, Dims>());
41 template <
typename BaseScaledUnit,
typename System>
42 struct make_scaled_base_dim_unit;
44 template <
typename BaseScaledUnit,
typename System>
45 using make_scaled_base_dim_unit_t =
46 typename make_scaled_base_dim_unit<BaseScaledUnit, System>::type;
48 template <
typename Scale,
typename BaseUnit,
typename System>
49 struct make_scaled_base_dim_unit<base::scaled_unit<Scale, BaseUnit>, System>
51 dimension<dimension_of_t<BaseUnit>, 1>,
52 bits::unit_scales<bits::uni_sca<BaseUnit, Scale>, nothing_t>,
55 template <
typename Scale,
typename UnitScales>
56 using add_none_unit_scale_t =
57 bits::unit_scales<bits::uni_sca<nothing_t, Scale>, UnitScales>;
60 template <
typename Scale,
typename Unit>
61 struct make_scaled_unit;
63 template <
typename Scale,
typename Unit>
64 using make_scaled_unit_t =
typename make_scaled_unit<Scale, Unit>::type;
66 template <
typename Scale,
typename Dimension,
typename System>
67 struct make_scaled_unit<Scale, unit<Dimension, System>>
68 : scaled_dim_unit<Dimension, add_none_unit_scale_t<Scale, nothing_t>, System> {
72 template <
typename D,
typename AS,
typename US,
typename System>
74 scaled_dim_unit<D, add_none_unit_scale_t<AS, US>, System>,
77 constexpr
auto operator()(T v)
const {
78 return AS::to_base(v);
82 template <
typename D,
typename AS,
typename US,
typename System>
85 scaled_dim_unit<D, add_none_unit_scale_t<AS, US>, System>> {
87 constexpr
auto operator()(T v)
const {
88 return AS::from_base(v);
92 template <
typename D,
typename AS1,
typename AS2,
typename US,
typename System>
94 scaled_dim_unit<D, add_none_unit_scale_t<AS1, US>, System>,
95 scaled_dim_unit<D, add_none_unit_scale_t<AS2, US>, System>> {
97 constexpr
auto operator()(T v)
const {
98 return AS2::from_base(AS1::to_base(v));
103 template <
typename D,
typename S>
104 struct lit_result<unit<D, S>>
105 : scaled_dim_unit<D, bits::unit_scales<nothing_t, nothing_t>, S> {};
107 template <
typename D1,
typename D2,
typename US1,
typename US2,
typename S>
108 struct mul_l_operand<scaled_dim_unit<D1, US1, S>, scaled_dim_unit<D2, US2, S>>
109 : scaled_dim_unit<D1, bits::merge_t<US1, US2>, S> {};
111 template <
typename D1,
typename D2,
typename US1,
typename US2,
typename S>
112 struct mul_r_operand<scaled_dim_unit<D1, US1, S>, scaled_dim_unit<D2, US2, S>>
113 : scaled_dim_unit<D2, bits::merge_t<US1, US2>, S> {};
115 template <
typename D1,
typename D2,
typename US1,
typename US2,
typename S>
116 struct mul_result<scaled_dim_unit<D1, US1, S>, scaled_dim_unit<D2, US2, S>>
117 : scaled_dim_unit<bits::dim_add_t<D1, D2>, bits::merge_t<US1, US2>, S> {};
119 template <
typename D1,
typename D2,
typename US1,
typename US2,
typename S>
120 struct div_result<scaled_dim_unit<D1, US1, S>, scaled_dim_unit<D2, US2, S>>
121 : scaled_dim_unit<bits::dim_sub_t<D1, D2>, bits::merge_t<US1, US2>, S> {};
125 #endif // EAGINE_UNITS_SCALED_UNIT_HPP