Arrays and collections / Arrays

#include <iostream>
#include <vector>
#include <ranges>
using namespace std;

vector<int> vec = {12345};
vector<int> odd;
copy_if(vec.begin(), vec.end(),
    back_inserter(odd),
    //only odd values
    [&](int i) { return i % 2 == 1; });
//f_vec is {1, 3, 5}

for (int i : odd) cout << i << "; ";
cout << endl;

//since C++20
auto evens = views::filter(vec,
    [](int a){ return a % 2 == 0; });

for (int i : evens) cout << i << "; ";