std::ranges::move_backward
Актуально для C++26.
#include <algorithm>
Актуально на 2025-07-01.
Define overload #1
template<bidirectional_iterator I1, sentinel_for<I1> S1, bidirectional_iterator I2> requires indirectly_movable<I1, I2> constexpr ranges::move_backward_result<I1, I2> move_backward(I1 first, S1 last, I2 result);
Перемещает элементы из диапазона [first, last], начиная с last, в result.
Example, possible implementation
Define overload #2
template<bidirectional_range R, bidirectional_iterator I> requires indirectly_movable<iterator_t<R>, I> constexpr ranges::move_backward_result<borrowed_iterator_t<R>, I> move_backward(R&& r, I result);
Перемещает элементы из r, начиная с конца, в result.
Example, possible implementation
Параметры
first, last - пара iterator-sentinel указывающих на перемещаемые данные.
r - объект, содержащий перемещаемые данные, удовлетворяющий требования концепта bidirectional_range.
result - объект-итератор, удовлетворяющий требования концепта bidirectional_iterator, указывающий на конец результирующего диапазона. Во избежание переполнения буфера, пользователь должен позаботиться о том, чтобы памяти на которую ссылается result, хватило для записи всех элементов.
Возвращаемое значение
Вернёт два итератора {last, result - N}, где N, кол-во элементов в диапазоне.
Examples
Example 1:
#include <iostream> #include <algorithm> #include <vector> #include <string> namespace ranges = std::ranges; int main() { std::vector<std::string> in{"str1", "str2"}; std::vector<std::string> out(2); auto [in_, out_] = ranges::move_backward(in, out.end()); if (in_ == in.end() && out_ == out.begin()) { std::cout << "in[0]: " << in[0] << std::endl; std::cout << "in[1]: " << in[1] << std::endl; std::cout << "out[0]: " << out[0] << std::endl; std::cout << "out[1]: " << out[1] << std::endl; } }
in[0]: in[1]: out[0]: str1 out[1]: str2
Changelog
C++20
Введён в стандарт.See also
TODO
This page was last modified on 2025-07-01