Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
selected_unit_for.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_SELECTED_UNIT_FOR_HPP_
5#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_UNITS_SELECTED_UNIT_FOR_HPP_
6
7#include "arene/base/constraints/constraints.hpp"
8#include "arene/base/stdlib_choice/enable_if.hpp"
9#include "arene/base/stdlib_choice/remove_cv.hpp"
10#include "arene/base/units/has_explicit_units.hpp"
11#include "arene/base/units/has_parent_kind.hpp"
12#include "arene/base/units/is_quantity_kind.hpp"
13#include "arene/base/units/is_unit.hpp"
14
15namespace arene {
16namespace base {
17
18namespace selected_unit_for_detail {
19/// @brief Type trait for determining the unit for a quantity kind. If there is a unit for a given kind, then the @c
20/// type member is a type alias for the unit type. Otherwise, the @c type member is not present.
21/// @tparam Kind the type to check
22template <typename Kind, typename = constraints<>>
23struct selected_unit_for_impl;
24
25/// @brief Type trait for determining the unit for a quantity kind. If there is a unit for a given kind, then the @c
26/// type member is a type alias for the unit type. Otherwise, the @c type member is not present.
27/// @tparam Kind the type to check
28template <typename Kind>
29struct selected_unit_for_impl<Kind, constraints<std::enable_if_t<is_unit_v<Kind>>>> {
30 /// @brief A type alias for the unit type for @c Kind
31 using type = Kind;
32};
33
34/// @brief Type trait for determining the unit for a quantity kind. If there is a unit for a given kind, then the @c
35/// type member is a type alias for the unit type. Otherwise, the @c type member is not present.
36/// @tparam Kind the type to check
37template <typename Kind>
38struct selected_unit_for_impl<
39 Kind,
40 constraints<
41 std::enable_if_t<!is_unit_v<Kind>>,
42 std::enable_if_t<is_quantity_kind_v<Kind>>,
43 std::enable_if_t<units_detail::has_explicit_units_v<Kind>>>> {
44 /// @brief A type alias for the unit type for @c Kind
45 using type = typename Kind::unit_type;
46};
47
48/// @brief Type trait for determining the unit for a quantity kind. If there is a unit for a given kind, then the @c
49/// type member is a type alias for the unit type. Otherwise, the @c type member is not present.
50/// @tparam Kind the type to check
51template <typename Kind>
52struct selected_unit_for_impl<
53 Kind,
54 constraints<
55 std::enable_if_t<!is_unit_v<Kind>>,
56 std::enable_if_t<is_quantity_kind_v<Kind>>,
57 std::enable_if_t<!units_detail::has_explicit_units_v<Kind>>,
58 std::enable_if_t<units_detail::has_parent_kind_v<Kind>>>> {
59 /// @brief A type alias for the unit type for @c Kind
60 using type = typename selected_unit_for_impl<typename Kind::parent_quantity_kind_type>::type;
61};
62
63} // namespace selected_unit_for_detail
64
65/// @brief Type trait for determining the unit for a quantity kind. If there is a unit for a given kind, then it is a
66/// type alias for the unit type. Otherwise, it is undefined.
67/// @tparam Kind the type to check
68template <typename Kind>
70
71/// @brief Type trait for determining if the given quantity kind has a unit selected. It is @c true if a unit
72/// is selected, @c false otherwise
73/// @tparam Kind the quantity kind to check
74template <typename Kind, typename = arene::base::constraints<>>
75extern constexpr bool has_selected_unit_v = false;
76
77/// @brief Type trait for determining if the given quantity kind has a unit selected. It is @c true if a unit
78/// is selected, @c false otherwise
79/// @tparam Kind the quantity kind to check
80template <typename Kind>
81extern constexpr bool has_selected_unit_v<Kind, arene::base::constraints<selected_unit_for_t<Kind>>> = true;
82
83} // namespace base
84} // namespace arene
85
86#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_UNITS_SELECTED_UNIT_FOR_HPP_
Definition array_exceptions_disabled.cpp:11
constexpr bool has_selected_unit_v
Type trait for determining if the given quantity kind has a unit selected. It is true if a unit is se...
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10