2011-04-10 88 views
0

这里是我的multi_index代码:如何迭代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"); 

可是如何才能让另一/结束迭代器?

回答

1

你试过这个吗?

ByTypeIt end = mObjectsByTypeViewer.end(); 
+0

但我需要结束迭代器搜索(查找调用),而不是所有'mObjectsByTypeViewer'。这将是容器中所有对象的结束,对吧? – Ockonal 2011-04-10 20:06:24

+0

哦,如果你的意思是你想遍历所有具有某个键的值,那么你应该使用'lower_bound()'而不是'find()','upper_bound()'而不是'end()'。或者你可以调用'equal_range()'在一次调用中获得两个边界。它的工作原理与通常的STL一样:http://www.sgi.com/tech/stl/equal_range.html – 2011-04-10 20:10:42

+0

就是这样!谢谢 :) – Ockonal 2011-04-10 20:17:17