如何提升副本::文件系统:: directory_iterator? [英] how to make a copy of boost::filesystem::directory_iterator?

查看:161
本文介绍了如何提升副本::文件系统:: directory_iterator?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I know this sounds stupid, but look at this simple example (working dir should have more than one item):

#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;
}

it_copy 一起修改了它! (提高1.45),可能会导致这样的设计有什么注意事项( directory_iterator 是像智能PTR)?

it_copy is modified together with it! (boost 1.45) What considerations could lead to such design (directory_iterator is something like smart ptr)?

我只需要保存 directory_iterator 的副本以后使用它。

I just need to save a copy of directory_iterator to use it later.

推荐答案

如果你看看在<一个href=\"http://live.boost.org/doc/libs/1_46_1/libs/filesystem/v3/doc/reference.html#Class-directory_iterator\">reference你会发现,它是标榜是一个的boost :: single_pass_traversal_tag

If you take a look at the reference you will notice that it is advertised to be a boost::single_pass_traversal_tag.

这是在STL的输入迭代相当于(升压术语)(想想它作为一个迭代器从网络连接提供数据包,则不能退)。

This is the equivalent (in boost terminology) of the Input Iterator in the STL (think of it as an iterator delivering packets from a network connection, you cannot rewind).

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

Also note (from this same page):

我==Ĵ并不意味着 ++我== ++Ĵ

在这一点上,人们可能会问,为什么它可以被复制。其原因是,STL算法设置规范通过复制服用他们的论点。因此,它不会与STL算法使用的,如果它无法复制。

At this point, one may wonder why it can be copied. The reason is that STL algorithms have set the norm taking their arguments by copy. Therefore it would not be usable with STL algorithms if it could not be copied.

这篇关于如何提升副本::文件系统:: directory_iterator?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆