1#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_UNITS_BASE_KIND_SET_HPP_
2#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_UNITS_BASE_KIND_SET_HPP_
4#include "arene/base/algorithm/transform.hpp"
5#include "arene/base/array/array.hpp"
6#include "arene/base/contracts/contract.hpp"
7#include "arene/base/functional/bind_front.hpp"
8#include "arene/base/stdlib_choice/multiplies.hpp"
9#include "arene/base/stdlib_choice/remove_const.hpp"
10#include "arene/base/type_list/concat_unique.hpp"
11#include "arene/base/type_list/index_of.hpp"
12#include "arene/base/type_list/type_list.hpp"
13#include "arene/base/type_manipulation/consume_values.hpp"
14#include "arene/base/type_traits/all_of.hpp"
15#include "arene/base/type_traits/is_instantiation_of.hpp"
16#include "arene/base/units/is_quantity_kind.hpp"
17#include "arene/base/units/kind_with_exponent_fwd.hpp"
26namespace units_detail {
29class base_kind_exponents {
42 constexpr base_kind_exponents(exponent_t pos, exponent_t neg)
noexcept
45 ARENE_PRECONDITION(pos >= 0);
46 ARENE_PRECONDITION(neg >= 0);
50 constexpr base_kind_exponents()
noexcept
51 : base_kind_exponents{0, 0} {}
55 constexpr auto positive()
const noexcept -> exponent_t {
return positive_; }
59 constexpr auto negative()
const noexcept -> exponent_t {
return negative_; }
68 friend constexpr auto operator*(exponent_t
const scaling, base_kind_exponents
const self)
noexcept
69 -> base_kind_exponents {
71 return {-scaling * self.negative(), -scaling * self.positive()};
74 return {scaling * self.positive(), scaling * self.negative()};
84 constexpr auto operator+=(base_kind_exponents
const other)
noexcept -> base_kind_exponents& {
85 positive_ += other.positive();
86 negative_ += other.negative();
94template <
typename... Kinds>
97 static_assert(all_of_v<is_quantity_kind_v<Kinds>...>,
"every type in 'Kinds' must be a quantity kind");
105 arene::base::array<base_kind_exponents,
sizeof...(Kinds)> exponents{};
117 friend constexpr auto operator*(exponent_t
const scaling, base_kind_set
const& self)
noexcept -> base_kind_set {
118 auto updated = base_kind_set{};
119 arene::base::transform(
120 self.exponents.begin(),
121 self.exponents.end(),
122 updated.exponents.begin(),
123 bind_front(std::multiplies<>{}, scaling)
134 template <
typename Kind>
135 constexpr auto exponent_for()
noexcept -> base_kind_exponents& {
136 return get<type_lists::index_of_v<base_kind_set, Kind>>(exponents);
142 template <
typename Kind>
143 constexpr auto exponent_for()
const noexcept -> base_kind_exponents
const& {
144 return get<type_lists::index_of_v<base_kind_set, Kind>>(exponents);
156 template <
typename... OtherKinds>
157 constexpr auto add_exponents_from(base_kind_set<OtherKinds...>
const& other)
noexcept -> base_kind_set& {
159 consume_values({(exponent_for<OtherKinds>() += other.
template exponent_for<OtherKinds>(),
true)...});
171template <
typename... Bases>
172constexpr auto set_union(Bases
const&... bases)
noexcept -> type_lists::concat_unique_t<Bases...> {
174 all_of_v<is_instantiation_of_v<Bases, base_kind_set>...>,
175 "every type in 'Bases' must be a base kind set"
178 auto combined = type_lists::concat_unique_t<Bases...>{};
181 consume_values({(combined.add_exponents_from(bases),
true)...});
191template <
typename BaseKindSetConstant>
192class as_list_of_kinds_with_exponents {
196 is_instantiation_of_v<std::remove_const_t<
decltype(BaseKindSetConstant::value)>, base_kind_set>,
197 "'BaseKindSetConstant::value' must be a 'base_kind_set'"
204 template <
typename... BaseKinds>
205 static auto impl(base_kind_set<BaseKinds...>) -> type_list<quantity_kind_with_exponent<
207 BaseKindSetConstant::value.
template exponent_for<BaseKinds>().positive(),
208 BaseKindSetConstant::value.
template exponent_for<BaseKinds>().negative()>...>;
212 using type =
decltype(impl(BaseKindSetConstant::value));
220template <
typename BaseKindSetConstant>
221using as_list_of_kinds_with_exponents_t =
typename as_list_of_kinds_with_exponents<BaseKindSetConstant>::type;
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10