an example showing how to create a list from a vector, and vice versa

rbegin() and rend() return reverse_iterator



👍 g++ -std=c++11 list_from_vector.cpp
👍 ./a.out
3 1 4 1 5 9 2 6 
3 1 4 1 5 9 2 6 
6 2 9 5 1 4 1 3 
👍 cat list_from_vector.cpp 
#include <iostream>
#include <vector>
#include <list>
using namespace std;

template<typename C>
void prt(C c) {
  for(auto i=c.begin();i!=c.end();++i) 
    cout << *i << ' ';
  cout << endl;
}

int main() {
  vector<int> v{3,1,4,1,5,9,2,6};
  list<int> l(v.begin(), v.end());
  vector<int> w(l.rbegin(), l.rend());
  prt(v);
  prt(l);
  prt(w);
}