Range-v3带有移动的平板

我正在尝试将一个容器的容器平展成一个维度,并使用views :: join和views :: move,但是我很难理解先移动然后先加入VS先连接然后再移动之间的区别。 Try2可以正常工作,但是有人可以帮助我了解在Try1最终复制的幕后发生的事情吗?某处的举动没有奏效。谢谢 !

wandbox link to the code: https://wandbox.org/permlink/BeFI3wjBiUPbsMA2

#include <iostream>
#include <vector>
#include <string>
#include <range/v3/all.hpp>

int main()
{     
    auto words = std::vector<std::vector<std::string>>{
        {"Hello", "World"},
        {"ni","hao"}
    };
    // Try1
    auto result1 = words
        | ranges::views::move
        | ranges::views::join
        | ranges::to<std::vector<std::string>>();

    std::cout<<ranges::views::all(ranges::views::join(words))<<std::endl;
    //[Hello,World,ni,hao]

    // Try2   
    auto result2 = words
        | ranges::views::join
        | ranges::views::move
        | ranges::to<std::vector<std::string>>();

    std::cout<<ranges::views::all(ranges::views::join(words))<<std::endl;
    //[,,,]
}
评论