Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
max_value_overload.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_MAX_VALUE_OVERLOAD_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_MAX_VALUE_OVERLOAD_HPP_
7
8// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
9#include "arene/base/functional/detail/max_fn.hpp"
10#include "arene/base/functional/detail/operator_less.hpp"
12// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
13
14// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
15// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
16// parasoft-begin-suppress AUTOSAR-M17_0_3-a "Reserved names are used as part of a standard library implementation"
17
18// IWYU pragma: private, include <algorithm>
19// IWYU pragma: friend "stdlib_detail/.*"
20
21namespace std {
22
23// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: inline function used in multiple translation units"
24/// @brief Returns the larger of the given values.
25/// @tparam T The type of the values
26/// @tparam Compare The type of the comparison function
27/// @param lhs The first value to compare
28/// @param rhs The second value to compare
29/// @param comp The comparison function which returns true if the first parameter is less than the second
30/// @return Returns the larger of @c lhs and @c rhs using the comparison function @c comp to compare the values
31template <class T, class Compare>
32constexpr auto max(T const& lhs, T const& rhs, Compare comp) noexcept(
34) -> T const& {
35 return arene::base::functional_detail::max_fn<Compare&>(comp)(lhs, rhs);
36}
37// parasoft-end-suppress AUTOSAR-M3_3_2-a
38
39// parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
40// parasoft-begin-suppress AUTOSAR-M17_0_3-a "This is an implementation of the standard library function"
41// parasoft-begin-suppress AUTOSAR-M4_5_1-a "False positive: Arguments are only used with the conditional operator"
42// parasoft-begin-suppress CERT_C-EXP46-b "False positive: Arguments are only used with the conditional operator"
43/// @brief Returns the larger of the given values.
44/// @tparam T The type of the values
45/// @param lhs The first value to compare
46/// @param rhs The second value to compare
47/// @return Returns the larger of @c lhs and @c rhs
48///
49/// @note If T is not @c LessThanComparable, the behavior is undefined
50template <class T>
51constexpr auto max(T const& lhs, T const& rhs) noexcept(
52 noexcept(max(lhs, rhs, arene::base::functional_detail::operator_less))
53) -> T const& {
54 return max(lhs, rhs, arene::base::functional_detail::operator_less);
55}
56// parasoft-end-suppress CERT_C-EXP46-b
57// parasoft-end-suppress AUTOSAR-M4_5_1-a
58
59// parasoft-end-suppress AUTOSAR-M3_3_2-a-2
60// parasoft-end-suppress AUTOSAR-M17_0_3-a
61
62} // namespace std
63
64#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_MAX_VALUE_OVERLOAD_HPP_
STL namespace.
constexpr auto max(initializer_list< T > list, Compare comp) noexcept(noexcept(comp(std::declval< T & >(), std::declval< T & >())) &&std::is_nothrow_copy_constructible_v< T >) -> T
Returns the largest value in the std::initializer_list.
Definition max_initializer_list_overload.hpp:49
auto declval() noexcept -> T &&
A dummy function that is declared but not defined, with a user-specified return type,...