Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
quantity_unit.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#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_UNITS_QUANTITY_UNIT_HPP_
5#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_UNITS_QUANTITY_UNIT_HPP_
6
8#include "arene/base/stdlib_choice/enable_if.hpp"
9#include "arene/base/units/detail/missing.hpp"
12
13namespace arene {
14namespace base {
15
16namespace quantity_unit_detail {
17
18/// @brief implementation class for a quantity kind with a rebound unit
19/// @tparam Kind quantity kind to rebind
20/// @tparam Unit the unit type to rebind with
21template <typename Kind, typename Unit>
22class quantity_kind_with_rebound_unit
23 : public quantity_kind<quantity_kind_with_rebound_unit<Kind, Unit>, Kind, Unit> {};
24
25} // namespace quantity_unit_detail
26
27/// @brief Base class for declaring a quantity unit
28/// @tparam Tag the derived class which represents the quantity unit
29/// @tparam Kind The quantity kind for which this is a unit
30///
31/// @pre @c Tag must derive from @c quantity_unit<Tag>
32template <typename Tag, typename Kind>
34 : public quantity_kind_detail::quantity_kind_base<Tag, Kind, units_detail::missing, units_detail::missing> {
35 // parasoft-begin-suppress AUTOSAR-A11_3_1-a-2 "Use of friend permitted for hidden friend idiom by A11-3-1 Permit #2
36 // v1.0.0"
37 //
38 // parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: cannot apply static to a hidden friend function"
39 // parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: rule does not mention naming all parameters"
40
41 /// @brief helper used to rebind the unit type of a quantity kind
42 /// @tparam OtherDerived derived quantity kind type to rebind
43 /// @tparam OtherParentKind parent kind of the quantity type to rebind
44 /// @tparam OtherUnit unit of the quantity type to rebind
45 /// @return different quantity kind with the unit specified to be @c Tag
46 /// @note Requires @c is_possible_unit_for<Tag, OtherDerived> to be @c true
47 template <
48 typename OtherDerived,
49 typename OtherParentKind,
50 typename OtherOrigin,
51 typename OtherUnit,
53 friend auto
54 rebind_quantity_kind_unit_type(quantity_kind_detail::quantity_kind_base<OtherDerived, OtherParentKind, OtherOrigin, OtherUnit> const&, Tag const&)
55 -> quantity_unit_detail::quantity_kind_with_rebound_unit<OtherDerived, Tag> {
56 return {};
57 }
58
59 // parasoft-end-suppress AUTOSAR-A11_3_1-a-2
60 // parasoft-end-suppress AUTOSAR-M3_3_2-a
61 // parasoft-end-suppress CERT_C-EXP37-a-3
62
63 public:
64 /// @brief Type alias to indicate the quantity kind for which this is a unit
65 using unit_kind_type = Kind;
66};
67
68} // namespace base
69} // namespace arene
70
71#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_UNITS_QUANTITY_UNIT_HPP_
Base class for declaring a quantity unit.
Definition quantity_unit.hpp:34
combine_kinds_t< unit_kind_t< BaseKinds >... > unit_kind_type
Definition quantity_unit.hpp:65
friend auto rebind_quantity_kind_unit_type(quantity_kind_detail::quantity_kind_base< OtherDerived, OtherParentKind, OtherOrigin, OtherUnit > const &, Tag const &) -> quantity_unit_detail::quantity_kind_with_rebound_unit< OtherDerived, Tag >
helper used to rebind the unit type of a quantity kind
Definition quantity_unit.hpp:54
Definition accumulate.hpp:37
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
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