tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
move_backward.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2020 Tobias Hienzsch
3
4#ifndef TETL_ALGORITHM_MOVE_BACKWARD_HPP
5#define TETL_ALGORITHM_MOVE_BACKWARD_HPP
6
7#include <etl/_utility/move.hpp>
8
9namespace etl {
10
11/// Moves the elements from the range `[first, last)`, to another range
12/// ending at destination. The elements are moved in reverse order (the last
13/// element is moved first), but their relative order is preserved.
14///
15/// https://en.cppreference.com/w/cpp/algorithm/move_backward
16///
17/// \returns Iterator in the destination range, pointing at the last element moved.
18///
19/// \param first The range of elements to move.
20/// \param last The range of elements to move.
21/// \param destination End of the destination range.
22///
23/// \ingroup algorithm
24template <typename BidirIt1, typename BidirIt2>
25constexpr auto move_backward(BidirIt1 first, BidirIt1 last, BidirIt2 destination) -> BidirIt2
26{
27 for (; first != last;) {
28 --last;
29 *(--destination) = etl::move(*last);
30 }
31 return destination;
32}
33
34} // namespace etl
35
36#endif // TETL_ALGORITHM_MOVE_BACKWARD_HPP
constexpr auto move_backward(BidirIt1 first, BidirIt1 last, BidirIt2 destination) -> BidirIt2
Moves the elements from the range [first, last), to another range ending at destination....
Definition move_backward.hpp:25
Definition adjacent_find.hpp:9