Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Distance between multiset iterator

Can we find the distance between two iterator in multiset with a complexity of less than O(n)?
I tried to use the std::distance() function provided with iterator header. But its internal implementation is O(n) for multiset iterator.

like image 963
rohangulati Avatar asked Nov 14 '25 20:11

rohangulati


1 Answers

multiset::iterator models BidirectionalIterator, not RandomAccessIterator, so std::distance is only required to be linear, not constant.

like image 103
ecatmur Avatar answered Nov 17 '25 10:11

ecatmur