an example of using unique() of STL list

It works as expected when the list is sorted.



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

template<typename I>
void show(I i, I e) {
  for(; i != e; ++i)
    cout << *i << ' ';
  cout << endl;
} 

int main() {
  list<int> l1{3,1,4,1,5,9,2,5},l2;
  show(l1.begin(), l1.end());
  l1.unique();
  show(l1.begin(), l1.end());
  l1.sort();
  l2 = l1;
  show(l1.begin(), l1.end());
  l1.unique();
  show(l1.begin(), l1.end());
  l2.reverse();
  show(l2.begin(), l2.end());
  l2.unique();
  show(l2.begin(), l2.end());
}