Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
monostate.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_ARENE_BASE_MONOSTATE_MONOSTATE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MONOSTATE_MONOSTATE_HPP_
7
8// IWYU pragma: private, include "arene/base/monostate.hpp"
9// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
12
13#include "arene/base/compiler_support/attributes.hpp"
14#include "arene/base/stdlib_choice/cstddef.hpp"
15#include "arene/base/stdlib_choice/hash.hpp"
16#include "arene/base/stdlib_choice/is_void.hpp"
17#include "arene/base/type_manipulation/static_if.hpp"
18#include "arene/base/type_traits/give_cv_to.hpp"
19
20// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
21
22// parasoft-begin-suppress AUTOSAR-A7_1_5-a-2 "Trailing return syntax permitted by A7-1-5 Permit #1 v1.0.0"
23
24namespace arene {
25namespace base {
26
27/// @brief A monostate type that is a well-behaved empty value for variants.
28struct monostate {
29 // parasoft-begin-suppress AUTOSAR-A11_3_1-a-2 "False positive: comparison operators are permitted"
30 /// @brief All monostates are equal.
31 /// @return Always returns @c true
32 ARENE_NODISCARD friend constexpr auto operator==(monostate, monostate) noexcept -> bool { return true; }
33
34 /// @brief All monostates are not not equal.
35 /// @return Always returns @c false
36 ARENE_NODISCARD friend constexpr auto operator!=(monostate, monostate) noexcept -> bool { return false; }
37
38 /// @brief A monostate is never less than another monostate.
39 /// @return Always returns @c false
40 ARENE_NODISCARD friend constexpr auto operator<(monostate, monostate) noexcept -> bool { return false; }
41
42 /// @brief A monostate is always less-equal than another monostate as all are equal.
43 /// @return Always returns @c true
44 ARENE_NODISCARD friend constexpr auto operator<=(monostate, monostate) noexcept -> bool { return true; }
45
46 /// @brief A monostate is never greater than another monostate
47 /// @return Always returns @c false
48 ARENE_NODISCARD friend constexpr auto operator>(monostate, monostate) noexcept -> bool { return false; }
49
50 /// @brief A monostate is always greater-equal than another monostate as all are equal
51 /// @return Always returns @c true
52 ARENE_NODISCARD friend constexpr auto operator>=(monostate, monostate) noexcept -> bool { return true; }
53 // parasoft-end-suppress AUTOSAR-A11_3_1-a-2
54};
55
56/// @brief A metafunction that is an identity for all types except for void types.
57/// @details In the case of a void type, this results in @c arene::base::monostate with the same cv-qualifiers.
58/// @tparam T The parameter type.
59template <class T>
62
63} // namespace base
64} // namespace arene
65
66// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "False positive: specialization of standard templates is permitted"
67// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "False positive: specialization of standard templates is permitted"
68namespace std {
69// parasoft-begin-suppress AUTOSAR-A11_0_2-a-2 "False positive: must follow the primary template"
70/// @brief Implementation of std::hash for arene::base::monostate.
71template <>
72struct hash<arene::base::monostate> {
73 /// @brief The result type.
74 using result_type = std::size_t;
75 /// @brief The argument type.
76 using argument_type = arene::base::monostate;
77
78 /// @brief Compute the hash of a monostate instance.
79 /// @return The hash of a monostate instance.
80 constexpr auto operator()(arene::base::monostate const&) const noexcept -> std::size_t {
81 constexpr std::size_t monostate_hash{0xEF0B0666}; // an arbitrary constant
82 return monostate_hash;
83 }
84};
85// parasoft-end-suppress AUTOSAR-A11_0_2-a-2
86} // namespace std
87// parasoft-end-suppress CERT_CPP-DCL58-a-2
88// parasoft-end-suppress AUTOSAR-A17_6_1-a-2
89
90#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MONOSTATE_MONOSTATE_HPP_
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10
A monostate type that is a well-behaved empty value for variants.
Definition monostate.hpp:28
ARENE_NODISCARD friend constexpr auto operator==(monostate, monostate) noexcept -> bool
All monostates are equal.
Definition monostate.hpp:32
ARENE_NODISCARD friend constexpr auto operator<(monostate, monostate) noexcept -> bool
A monostate is never less than another monostate.
Definition monostate.hpp:40
ARENE_NODISCARD friend constexpr auto operator!=(monostate, monostate) noexcept -> bool
All monostates are not not equal.
Definition monostate.hpp:36
ARENE_NODISCARD friend constexpr auto operator<=(monostate, monostate) noexcept -> bool
A monostate is always less-equal than another monostate as all are equal.
Definition monostate.hpp:44
ARENE_NODISCARD friend constexpr auto operator>=(monostate, monostate) noexcept -> bool
A monostate is always greater-equal than another monostate as all are equal.
Definition monostate.hpp:52
ARENE_NODISCARD friend constexpr auto operator>(monostate, monostate) noexcept -> bool
A monostate is never greater than another monostate.
Definition monostate.hpp:48
constexpr auto operator()(arene::base::monostate const &) const noexcept -> std::size_t
Compute the hash of a monostate instance.
Definition monostate.hpp:80
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