Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
is_possible_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_IS_POSSIBLE_UNIT_FOR_HPP_
5#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_UNITS_IS_POSSIBLE_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/is_same.hpp"
10#include "arene/base/units/has_parent_kind.hpp"
11#include "arene/base/units/is_quantity_kind.hpp"
12#include "arene/base/units/is_unit.hpp"
13
14namespace arene {
15namespace base {
16
17namespace units_detail {
18/// @brief Type trait for detecting if a type is explicitly declared to be applicable for a specific quantity
19/// kind. Evaluates to @c true if @c Unit is a unit for @c Kind, @c false otherwise
20/// @tparam Unit the type to check
21/// @tparam Kind the type to check if the type is a unit for
22template <typename Unit, typename Kind, typename = constraints<>>
23extern constexpr bool is_declared_possible_unit_for_v = false;
24
25/// @brief Type trait for detecting if a type is explicitly declared to be applicable for a specific quantity kind.
26/// Evaluates to @c true if @c Unit is a unit for @c Kind, @c false otherwise
27/// @tparam Unit the type to check
28/// @tparam Kind the type to check if the type is a unit for
29template <typename Unit, typename Kind>
30extern constexpr bool is_declared_possible_unit_for_v<
31 Unit,
32 Kind,
33 constraints<std::enable_if_t<std::is_same<Kind, typename Unit::unit_kind_type>::value>>> = true;
34} // namespace units_detail
35
36namespace is_possible_unit_for_detail {
37
38/// @brief Type trait for detecting if a type is a unit for a specific quantity kind. Evaluates to @c true if @c Unit
39/// is a unit for @c Kind, @c false otherwise
40/// @tparam Unit the type to check
41/// @tparam Kind the type to check if the type is a unit for
42template <typename Unit, typename Kind, typename = constraints<>>
43extern constexpr bool is_possible_unit_for_v = false;
44
45/// @brief Type trait for detecting if a type is a unit for a specific quantity kind. Evaluates to @c true if @c Unit
46/// is a unit for @c Kind, @c false otherwise
47/// @tparam Unit the type to check
48/// @tparam Kind the type to check if the type is a unit for
49template <typename Unit, typename Kind>
50extern constexpr bool is_possible_unit_for_v<
51 Unit,
52 Kind,
53 constraints<std::enable_if_t<units_detail::is_declared_possible_unit_for_v<Unit, Kind>>>> =
54 is_quantity_kind_v<Unit>;
55
56/// @brief Type trait for detecting if a type is a unit for a specific quantity kind. Evaluates to @c true if @c Unit
57/// is a unit for @c Kind, @c false otherwise
58/// @tparam Unit the type to check
59/// @tparam Kind the type to check if the type is a unit for
60template <typename Unit, typename Kind>
61extern constexpr bool is_possible_unit_for_v<
62 Unit,
63 Kind,
64 constraints<
65 std::enable_if_t<!units_detail::is_declared_possible_unit_for_v<Unit, Kind>>,
66 std::enable_if_t<!is_unit_v<typename Unit::unit_kind_type>>,
67 std::enable_if_t<units_detail::has_parent_kind_v<Kind>>>> =
68 is_quantity_kind_v<Unit> && is_possible_unit_for_v<Unit, typename Kind::parent_quantity_kind_type>;
69
70/// @brief Type trait for detecting if a type is a unit for a specific quantity kind. Evaluates to @c true if @c Unit
71/// is a unit for @c Kind, @c false otherwise
72/// @tparam Unit the type to check
73/// @tparam Kind the type to check if the type is a unit for
74template <typename Unit, typename Kind>
75extern constexpr bool is_possible_unit_for_v<
76 Unit,
77 Kind,
78 constraints<
79 std::enable_if_t<!units_detail::is_declared_possible_unit_for_v<Unit, Kind>>,
80 std::enable_if_t<is_unit_v<typename Unit::unit_kind_type>>>> =
81 is_possible_unit_for_v<typename Unit::unit_kind_type, Kind>;
82
83} // namespace is_possible_unit_for_detail
84
85/// @brief Type trait for detecting if a type is a unit for a specific quantity kind. Evaluates to @c true if @c
86/// Unit is a unit for @c Kind, @c false otherwise
87/// @tparam Unit the type to check
88/// @tparam Kind the type to check if the type is a unit for
89template <typename Unit, typename Kind>
91
92} // namespace base
93} // namespace arene
94
95#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_UNITS_IS_POSSIBLE_UNIT_FOR_HPP_
Definition array_exceptions_disabled.cpp:11
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 ...
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10