Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How should I assume which iterator category an algorithm uses?

Let’s say :

std::sort(beg1, beg2, pred);

This algorithm takes a range of iterators for the container and a predicate. It takes an LegacyRandomAccessIterator.
I do understand the the 5 iterator categories are categorised by their operators.
Albeit I’m having a hard time assuming which iterator the algorithm uses.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There is no need to assume anything, it is all documented. According to cppreference the iterators are LegacyRandomAccessIterator.

Type requirements
-RandomIt must meet the requirements of ValueSwappable and LegacyRandomAccessIterator.
-The type of dereferenced RandomIt must meet the requirements of MoveAssignable and MoveConstructible.

The page for LegacyRandomAccessIterator describes what such an iterator looks like.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading