5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_UNITS_BASE_KIND_SET_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_UNITS_BASE_KIND_SET_HPP_
12#include "arene/base/stdlib_choice/multiplies.hpp"
13#include "arene/base/stdlib_choice/remove_const.hpp"
30namespace units_detail {
33class base_kind_exponents {
46 constexpr base_kind_exponents(exponent_t pos, exponent_t neg) noexcept
54 constexpr base_kind_exponents() noexcept
55 : base_kind_exponents{0, 0} {}
59 constexpr auto positive() const noexcept -> exponent_t {
return positive_; }
63 constexpr auto negative() const noexcept -> exponent_t {
return negative_; }
72 friend constexpr auto operator*(exponent_t
const scaling, base_kind_exponents
const self)
noexcept
73 -> base_kind_exponents {
75 return {-scaling * self.negative(), -scaling * self.positive()};
78 return {scaling * self.positive(), scaling * self.negative()};
88 constexpr auto operator+=(base_kind_exponents
const other)
noexcept -> base_kind_exponents& {
89 positive_ += other.positive();
90 negative_ += other.negative();
98template <
typename... Kinds>
109 arene::base::array<base_kind_exponents,
sizeof...(Kinds)> exponents{};
121 friend constexpr auto operator*(exponent_t
const scaling, base_kind_set
const& self)
noexcept -> base_kind_set {
122 auto updated = base_kind_set{};
123 arene::base::transform(
124 self.exponents.begin(),
125 self.exponents.end(),
126 updated.exponents.begin(),
127 bind_front(std::multiplies<>{}, scaling)
138 template <
typename Kind>
139 constexpr auto exponent_for() noexcept -> base_kind_exponents& {
146 template <
typename Kind>
147 constexpr auto exponent_for() const noexcept -> base_kind_exponents const& {
160 template <
typename... OtherKinds>
161 constexpr auto add_exponents_from(base_kind_set<OtherKinds...>
const& other)
noexcept -> base_kind_set& {
163 consume_values({(exponent_for<OtherKinds>() += other.template exponent_for<OtherKinds>(),
true)...});
175template <
typename... Bases>
179 "every type in 'Bases' must be a base kind set"
195template <
typename BaseKindSetConstant>
196class as_list_of_kinds_with_exponents {
201 "'BaseKindSetConstant::value' must be a 'base_kind_set'"
208 template <
typename... BaseKinds>
209 static auto impl(base_kind_set<BaseKinds...>) -> type_list<quantity_kind_with_exponent<
211 BaseKindSetConstant::value.template exponent_for<BaseKinds>().positive(),
212 BaseKindSetConstant::value.template exponent_for<BaseKinds>().negative()>...>;
216 using type =
decltype(impl(BaseKindSetConstant::value));
224template <
typename BaseKindSetConstant>
225using as_list_of_kinds_with_exponents_t =
typename as_list_of_kinds_with_exponents<BaseKindSetConstant>::type;
#define ARENE_PRECONDITION(condition)
Check that a precondition holds, and terminate the application if it does not.
Definition contract.hpp:150
arene::base::type_lists::remove_duplicates_t< arene::base::type_lists::concat_t< Ls... > > concat_unique_t
Concatenate multiple lists together with duplicate types removed.
Definition concat_unique.hpp:21
Definition accumulate.hpp:37
constexpr bool is_instantiation_of_v
Definition is_instantiation_of.hpp:16
constexpr void consume_values(std::initializer_list< consume_values_detail::anything > const &) noexcept
Consume a list of values and discard them. Must be called with an extra pair of braces around the exp...
Definition consume_values.hpp:73
constexpr bool all_of_v
Trait which tests if every value in a parameter pack is true .
constexpr auto get(array< T, N > &arr) noexcept -> T &
Get a reference to the element at the specified index in the array.
Definition array.hpp:885
Definition accumulate.hpp:36
typename remove_const< Type >::type remove_const_t
remove const from the provided type. An alias for the modified type.
Definition remove_const.hpp:36
Provides the all_of_v<bool...> trait.