Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
integral_constant.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_INTEGRAL_CONSTANT_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_INTEGRAL_CONSTANT_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// IWYU pragma: friend "stdlib_detail/.*"
13
14namespace std {
15// parasoft-begin-suppress AUTOSAR-A2_7_3-a "False positive: there is a comment with @brief"
16/// @brief A helper class to represent a compile-time constant with the specified type and value. Instances of the type
17/// are implicitly convertible to the specified type and are nullary-invocable, yielding the specified type. The result
18/// of such a conversion or invocation is the specified value. The @c value member is a constant of the specified type,
19/// holding the specified value.
20/// @tparam Type The type of the value
21/// @tparam Value The value of the constant
22template <typename Type, Type Value>
24 public:
25 // parasoft-begin-suppress AUTOSAR-A2_10_1-e "False positive: identifiers can not hide themselves"
26 /// @brief The type of this class
27 using type = integral_constant;
28 /// @brief The type of the value
29 using value_type = Type;
30
31 // parasoft-begin-suppress CERT_C-STR34-b-2 "False positive: this is generic code and uses exactly the specified type"
32 // parasoft-begin-suppress AUTOSAR-M11_0_1-a-2 "False positive: this is not 'member data', it is a public property"
33 /// @brief The constant
34 static constexpr value_type value{Value};
35 // parasoft-end-suppress AUTOSAR-M11_0_1-a-2
36 // parasoft-end-suppress CERT_C-STR34-b-2
37 // parasoft-end-suppress AUTOSAR-A2_10_1-e
38
39 // parasoft-begin-suppress AUTOSAR-A8_4_2-a CERT_CPP-MSC52-a-2 CERT_C-MSC37-a "False positive: this function returns a
40 // value"
41 // parasoft-begin-suppress AUTOSAR-A13_2_3-a-2 "False positive: Suggested return type is incorrect"
42 // parasoft-begin-suppress AUTOSAR-A13_5_2-a-2 "Implicit conversion to value_type is part of the API"
43 /// @brief Implicit conversion to @c Type
44 /// @return The specified @c Value
45 // NOLINTNEXTLINE(hicpp-explicit-conversions)
46 constexpr operator value_type() const noexcept { return value; }
47 // parasoft-end-suppress AUTOSAR-A13_5_2-a-2
48 // parasoft-end-suppress AUTOSAR-A13_2_3-a-2
49 // parasoft-end-suppress AUTOSAR-A8_4_2-a CERT_CPP-MSC52-a-2 CERT_C-MSC37-a
50
51 // parasoft-begin-suppress AUTOSAR-A8_4_2-a CERT_CPP-MSC52-a-2 CERT_C-MSC37-a "False positive: this function returns a
52 // value"
53 /// @brief Nullary function call operator
54 /// @return The specified @c Value
55 constexpr auto operator()() const noexcept -> value_type { return value; }
56 // parasoft-end-suppress AUTOSAR-A8_4_2-a CERT_CPP-MSC52-a-2 CERT_C-MSC37-a
57};
58// parasoft-end-suppress AUTOSAR-A2_7_3-a
59
60/// @brief Out-of-line definition for the @c value constant
61/// @tparam Type The type of the value
62/// @tparam Value The value of the constant
63template <typename Type, Type Value>
64constexpr Type integral_constant<Type, Value>::value;
65
66// parasoft-begin-suppress AUTOSAR-A2_7_3-a "False positive: there is a comment with @brief"
67
68/// @brief An alias for @c integral_constant<bool,Value>
69/// @tparam Value the value of the constant
70template <bool Value>
71using bool_constant = integral_constant<bool, Value>;
72
73// parasoft-end-suppress AUTOSAR-A2_7_3-a
74
75/// @brief An alias for @c bool_constant<true>
76using true_type = bool_constant<true>;
77
78/// @brief An alias for @c bool_constant<false>
79using false_type = bool_constant<false>;
80
81} // namespace std
82
83#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_INTEGRAL_CONSTANT_HPP_
A helper class to represent a compile-time constant with the specified type and value....
Definition integral_constant.hpp:23
constexpr auto operator()() const noexcept -> value_type
Nullary function call operator.
Definition integral_constant.hpp:55
constexpr operator value_type() const noexcept
Implicit conversion to Type.
Definition integral_constant.hpp:46
static constexpr value_type value
The constant.
Definition integral_constant.hpp:34
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