#include <range/v3/all.hpp>
#include <vector>
#include <string>
#include <deque>
using namespace std::literals;
int main()
{
auto src = std::vector{"123"s, "456"s, "789"s};
auto movable_rng = ranges::subrange(
std::make_move_iterator(src.begin()),
std::make_move_iterator(src.end()));
auto dst = ranges::to<std::deque<std::string>>(movable_rng);
for (auto e : src)
{
std::cout << e << std::endl;
}
for (auto e : dst)
{
std::cout << e << std::endl;
}
}
Compiled with clang 10 with libc++ and the output is:
123
456
789
123
456
789
As I expected, the result should be:
""
""
""
123
456
789
Why does ranges-v3 not move elements even the iterator is std::move_iterator
?
======= Update =======
My ranges version is : range-v3-0.10.0
. Even I replace std::string
with std::vector<char>
, the problem is still reproducible on my linux docker, both gcc and clang produce the same result.
However, the same code is ok on godbolt.org, but I am not sure the ranges' version of ranges on godbold.org is 3.0.10
.