【问题标题】:How to iterate multi_index如何迭代 multi_index
【发布时间】:2011-04-10 19:46:55
【问题描述】:

这是我的 multi_index 代码:

struct tag_type {};
typedef boost::multi_index_container<ObjectStorage,
            bmi::indexed_by<
                // Type
                bmi::ordered_non_unique<
                    bmi::tag<tag_type>,
                    bmi::const_mem_fun<ObjectStorage, std::string, &ObjectStorage::getType>
                >
            >
        > ObjectWrapperSet;

现在我想遍历 find 的结果。

ObjectWrapperSet::index<tag_type>::type &mObjectsByTypeViewer = 
    mObjectsSet.get<tag_type>()

 typedef ObjectWrapperSet::index<tag_type>::type::const_iterator ByTypeIt;
 ByTypeIt it = mObjectsByTypeViewer.find("Some type");

但是如何获得另一个/结束迭代器?

【问题讨论】:

    标签: c++ boost iterator multi-index


    【解决方案1】:

    你试过了吗?

    ByTypeIt end = mObjectsByTypeViewer.end();
    

    【讨论】:

    • 但我需要结束迭代器来进行搜索(查找调用),而不是所有mObjectsByTypeViewer。这将是容器中所有对象的终结,对吧?
    • 哦,如果您的意思是要遍历具有某个键的所有值,那么您应该使用lower_bound() 而不是find(),以及upper_bound() 而不是end()。或者您可以调用equal_range() 以在一次调用中获得两个边界。它的工作方式与通常的 STL 相同:sgi.com/tech/stl/equal_range.html
    猜你喜欢
    • 2016-03-23
    • 2014-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-23
    • 2011-05-11
    相关资源
    最近更新 更多