Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
reverse.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_REVERSE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_REVERSE_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 <algorithm>
12// IWYU pragma: friend "stdlib_detail/.*"
13
21
22namespace std {
23
24/// @brief reverses the order of elements in a range
25/// @tparam BidirIt The iterator used to iterate over the input range
26/// @param first the beginning of the range
27/// @param last the end of the range
28template <
29 typename BidirIt,
32 std::enable_if_t<arene::base::is_swappable_v<typename std::iterator_traits<BidirIt>::value_type>>> = nullptr>
33// clang-format cannot format the noexcept clause correctly
34// clang-format off
35constexpr auto reverse(
36 BidirIt first,
37 BidirIt last
38) noexcept(
41 // clang-format on
42 while (first != last && first != --last) {
43 std::iter_swap(first, last);
44 ++first;
45 }
46}
47
48} // namespace std
49
50#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_REVERSE_HPP_
Public export header for the constraints subpackage.
constexpr bool is_nothrow_swappable_v
Trait query indicating if a type can be noexcept-swapped.
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
constexpr bool has_nothrow_basic_bidirectional_iterator_operations_v
Internal type trait to check if a type supports the necessary bidirectional iterator operations witho...
STL namespace.
constexpr auto iter_swap(ForwardIterator1 lhs, ForwardIterator2 rhs) noexcept(arene::base::is_nothrow_swappable_with_v< typename std::iterator_traits< ForwardIterator1 >::reference, typename std::iterator_traits< ForwardIterator2 >::reference >) -> void
swaps the objects pointed to by two iterators
Definition iter_swap.hpp:37
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
constexpr auto reverse(BidirIt first, BidirIt last) noexcept(internal::has_nothrow_basic_bidirectional_iterator_operations_v< BidirIt > &&arene::base::is_nothrow_swappable_v< typename std::iterator_traits< BidirIt >::value_type >) -> void
reverses the order of elements in a range
Definition reverse.hpp:35