is there a better way than a loop to get the value/const_iterator at a specific position in multi_index table?


auto idx =  _table.get_index<"name"_n>();
const_iterator b;
int count = 0;
for(auto it = idx.cbegin(); it != idx.cend() && count <= position; it++){
   if(count == position){
       b = it;


something like:

std::vetor<int> i ={10,12,23,45};
auto idx = i.cbegin()+position;

as far as i understand lower_bound won't work because it will only show the values which are identical with secondary_index and not the position. And in the multi_index.hpp does not support the standard method for vectors etc.

  • yes, your can use lower_bound and upper_bound
    – Jimmy Guo
    Sep 3, 2019 at 1:59

1 Answer 1


Implementing loop to find a index from first element to last element can give you O(n) complexity if element is always at last index, this approach is not suitable.

You can get the position the element by simply doing increment in iterator.

auto itr = idx.begin();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.