Difference between revisions of "cpp/named req/ReversibleContainer"
From cppreference.com
(LWG issue 2105 (fixed in c++14)) |
m (link to zh) |
||
Line 9: | Line 9: | ||
{{dsc|{{ttb|X}}|Container type}} | {{dsc|{{ttb|X}}|Container type}} | ||
{{dsc|{{ttb|T}}|Element type}} | {{dsc|{{ttb|T}}|Element type}} | ||
− | {{dsc|{{ttb|a | + | {{dsc|{{ttb|a}}|Objects of type {{ttb|X}}}} |
{{dsc end}} | {{dsc end}} | ||
Line 28: | Line 28: | ||
!expression||return type||conditions||complexity | !expression||return type||conditions||complexity | ||
|- | |- | ||
− | |{{c|a.rbegin()}}|| {{c|reverse_iterator | + | |{{c|a.rbegin()}}|| {{c|reverse_iterator}}; {{c|const_reverse_iterator}} for constant {{tt|a}} || {{c|reverse_iterator(end())}} || constant |
|- | |- | ||
− | |{{c|a.rend()}}|| {{c|reverse_iterator | + | |{{c|a.rend()}}|| {{c|reverse_iterator}}; {{c|const_reverse_iterator}} for constant {{tt|a}} || {{c|reverse_iterator(begin())}} || constant |
|- | |- | ||
− | |{{c|a.crbegin()}}|| {{c|const_reverse_iterator}} || {{c|const_cast<X const&>(a).rbegin() | + | |{{c|a.crbegin()}}|| {{c|const_reverse_iterator}} || {{c|const_cast<X const&>(a).rbegin()}} || constant |
− | + | ||
− | + | ||
|- | |- | ||
+ | |{{c|a.crend()}}|| {{c|const_reverse_iterator}} || {{c|const_cast<X const&>(a).rend()}} || constant | ||
|} | |} | ||
Line 73: | Line 72: | ||
* {{lc|std::set}} | * {{lc|std::set}} | ||
* {{lc|std::multiset}} | * {{lc|std::multiset}} | ||
+ | |||
+ | {{langlinks|zh}} |
Revision as of 09:49, 20 August 2017
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
|
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 | constant iterator type whose value type is 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.
Run this code
#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