Namespaces
Variants
Views
Actions

cpp/named req/ReversibleContainer

From cppreference.com
< cpp‎ | named req
Revision as of 04:26, 24 December 2012 by 83.177.154.38 (Talk)

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.

Template:cpp/container/dcl list rbeginTemplate:cpp/container/dcl list rend

Example

The following example uses vector but will work with all containers that support iteration.

#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;
}