Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
explicit_base_set.hpp
Go to the documentation of this file.
1// Copyright 2026, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5// parasoft-begin-suppress AUTOSAR-A2_8_1-a "False positive: also defines arene::base::units_detail::explicit_base_set"
6#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_UNITS_EXPLICIT_BASE_SET_HPP_
7#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_UNITS_EXPLICIT_BASE_SET_HPP_
8
10#include "arene/base/stdlib_choice/cstddef.hpp"
11#include "arene/base/stdlib_choice/enable_if.hpp"
12#include "arene/base/stdlib_choice/remove_const.hpp"
13#include "arene/base/stdlib_choice/remove_cv.hpp"
21
22// parasoft-begin-suppress AUTOSAR-A7_1_5-a-2 "Trailing return syntax permitted by A7-1-5 Permit #1 v1.0.0"
23// parasoft-begin-suppress AUTOSAR-A3_1_5-a "False positive: all functions are constexpr so are intended to be inlined"
24// parasoft-begin-suppress AUTOSAR-M2_10_1-a "Similar identifiers permitted by M2-10-1 Permit #1 v1.0.0"
25
26namespace arene {
27namespace base {
28
29namespace combine_kinds_detail {
30/// @brief A template that represents a quantity kind that is a combination of base quantity kinds
31/// @tparam BaseKinds The base quantity kinds to combine
32template <typename... BaseKinds>
33class combined_quantity_kind;
34} // namespace combine_kinds_detail
35
36namespace units_detail {
37
38/// @brief provide a barrier type to treat a quantity kind as explicit
39/// @tparam Kind quantity kind type
40///
41/// Creates a quantity kind barrier, blocking rules for implicit kinds when
42/// determining the explicit base set.
43template <typename Kind>
44class explicit_base_barrier : public quantity_kind<explicit_base_barrier<Kind>> {};
45
46namespace explicit_base_set_detail {
47
48/// @brief helper used to denote that the explicit base set cannot be determined
49/// for the specified type
50/// @tparam Kind quantity kind of which to obtain the explicit base set
51/// @return never actually returns as use of this function is always a
52/// compilation error.
53template <typename Kind>
54constexpr auto explicit_base_set_error() -> std::nullptr_t {
55 static_assert( //
57 "explicit base set cannot be determined for invalid quantity kind"
58 );
59 static_assert(
61 "internal error: a valid quantity kind was sorted to the explicit_base_set_error function by mistake"
62 );
63 return {};
64}
65
66/// @brief obtains the explicit base set of a quantity kind
67/// @tparam Kind quantity kind of which to obtain the explicit base set
68///
69/// This primary template is always an error.
70template <typename Kind, typename = constraints<>>
71extern constexpr auto explicit_base_set = explicit_base_set_error<Kind>();
72
73/// @brief obtains the explicit base set of a quantity kind
74/// @tparam Kind quantity kind of which to obtain the explicit base set
75///
76/// This specialization handles an explicit quantity kind.
77template <typename Kind>
78extern constexpr auto explicit_base_set<Kind, constraints<std::enable_if_t<is_explicit_v<Kind>>>> =
79 base_kind_set<Kind>{base_kind_exponents{1U, 0U}};
80
81// scaled unit not yet handled
82
83/// @brief obtains the explicit base set of a quantity kind
84/// @tparam Kind quantity kind of which to obtain the explicit base set
85///
86/// This specialization handles an quantity kind with exponent.
87template <typename Kind, exponent_t PositiveExponent, exponent_t NegativeExponent>
88extern constexpr auto
89 explicit_base_set<quantity_kind_with_exponent<Kind, PositiveExponent, NegativeExponent, constraints<>>> = //
90 set_union( //
91 PositiveExponent * explicit_base_set<typename Kind::quantity_kind_type>, //
92 -NegativeExponent* explicit_base_set<typename Kind::quantity_kind_type> //
93 );
94
95/// @brief obtains the explicit base set of a quantity kind
96/// @tparam Kind quantity kind of which to obtain the explicit base set
97///
98/// This specialization handles a combined quantity kind.
99template <typename... BaseKinds>
100extern constexpr auto explicit_base_set<combine_kinds_detail::combined_quantity_kind<BaseKinds...>> =
101 set_union(explicit_base_set<BaseKinds>...);
102
103/// @brief obtains the explicit base set of a quantity kind
104/// @tparam BaseUnit the base unit for the scaled unit
105/// @tparam Scale the scale factor for the scaled unit
106///
107/// This specialization handles a scaled quantity kind.
108template <typename BaseUnit, typename Scale>
109extern constexpr auto explicit_base_set<scaled_unit_detail::scaled_unit_impl<BaseUnit, Scale>> =
110 explicit_base_set<BaseUnit>;
111
112} // namespace explicit_base_set_detail
113
114/// @brief obtains the explicit base set of a quantity kind
115/// @tparam Kind quantity kind of which to obtain the explicit base set
116///
117/// Obtains a set of elements specifying the explicit base set of a quantity
118/// kind. Each set element is a triple of <c>(Kind, PositiveExponent,
119/// NegativeExponent)</c>.
120///
121/// * If @c Kind is an explicit quantity kind, this set is <c>{(Kind, 1,
122/// 0)}</c>.
123/// * otherwise, if @c Kind is a scaled unit, this set is the explict base set
124/// for the base unit of @c Kind.
125/// * otherwise, if @c Kind is a composite quantity kind consisting of @c I
126/// quantity kinds @c Ki with explicit base sets @c E(K_ij) equal to <c>{(K_ij,
127/// P_ij, N_ij)}</c>, then the explicit base set of @c Kind is the set <c>{(K_n,
128/// P_n, N_n)}</c> where the quantity kinds @c K_n are the distinct quantity
129/// kinds from @c K_ij, and @c P_n is the sum of the corresponding positive
130/// exponents <c>P_i * P_ij + N_i * N_ij</c>, @c N_n is the sum of the
131/// corresponding negative exponents <c>N_i * P_ij + P_i * N_ij</c>, where
132/// @c P_i and @c N_i are the positive and negative exponents of @c K_i
133/// * otherwise, there is an error.
134///
135template <typename Kind>
136extern constexpr auto explicit_base_set = explicit_base_set_detail::explicit_base_set<std::remove_cv_t<Kind>>;
137
138/// @brief trait to obtain the type of the explicit base set of a quantity kind
139/// @tparam Kind quantity kind of which to obtain the explicit base set
140template <typename Kind>
141using explicit_base_set_t = std::remove_const_t<decltype(explicit_base_set<Kind>)>;
142
143} // namespace units_detail
144
145} // namespace base
146} // namespace arene
147
148#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_UNITS_EXPLICIT_BASE_SET_HPP_
Definition accumulate.hpp:37
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 always_false_v
A trait which always is false, as a type-dependent expression.
Definition always_false.hpp:25
Definition accumulate.hpp:36
typedef nullptr_t
The type of nullptr.
Definition cstddef.hpp:33
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