tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
copy_backward.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_ALGORITHM_COPY_BACKWARD_HPP
5#define TETL_ALGORITHM_COPY_BACKWARD_HPP
6
7namespace etl {
8
9/// Copies the elements from the range, defined by `[first, last)`, to
10/// another range ending at `dLast`. The elements are copied in reverse order
11/// (the last element is copied first), but their relative order is preserved.
12///
13/// The behavior is undefined if `dLast` is within `(first, last]`.
14/// copy must be used instead of copy_backward in that case.
15///
16/// \returns Iterator to the last element copied.
17/// \ingroup algorithm
18template <typename BidirIt1, typename BidirIt2>
19constexpr auto copy_backward(BidirIt1 first, BidirIt1 last, BidirIt2 dLast) -> BidirIt2
20{
21 while (first != last) {
22 *(--dLast) = *(--last);
23 }
24 return dLast;
25}
26
27} // namespace etl
28
29#endif // TETL_ALGORITHM_COPY_BACKWARD_HPP
constexpr auto copy_backward(BidirIt1 first, BidirIt1 last, BidirIt2 dLast) -> BidirIt2
Copies the elements from the range, defined by [first, last), to another range ending at dLast....
Definition copy_backward.hpp:19
Definition adjacent_find.hpp:9