Difference between revisions of "cpp/named req/ReversibleContainer"
From cppreference.com
Sonulohani (Talk | contribs) (Created page with "{{cpp/concept/title|ReversibleContainer}} {{cpp/concept/navbar}} The concept {{concept|ReversibleContainer}} is a Forward Container whose iterators are Bidirectional Iterator...") |
(not true for std::forward_list) |
||
Line 2: | Line 2: | ||
{{cpp/concept/navbar}} | {{cpp/concept/navbar}} | ||
− | The concept {{concept|ReversibleContainer}} is a Forward Container whose iterators are Bidirectional Iterators. It allows backwards iteration through the container. It means that it can produce iterators that move backward from the end, as well as iterators that move forward from the beginning | + | The concept {{concept|ReversibleContainer}} is a Forward Container whose iterators are Bidirectional Iterators. It allows backwards iteration through the container. It means that it can produce iterators that move backward from the end, as well as iterators that move forward from the beginning. |
===Standard library=== | ===Standard library=== |
Revision as of 04:26, 24 December 2012
Template:cpp/concept/title Template:cpp/concept/navbar
The concept Template:concept is a Forward Container whose iterators are Bidirectional Iterators. It allows backwards iteration through the container. It means that it can produce iterators that move backward from the end, as well as iterators that move forward from the beginning.
Standard library
The following standard library facilities.
Example
The following example uses vector but will work with all containers that support iteration.
Run this code
#include <fstream> #include <iostream> #include <string> #include <vector> #include "../require.h" using namespace std; int main() { ifstream in("Reversible.cpp"); assure(in, "Reversible.cpp"); string line; vector<string> lines; while(getline(in, line)) lines.push_back(line); for(vector<string>::reverse_iterator r = lines.rbegin(); r != lines.rend(); r++) cout << *r << endl; }