Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
conditional.hpp
Go to the documentation of this file.
1// Copyright 2024, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_CONDITIONAL_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_CONDITIONAL_HPP_
7
8// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
9// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
10
11// IWYU pragma: private, include <type_traits>
12
13namespace std {
14
15/// @brief Helper template for selecting types based on a condition. If the supplied @c Condition is @c true then the
16/// nested @c type member is an alias for @c TrueType otherwise it is an alias for @c FalseType
17/// @tparam Condition The condition
18/// @tparam TrueType The type to use if the condition is @c true
19/// @tparam FalseType The type to use if the condition is @c false
20template <bool Condition, typename TrueType, typename FalseType>
22 public:
23 /// @brief The selected type
24 using type = FalseType;
25};
26
27// parasoft-begin-suppress AUTOSAR-A14_7_2-a-2 "False positive: All
28// 'conditional' specializations are declared in the same files as the
29// primary template"
30
31// parasoft-begin-suppress AUTOSAR-A2_7_3-a "False positive: all declarations
32// and typedefs *are* preceded by a comment with @brief"
33
34/// @brief Helper template for selecting types based on a condition. If the supplied @c Condition is @c true then the
35/// nested @c type member is an alias for @c TrueType otherwise it is an alias for @c FalseType
36///
37/// This specialization handles the case that the condition is @c true
38/// @tparam TrueType The type to use if the condition is @c true
39/// @tparam FalseType The type to use if the condition is @c false
40template <typename TrueType, typename FalseType>
41class conditional<true, TrueType, FalseType> {
42 public:
43 /// @brief The selected type
44 using type = TrueType;
45};
46
47// parasoft-end-suppress AUTOSAR-A2_7_3-a
48// parasoft-end-suppress AUTOSAR-A14_7_2-a-2
49
50// parasoft-begin-suppress AUTOSAR-A2_7_3-a "False positive: the typedef *is* preceded by a comment with @brief"
51/// @brief Helper template alias for selecting types based on a condition. If the supplied @c Condition is @c true then
52/// it is an alias for @c TrueType otherwise it is an alias for @c FalseType
53/// @tparam Condition The condition
54/// @tparam TrueType The type to use if the condition is @c true
55/// @tparam FalseType The type to use if the condition is @c false
56template <bool Condition, typename TrueType, typename FalseType>
57using conditional_t = typename conditional<Condition, TrueType, FalseType>::type;
58// parasoft-end-suppress AUTOSAR-A2_7_3-a
59
60} // namespace std
61
62#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_CONDITIONAL_HPP_
Helper template for selecting types based on a condition. If the supplied Condition is true then the ...
Definition conditional.hpp:21
constexpr auto operator()(::arene::base::result< void, E > const &value) const noexcept(noexcept(hash< E >{}(std::declval< E const & >()))) -> std::size_t
Calculate the hash of a result.
Definition result.hpp:1827