.. Iterators/Iterator Metafunctions//iterator_category |60 iterator_category ================= Synopsis -------- .. parsed-literal:: template< typename Iterator > struct iterator_category { typedef typename Iterator::category type; }; Description ----------- Returns one of the following iterator category tags: * ``forward_iterator_tag`` * ``bidirectional_iterator_tag`` * ``random_access_iterator_tag`` Header ------ .. parsed-literal:: #include #include Parameters ---------- +---------------+-----------------------+-------------------------------------------+ | Parameter | Requirement | Description | +===============+=======================+===========================================+ | ``Iterator`` | |Forward Iterator| | The iterator to obtain a category for. | +---------------+-----------------------+-------------------------------------------+ Expression semantics -------------------- For any |Forward Iterator|\ s ``iter``: .. parsed-literal:: typedef iterator_category::type tag; :Return type: |Integral Constant|. :Semantics: ``tag`` is ``forward_iterator_tag`` if ``iter`` is a model of |Forward Iterator|, ``bidirectional_iterator_tag`` if ``iter`` is a model of |Bidirectional Iterator|, or ``random_access_iterator_tag`` if ``iter`` is a model of |Random Access Iterator|; :Postcondition: ``forward_iterator_tag::value < bidirectional_iterator_tag::value``, ``bidirectional_iterator_tag::value < random_access_iterator_tag::value``. Complexity ---------- Amortized constant time. Example ------- .. parsed-literal:: template< typename Tag, typename Iterator > struct algorithm_impl { // *O(n)* implementation }; template< typename Iterator > struct algorithm_impl { // *O(1)* implementation }; template< typename Iterator > struct algorithm : algorithm_impl< iterator_category::type , Iterator > { }; See also -------- |Iterators|, |begin| / |end|, |advance|, |distance|, |next|