1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <limits>
#include <numeric>
#include <random>
#include <vector>

struct IsIncreasing {
   bool operator()(const int& value) {
      if (value >= last_selected_value) {
	 last_selected_value = value;
	 return true;
      } else {
	 return false;
      }
   }
   int last_selected_value = std::numeric_limits<int>::min();
};

int main() {
   /* initialize values and fill it with shuffled values 1..100 */
   std::vector<int> values(100);
   std::iota(values.begin(), values.end(), 1);
   std::shuffle(values.begin(), values.end(), std::mt19937(2));

   /* select all even values out of it */
   std::vector<int> selected_values;
   std::copy_if(values.begin(), values.end(),
      std::back_inserter(selected_values), IsIncreasing());

   /* print selected values */
   int count = 0;
   for (auto value: selected_values) {
      std::cout << std::setw(4) << value;
      if (++count % 10 == 0) std::cout << std::endl;
   }
   std::cout << std::endl;
}