Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
less.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_LESS_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_LESS_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/constraints.hpp"
15#include "stdlib/include/stdlib_detail/cstddef.hpp"
16#include "stdlib/include/stdlib_detail/decay.hpp"
17#include "stdlib/include/stdlib_detail/enable_if.hpp"
18#include "stdlib/include/stdlib_detail/forward.hpp"
19#include "stdlib/include/stdlib_detail/is_pointer.hpp"
20#include "stdlib/include/stdlib_detail/is_same.hpp"
21
22namespace std {
23
24// parasoft-begin-suppress AUTOSAR-M4_5_1-a "Standard library implementation must cover all types, including bool"
25// parasoft-begin-suppress CERT_C-EXP46-b "Standard library implementation must cover all types, including bool"
26
27/// @brief Function object that can be invoked for less than comparisons
28/// @tparam T The type of the values
29/// @note This class contains the member types @c result_type, @c first_argument type, and @c second_argument type.
30/// These aliases have been deprecated in C++17 and removed in C++20.
31template <class T = void>
32class less {
33 public:
34 /// @brief Result type of invoking this object
35 using result_type = bool;
36 /// @brief Type of the first value to compare
37 using first_argument_type = T;
38 /// @brief Type of the second value to compare
39 using second_argument_type = T;
40
41 /// @brief Returns if the first value is less than the second
42 /// @param lhs The first value to compare
43 /// @param rhs The second value to compare
44 /// @return Returns the boolean result of invoking @c operator< on @c lhs and @c rhs
45 constexpr auto operator()(T const& lhs, T const& rhs) const noexcept(noexcept(lhs < rhs)) -> bool {
46 return lhs < rhs;
47 }
48};
49
50// parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: No identifiers are hidden by this type"
51// parasoft-begin-suppress AUTOSAR-A2_7_3-a "False positive: it does have a brief tag."
52/// @brief Function object that can be invoked for less than comparisons, specialized for type deduction
53template <>
54class less<void> {
55 public:
56 /// @brief Denotes that this is a transparent function object type
57 using is_transparent = void;
58
59 /// @brief Returns if the first value is less than the second
60 /// @tparam T The first type
61 /// @tparam U The second type
62 /// @param lhs The first value to compare
63 /// @param rhs The second value to compare
64 /// @return Returns the boolean result of invoking @c operator< on @c lhs and @c rhs
65 template <
66 class T,
67 class U,
71 constexpr auto operator()(T&& lhs, U&& rhs) const noexcept(noexcept(std::forward<T>(lhs) < std::forward<U>(rhs)))
72 -> decltype(std::forward<T>(lhs) < std::forward<U>(rhs)) {
73 return std::forward<T>(lhs) < std::forward<U>(rhs);
74 }
75
76 /// @brief Returns if the first value is less than the second
77 ///
78 /// This overload checks if a pointer is less than @c nullptr which is always @c false
79 /// @tparam T The first type
80 /// @tparam U The second type
81 /// @return Returns the boolean result of invoking @c operator< on the supplied values
82 template <
83 class T,
84 class U,
86 // parasoft-begin-suppress CERT_C-EXP37-a "False positive: The rule does not mention naming all parameters"
87 constexpr auto operator()(T&&, U&&) const noexcept -> bool {
88 return false;
89 }
90 // parasoft-end-suppress CERT_C-EXP37-a
91
92 /// @brief Returns if the first value is less than the second
93 ///
94 /// This overload checks if @c nullptr is less than a supplied pointer
95 /// @tparam T The first type
96 /// @tparam U The second type
97 /// @param rhs The pointer value to compare
98 /// @return Returns the boolean result of invoking @c operator< on the supplied values
99 template <
100 class T,
101 class U,
103 // parasoft-begin-suppress CERT_C-EXP37-a "False positive: The rule does not mention naming all parameters"
104 constexpr auto operator()(T&&, U&& rhs) const noexcept -> bool {
105 return rhs != nullptr;
106 }
107 // parasoft-end-suppress CERT_C-EXP37-a
108};
109// parasoft-end-suppress AUTOSAR-A2_7_3-a "False positive: it does have a brief tag."
110// parasoft-end-suppress AUTOSAR-A2_10_1-d "False positive: No identifiers are hidden by this type"
111
112} // namespace std
113
114#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_LESS_HPP_
Function object that can be invoked for less than comparisons.
Definition less.hpp:32
constexpr auto operator()(T const &lhs, T const &rhs) const noexcept(noexcept(lhs< rhs)) -> bool
Returns if the first value is less than the second.
Definition less.hpp:45
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