2014-11-24 52 views

回答

2

当然问题是按照什么顺序。但是,让我承担最直接的解释:

typedef boost::multi_index::multi_index_container< 
    myClssPtr, 
    boost::multi_index::indexed_by< 
    OrderdBValue // OrderdBValue this is boost::multi_index::ordered_unique type 
    > 
> container; 

for(myClassPtr& e : container.get<0>()) 
{ 
    // e.g.: 
    std::cout << e << "\n"; 
} 

事实上,看到你只有一个指标,这也是默认的(第一个)指数,所以你甚至可以只说

for(myClassPtr& e : container) 
{ 
    // e.g.: 
    std::cout << e << "\n"; 
} 

UPDATE对于C++ 03的语法是有点笨拙:

typedef employee_set::nth_index<0>::type idx_type; 
for(idx_type::iterator it=container.get<0>().begin(); it != container.get<0>().end(); ++it) 
{ 
    // e.g. 
    std::cout << *it << "\n"; 
} 

现在,如果你/意/ _insertion顺序,那么你就明确地需要添加例如indexed_by<sequenced<> >indexed_by<random_access<> >

+0

你好@sehe,它导致到folllowing错误:错误:一个函数的定义在这里不允许使用前“:”令牌,如何“:”将努力为中循环? – balaji 2014-11-24 11:54:54

+0

使用常规的,但与c + + 03语法:**更新**答案(当然,升级您的编译器,或通过'-std = c + + 11'!) – sehe 2014-11-24 11:59:29

+0

请参阅[迭代器访问](http ://www.boost.org/doc/libs/1_57_0/libs/multi_index/doc/tutorial/basics.html#iterator_access)在文档 – sehe 2014-11-24 12:01:57

相关问题