4#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_UNITS_QUANTITY_KIND_HPP_
5#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_UNITS_QUANTITY_KIND_HPP_
8#include "arene/base/stdlib_choice/declval.hpp"
9#include "arene/base/stdlib_choice/enable_if.hpp"
10#include "arene/base/stdlib_choice/is_class.hpp"
11#include "arene/base/stdlib_choice/is_same.hpp"
12#include "arene/base/stdlib_choice/remove_cv.hpp"
14#include "arene/base/units/detail/missing.hpp"
24namespace quantity_kind_detail {
27template <
typename Type>
32auto rebind_quantity_kind_unit_type() ->
void =
delete;
36template <
typename Unit>
37class quantity_kind_unit_mixin {
40 using unit_type = Unit;
45class quantity_kind_unit_mixin<units_detail::missing> {};
49template <
typename Origin>
50class quantity_kind_origin_mixin {
53 using origin = Origin;
58class quantity_kind_origin_mixin<units_detail::missing> {};
62template <
typename ParentKind>
63class quantity_kind_parent_mixin {
66 using parent_quantity_kind_type = ParentKind;
72class quantity_kind_parent_mixin<units_detail::missing> {};
79template <
typename Derived,
typename OptionalParentKind,
typename OptionalOrigin,
typename OptionalUnit>
80class quantity_kind_base
81 :
public quantity_kind_parent_mixin<OptionalParentKind>
82 ,
public quantity_kind_origin_mixin<OptionalOrigin>
83 ,
public quantity_kind_unit_mixin<OptionalUnit> {
86 using quantity_kind_type = Derived;
90 template <units_detail::exponent_t Exponent>
95 template <
typename OtherUnit>
106template <
typename Derived,
typename OptionalParentKind,
typename OptionalOrigin,
typename OptionalUnit>
107class choose_quantity_kind_sanity_check {
110 "The specified parent kind must be a quantity kind"
114 "The specified parent kind must not be a unit"
119 "The specified origin must be a quantity origin"
122 static_assert(is_missing_v<OptionalUnit> ||
is_unit_v<OptionalUnit>,
"The specified unit must be a quantity unit");
124 is_missing_v<OptionalUnit> || units_detail::is_declared_possible_unit_for_v<OptionalUnit, Derived> ||
126 "The specified unit must be a possible unit for the specified kind or for its parent kind"
133template <
typename MaybeParentKind,
typename MaybeDerivedOrigin,
typename = constra
ints<>>
134class derived_origin_impl {
137 using type = units_detail::missing;
143template <
typename MaybeParentKind>
144class derived_origin_impl<
146 units_detail::missing,
147 constraints<std::enable_if_t<quantity_has_origin_v<MaybeParentKind>>>> {
150 using type =
typename MaybeParentKind::origin;
156template <
typename MaybeParentKind,
typename MaybeDerivedOrigin>
157class derived_origin_impl<
163 using type = MaybeDerivedOrigin;
169template <
typename MaybeParentKind,
typename MaybeDerivedOrigin>
170class derived_origin_impl<
175 quantity_origin_detail::origin_is_relative_to_v<MaybeDerivedOrigin, typename MaybeParentKind::origin>,
176 "If the parent of a derived quantity kind has an origin, the derived kind's origin must be relative to it"
181 using type = MaybeDerivedOrigin;
187template <
typename MaybeParentKind,
typename MaybeDerivedOrigin>
188using derived_origin_t =
typename derived_origin_impl<MaybeParentKind, MaybeDerivedOrigin>::type;
197template <
typename Derived,
typename ParentKindOrOriginOrUnit,
typename OriginOrUnit,
typename Unit>
198class choose_quantity_kind_base {
200 using actual_parent = ParentKindOrOriginOrUnit;
203 using actual_origin = OriginOrUnit;
206 using actual_unit = Unit;
210 static constexpr choose_quantity_kind_sanity_check<Derived, actual_parent, actual_origin, actual_unit> check{};
215 using type = quantity_kind_base<Derived, actual_parent, derived_origin_t<actual_parent, actual_origin>, actual_unit>;
225template <
typename Derived,
typename ParentKindOrOrigin,
typename OriginOrUnit>
226class choose_quantity_kind_base<Derived, ParentKindOrOrigin, OriginOrUnit, units_detail::missing> {
229 using missing = units_detail::missing;
246 static constexpr choose_quantity_kind_sanity_check<Derived, actual_parent, actual_origin, actual_unit> check{};
251 using type = quantity_kind_base<Derived, actual_parent, derived_origin_t<actual_parent, actual_origin>, actual_unit>;
261template <
typename Derived,
typename ParentKindOrOriginOrUnit>
262class choose_quantity_kind_base<Derived, ParentKindOrOriginOrUnit, units_detail::missing, units_detail::missing> {
265 using missing = units_detail::missing;
271 ParentKindOrOriginOrUnit,
275 using actual_origin =
283 static constexpr choose_quantity_kind_sanity_check<Derived, actual_parent, actual_origin, actual_unit> check{};
288 using type = quantity_kind_base<Derived, actual_parent, derived_origin_t<actual_parent, actual_origin>, actual_unit>;
298template <
typename Derived>
299class choose_quantity_kind_base<Derived, units_detail::missing, units_detail::missing, units_detail::missing> {
302 using missing = units_detail::missing;
307 using type = quantity_kind_base<Derived, missing, missing, missing>;
324 typename ParentKindOrOriginOrUnit = units_detail::missing,
325 typename OriginOrUnit = units_detail::missing,
326 typename Unit = units_detail::missing>
327using quantity_kind =
typename quantity_kind_detail::choose_quantity_kind_base<
static constexpr value_type value
Definition integral_constant.hpp:34
Definition accumulate.hpp:37
constexpr bool is_possible_unit_for_v
Type trait for detecting if a type is a unit for a specific quantity kind. Evaluates to true if Unit ...
constexpr bool is_quantity_origin_v
Type trait to check if a quantity kind is itself an origin. The value is true if it is,...
typename static_if< B >::template then_else< T, F > conditional_t
lazily select between two types based on a boolean condition
Definition conditional.hpp:28
constexpr bool is_quantity_kind_v
Type trait for detecting a quantity kind. Evaluates to true if the type is a quantity kind,...
typename quantity_kind_detail::choose_quantity_kind_base< Derived, std::remove_cv_t< ParentKindOrOriginOrUnit >, std::remove_cv_t< OriginOrUnit >, std::remove_cv_t< Unit > >::type quantity_kind
ParentKind class for declaring a quantity kind with a parent quantity kind.
Definition quantity_kind.hpp:327
constexpr bool is_unit_v
Type trait for detecting if a type is a unit. Evaluates to true if the type is a unit,...
typename units_detail::kind_with_exponent_helper< std::remove_cv_t< Kind >,(Exponent< 0) ? 0 :Exponent,(Exponent< 0) ? -Exponent :0 >::type kind_with_exponent_t
Alias template for raising the specified quantity kind to the specified exponent.
Definition kind_with_exponent_fwd.hpp:47
typename constraints_impl::constraints< EnableIfs... >::type constraints
Helper used to express template constraints in a consistent way using std::enable_if_t.
Definition constraints.hpp:51
Definition accumulate.hpp:36
typename remove_cv< T >::type remove_cv_t
An alias for T, but with top-level const and/or volatile qualifiers removed.
Definition remove_cv.hpp:64
typename enable_if< Condition, Type >::type enable_if_t
Type alias to support constraining templates. Is an alias for the specified type if the Condition is ...
Definition enable_if.hpp:41
auto declval() noexcept -> T &&
A dummy function that is declared but not defined, with a user-specified return type,...