简体   繁体   中英

Storing an boost multi_index index iterator

I have a boost::multi_index class which has multiple indexes.

If i want to store a normal iterator i can do

multi_index_table::const_iterator x_itr == my_table.find(x);

but if i try

multi_index_table::const_iterator x_itr == my_table.get_index(y).find(x) it complains that it's not the same type of iterator.

I'm fairly new to C++ and come from a java background, ideally i'd like some form of superclass which is able to store any type of iterator if that's possibile.

Any guidance will be much appreciated!

EDIT: I'm basically looking to do something as such:

my_table.get_index(a).find(x);
x.erase<a>(x):

my_table.get_index(b).find(y);
    x.erase<b>(y):   

template<uint64_t Index>
template<typename Iterator>  
Iterator erase(Iterator itr){
  my_table.get_index<Index>().erase(itr)
}

With c++11 is rather easy. Just use:

auto x_itr = my_table.get_index(y).find(x)

The compiler will figure out the type of x_itr .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM