【发布时间】:2020-08-08 10:48:02
【问题描述】:
#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;
}
}
用clang 10用libc++编译,输出为:
123
456
789
123
456
789
如我所料,结果应该是:
""
""
""
123
456
789
为什么即使迭代器是 std::move_iterator,ranges-v3 也不移动元素?
======= 更新=======
我的范围版本是:range-v3-0.10.0。即使我将std::string 替换为std::vector<char>,问题在我的linux docker 上仍然可以重现,gcc 和clang 产生相同的结果。
但是,godbolt.org 上的相同代码是可以的,但我不确定godbold.org 上的范围版本是 3.0.10。
【问题讨论】:
标签: c++ standards move-semantics rvalue-reference range-v3