如何制作boost :: filesystem :: directory_iterator的副本?

And*_*hko 5 c++ boost iterator boost-filesystem

我知道这听起来很愚蠢,但看看这个简单的例子(工作目录应该有多个项目):

#define BOOST_FILESYSTEM_VERSION 3
#include <boost/filesystem.hpp>
#include <cassert>

int main()
{
    using namespace boost::filesystem;
    directory_iterator it("./");
    directory_iterator it_copy = it;
    ++it;
    assert(it_copy != it);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

it_copy与...一起修改it!(提升1.45)哪些因素可能导致这种设计(directory_iterator类似于智能ptr)?

我只需要保存一份副本directory_iterator以便以后使用它.

Mat*_* M. 6

如果您查看参考文献,您会注意到它被宣传为a boost::single_pass_traversal_tag.

这是STL中输入迭代器的等效(在boost术语中)(将其视为从网络连接传递数据包的迭代器,您无法倒带).

另请注意(从同一页面):

i == j并不意味着++i == ++j.

在这一点上,人们可能想知道为什么它可以被复制.原因是STL算法通过复制设置了他们的参数.因此,如果无法复制,它将无法用于STL算法.