#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

template <
    class InputIterator, class OutputIterator, 
    class UnaryOperator, class Pred
>
OutputIterator transform_if(InputIterator first1, InputIterator last1,
                            OutputIterator result, UnaryOperator op, Pred pred)
{
    while (first1 != last1) 
    {
        if (pred(*first1)) {
            *result = op(*first1);
            ++result;
        }
        ++first1;
    }
    return result;
}

struct ha { 
	int i;
    explicit ha(int a) : i(a) {}
};

int main() 
{
    vector<ha> v{ ha{1}, ha{7}, ha{1} }; // initial vector
    // GOAL : make a vector of pointers to elements with i < 2
    vector<ha*> ph; // target vector
    
    // example call 
    transform_if(v.begin(), v.end(), back_inserter(ph), 
    [](ha &arg) { return &arg;      }, // 1. 
    [](ha &arg) { return arg.i < 2; });// 2.
    
    return 0;
}

