Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
prev.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_PREV_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ITERATOR_PREV_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"
16#include "arene/base/stdlib_choice/enable_if.hpp"
17#include "arene/base/stdlib_choice/iterator_traits.hpp"
18#include "arene/base/stdlib_choice/numeric_limits.hpp"
20// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
21
22// parasoft-begin-suppress CERT_C-PRE31-c-3 "False Positive: numeric_limits::min() is constexpr and has no side effects,
23// exception PRE31-C-EX1"
24
25// parasoft-begin-suppress AUTOSAR-A5_0_3-a "This abstraction is generic and
26// does not restrict the value type of the iterator"
27
28namespace arene {
29namespace base {
30
31///
32/// @brief Produces the Nth predecessor (or successor if @c steps is negative) of an iterator.
33///
34/// @tparam Iterator The iterator to advance. Does not participate in overload resolution unless @c Iterator is at
35/// least a bidirectional iterator.
36/// @param itr The iterator to advance
37/// @param steps The number of steps to advance the iterator by
38/// @pre If incrementing or decrementing @c itr @c steps times results in attempting to produce an invalid iterator
39/// such as past-the-end or before-the-begin, behavior is undefined.
40/// @pre @c steps is not @c std::numeric_limits<difference_type>::min() , else behavior is undefined.
41/// @return The iterator produced by incrementing/decrementing @c itr @c steps times.
42///
43template <typename Iterator, constraints<std::enable_if_t<is_bidirectional_iterator_v<Iterator>>> = nullptr>
44ARENE_NODISCARD constexpr auto prev( // CODEQLFP(DCL51-CPP)
45 Iterator itr,
47) noexcept(noexcept(::arene::base::advance(itr, -steps))) -> Iterator { // CODEQLFP(EXP52-CPP)
49 ::arene::base::advance(itr, -steps);
50 return itr;
51}
52
53} // namespace base
54} // namespace arene
55
56#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ITERATOR_PREV_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
Traits class to provide information about the representation of arithmetic types.
Definition numeric_limits.hpp:745
#define ARENE_PRECONDITION(condition)
Check that a precondition holds, and terminate the application if it does not.
Definition contract.hpp:150
Definition accumulate.hpp:37
ARENE_NODISCARD constexpr auto prev(Iterator itr, typename std::iterator_traits< Iterator >::difference_type steps=1) noexcept(noexcept(::arene::base::advance(itr, -steps))) -> Iterator
Produces the Nth predecessor (or successor if steps is negative) of an iterator.
Definition prev.hpp:44
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