Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/named req/ReversibleContainer"

From cppreference.com
< cpp‎ | named req
(Standard library)
m (Shorten template names. Use {{lc}} where appropriate.)
Line 6: Line 6:
 
===Requirements===
 
===Requirements===
  
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list item|{{ttb|X}}|Container type}}
+
{{dsc|{{ttb|X}}|Container type}}
{{dcl list item|{{ttb|T}}|Element type}}
+
{{dsc|{{ttb|T}}|Element type}}
{{dcl list item|{{ttb|a}}, {{ttb|b}}|Objects of type {{ttb|X}}}}
+
{{dsc|{{ttb|a}}, {{ttb|b}}|Objects of type {{ttb|X}}}}
{{dcl list end}}
+
{{dsc end}}
  
 
====Types====
 
====Types====
Line 65: Line 65:
  
 
===Standard library===
 
===Standard library===
* {{c|std::array}}
+
* {{lc|std::array}}
* {{c|std::deque}}
+
* {{lc|std::deque}}
* {{c|std::list}}
+
* {{lc|std::list}}
* {{c|std::vector}}
+
* {{lc|std::vector}}
* {{c|std::map}}
+
* {{lc|std::map}}
* {{c|std::multimap}}
+
* {{lc|std::multimap}}
* {{c|std::set}}
+
* {{lc|std::set}}
* {{c|std::multiset}}
+
* {{lc|std::multiset}}

Revision as of 18:38, 31 May 2013

Template:cpp/concept/title Template:cpp/concept/navbar

A ReversibleContainer is a Template:concept that has iterators that meet the requirements of either Template:concept or Template:concept. Such iterators allow a ReversibleContainer to be iterated over in reverse.

Contents

Requirements

X Container type
T Element type
a, b Objects of type X

Types

expression return type conditions complexity
X::reverse_iterator iterator type whose value type is T reverse_iterator<iterator> compile time
X::const_reverse_iterator iterator type whose value type is const T reverse_iterator<const_iterator> compile time

Methods

expression return type conditions complexity
a.rbegin() reverse_iterator; const_reverse_iterator for constant a reverse_iterator(end()) constant
a.rend() reverse_iterator; const_reverse_iterator for constant a reverse_iterator(begin()) constant
a.crbegin() const_reverse_iterator const_cast<X const&>(a).rbegin(); constant
a.crend() const_reverse_iterator const_cast<X const&>(a).rend(); constant


Example

The following example iterates over a vector (which has random-access iterators) in reverse.

#include <vector>
#include <iostream>
 
int main()
{
    std::vector<int> v = {3, 1, 4, 1, 5, 9};
 
    for(std::vector<int>::reverse_iterator i = v.rbegin(); i != v.rend(); ++i) {
        std::cout << *i << '\n';
    }
}

Output:

9
5
1
4
1
3


Standard library