Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
equal_to.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
5#ifndef INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_EQUAL_TO_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_EQUAL_TO_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 <functional>
12// IWYU pragma: friend "stdlib_detail/.*"
13
14#include "arene/base/compiler_support/diagnostics.hpp"
15#include "stdlib/include/stdlib_detail/forward.hpp"
16
17namespace std {
18
19/// @brief Function object that can be invoked for equality comparisons
20/// @tparam T The type of the values
21/// @note This class contains the member types @c result_type, @c first_argument type, and @c second_argument type.
22/// These aliases have been deprecated in C++17 and removed in C++20.
23template <class T = void>
24class equal_to {
25 public:
26 /// @brief Result type of invoking this object
27 using result_type = bool;
28 /// @brief Type of the first value to compare
29 using first_argument_type = T;
30 /// @brief Type of the second value to compare
31 using second_argument_type = T;
32
33 /// @brief Returns if two values are equal
34 /// @param lhs The first value to compare
35 /// @param rhs The second value to compare
36 /// @return Returns the boolean result of invoking @c operator== on @c lhs and @c rhs
37 constexpr auto operator()(T const& lhs, T const& rhs) const noexcept(noexcept(lhs == rhs)) -> bool {
38 // parasoft-begin-suppress AUTOSAR-M6_2_2-a "The type being compared is up to the user"
39 return lhs == rhs;
40 // parasoft-end-suppress AUTOSAR-M6_2_2-a "The type being compared is up to the user"
41 }
42};
43
44// parasoft-begin-suppress AUTOSAR-A2_10_1-e "False positive: 'equal_to' does not hide anything"
45/// @brief Function object that can be invoked for equality comparisons, specialized for type deduction
46template <>
47class equal_to<void> {
48 public:
49 // parasoft-begin-suppress AUTOSAR-A2_10_1-e "False positive: 'is_transparent' does not hide anything"
50 /// @brief Denotes that this is a transparent function object type
51 using is_transparent = void;
52 // parasoft-end-suppress AUTOSAR-A2_10_1-e
53
54 // parasoft-begin-suppress AUTOSAR-M6_2_2-a "The type being compared is up to the user"
56 ARENE_IGNORE_ALL("-Wfloat-equal", "The type being compared is up to the user");
57 /// @brief Returns if two values are equal with parameter and return type deduced
58 /// @tparam T The type of the first value
59 /// @tparam U The type of the second value
60 /// @param lhs The first value to compare
61 /// @param rhs The second value to compare
62 /// @return Returns the result of invoking @c operator== on @c lhs and @c rhs
63 template <class T, class U>
64 constexpr auto operator()(T&& lhs, U&& rhs) const noexcept(noexcept(std::forward<T>(lhs) == std::forward<U>(rhs)))
65 -> decltype(std::forward<T>(lhs) == std::forward<U>(rhs)) {
66 return std::forward<T>(lhs) == std::forward<U>(rhs);
67 }
69 // parasoft-end-suppress AUTOSAR-M6_2_2-a "The type being compared is up to the user"
70};
71// parasoft-end-suppress AUTOSAR-A2_10_1-e
72
73} // namespace std
74
75#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_EQUAL_TO_HPP_
ARENE_IGNORE_ALL("-Wfloat-equal", "The type being compared is up to the user")
constexpr auto operator()(T &&lhs, U &&rhs) const noexcept(noexcept(std::forward< T >(lhs)==std::forward< U >(rhs))) ->
Returns if two values are equal with parameter and return type deduced.
Definition equal_to.hpp:64
Function object that can be invoked for equality comparisons.
Definition equal_to.hpp:24
constexpr auto operator()(T const &lhs, T const &rhs) const noexcept(noexcept(lhs==rhs)) -> bool
Returns if two values are equal.
Definition equal_to.hpp:37
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