Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
min_initializer_list_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_MIN_INITIALIZER_LIST_OVERLOAD_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_MIN_INITIALIZER_LIST_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/algorithm/detail/traits.hpp"
13#include "arene/base/functional/detail/flip.hpp"
14#include "arene/base/functional/detail/operator_less.hpp"
20// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
21
22// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
23// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
24
25// IWYU pragma: private, include <algorithm>
26// IWYU pragma: friend "stdlib_detail/.*"
27
28namespace std {
29
30// parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
31// parasoft-begin-suppress AUTOSAR-M17_0_3-a "This is an implementation of the standard library function"
32
33/// @brief Returns the smallest value in the @c std::initializer_list
34/// @tparam T The type of the values in the @c std::initializer_list
35/// @tparam Compare The type of the comparison function
36/// @param list The list of values to compare
37/// @param comp The comparison function which returns true if the first parameter is less than the second
38/// @return Returns the smallest value in @c list using the comparison function @c comp to compare the values
39///
40/// @pre <tt> list.size() > 0 </tt>
41/// @pre <tt> std::is_copy_constructible<T>::value == true </tt>
42/// @pre The expression <tt>comp(a, b)</tt> must be convertible to @c bool
43/// for every argument @c a, @c b of type <tt> T const& </tt>.
44template <
45 class T,
46 class Compare,
50constexpr auto min(
52 Compare comp
53) noexcept(noexcept(comp(std::declval<T&>(), std::declval<T&>())) && std::is_nothrow_copy_constructible_v<T>) -> T {
54 ARENE_PRECONDITION(list.size() > std::size_t{0});
55 return *arene::base::max_element(list.begin(), list.end(), arene::base::functional_detail::flip(comp));
56}
57
58/// @brief Returns the smallest value in the @c std::initializer_list
59/// @tparam T The type of the values in the @c std::initializer_list
60/// @param list The list of values to compare
61/// @return Returns the smallest value in @c list
62///
63/// @pre <tt> list.size() > 0 </tt>
64/// @pre <tt> std::is_copy_constructible<T>::value == true </tt>
65/// @pre The expression <tt>comp(a, b)</tt> must be convertible to @c bool
66/// for every argument @c a, @c b of type <tt> T const& </tt>.
67template <
68 class T,
72 arene::base::is_compare_v<decltype(arene::base::functional_detail::operator_less)&, T const&>>> = nullptr>
73constexpr auto min(initializer_list<T> list
74) noexcept(noexcept(std::min(list, arene::base::functional_detail::operator_less))) -> T {
75 return min(list, arene::base::functional_detail::operator_less);
76}
77
78// parasoft-end-suppress AUTOSAR-M3_3_2-a-2
79// parasoft-end-suppress AUTOSAR-M17_0_3-a
80
81} // namespace std
82
83#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_MIN_INITIALIZER_LIST_OVERLOAD_HPP_
Implementation of std::initializer_list for brace initialization.
Definition initializer_list.hpp:21
Public export header for the constraints subpackage.
#define ARENE_PRECONDITION(condition)
Check that a precondition holds, and terminate the application if it does not.
Definition contract.hpp:150
Public export header for the contracts subpackage.
constexpr bool is_compare_v
determines if a type satisfies the Compare named requirement
typename constraints_impl::constraints< EnableIfs... >::type constraints
Helper used to express template constraints in a consistent way using std::enable_if_t.
Definition constraints.hpp:51
STL namespace.
::size_t size_t
A type suitable for holding the size of an object.
Definition cstddef.hpp:29
typename enable_if< Condition, Type >::type enable_if_t
Type alias to support constraining templates. Is an alias for the specified type if the Condition is ...
Definition enable_if.hpp:41
auto declval() noexcept -> T &&
A dummy function that is declared but not defined, with a user-specified return type,...
constexpr auto min(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 smallest value in the std::initializer_list.
Definition min_initializer_list_overload.hpp:50
constexpr bool is_nothrow_copy_constructible_v
Type trait to detect if an instance of T is copy constructible without throwing.