[iterator.primitives] (original) (raw)

It is often desirable for a function template specialization to find out what is the most specific category of its iterator argument, so that the function can select the most efficient algorithm at compile time.

To facilitate this, the library introducescategory tagclasses which are used as compile time tags for algorithm selection.

They are:output_iterator_tag,input_iterator_tag,forward_iterator_tag,bidirectional_iterator_tag,random_access_iterator_tag, andcontiguous_iterator_tag.

For every iterator of typeI,iterator_traits<I>​::​iterator_categoryshall be defined to be a category tag that describes the iterator's behavior.

Additionally,iterator_traits<I>​::​iterator_conceptmay be used to indicate conformance to the iterator concepts ([iterator.concepts]).

namespace std { struct output_iterator_tag { };struct input_iterator_tag { };struct forward_iterator_tag: public input_iterator_tag { };struct bidirectional_iterator_tag: public forward_iterator_tag { };struct random_access_iterator_tag: public bidirectional_iterator_tag { };struct contiguous_iterator_tag: public random_access_iterator_tag { };}