Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
next.hpp
Go to the documentation of this file.
1// Copyright 2024, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ITERATOR_NEXT_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ITERATOR_NEXT_HPP_
7
8// IWYU pragma: private, include "arene/base/iterator.hpp"
9// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
15#include "arene/base/stdlib_choice/enable_if.hpp"
16#include "arene/base/stdlib_choice/iterator_traits.hpp"
18// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
19
20namespace arene {
21namespace base {
22
23// parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
24// parasoft-begin-suppress AUTOSAR-A5_0_3-a "False positive: There is no pointer indirection in return types"
25///
26/// @brief Produces the Nth successor (or predecessor if @c steps is negative) of an iterator.
27///
28/// @tparam Iterator The iterator to advance. Does not participate in overload resolution unless @c Iterator is at
29/// least an input iterator.
30/// @param itr The iterator to advance
31/// @param steps The number of steps to advance the iterator by
32/// @pre If incrementing or decrementing @c itr @c steps times results in attempting to produce an invalid iterator
33/// such as past-the-end or before-the-begin, behavior is undefined.
34/// @pre If @c Iterator is an input iterator, @c steps is not negative, else @c ARENE_PRECONDITION violation.
35/// @return The iterator produced by incrementing/decrementing @c itr @c steps times.
36///
37template <typename Iterator, constraints<std::enable_if_t<is_input_iterator_v<Iterator>>> = nullptr>
38ARENE_NODISCARD constexpr auto next( // CODEQLFP(DCL51-CPP)
39 Iterator itr,
41) noexcept(noexcept(::arene::base::advance(itr, steps))) -> Iterator { // CODEQLFP(EXP52-CPP)
42 ::arene::base::advance(itr, steps);
43 return itr;
44}
45// parasoft-end-suppress AUTOSAR-M3_3_2-a-2
46// parasoft-begin-suppress AUTOSAR-A5_0_3-a "False positive: There is no pointer indirection in return types"
47
48} // namespace base
49} // namespace arene
50
51#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ITERATOR_NEXT_HPP_
Provides a backport of C++17's constexpr std::advance.
provides a uniform interface to the properties of an iterator
Definition iterator_traits.hpp:90
Definition accumulate.hpp:37
ARENE_NODISCARD constexpr auto next(Iterator itr, typename std::iterator_traits< Iterator >::difference_type steps=1) noexcept(noexcept(::arene::base::advance(itr, steps))) -> Iterator
Produces the Nth successor (or predecessor if steps is negative) of an iterator.
Definition next.hpp:38
Definition accumulate.hpp:36
#define ARENE_NODISCARD
An alias for [[nodiscard]] , or a no-op if the attribute is not supported.
Definition nodiscard.hpp:26