Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
forward_iterator_with_predicate and test_efficiency
#include "forward_iterator_with_predicate.hpp"
#include <vector>
#include <algorithm>
#include <iostream>
template <class Iter>
void display(Iter& iter)
{
for (auto i : iter) std::cout << i << " ";
std::cout << "\n";
}
void test_efficiency()
{
auto is_even = [](int i) {
return (i & 0x1) == 0x0;
};
std::vector<int> xs = { 1, 2, 3, 4, 5, 6, 7, 8 };
auto iwp = make_iterator_with_predicate(xs, is_even);
std::vector<int> ys;
ys.resize(4);
std::copy(iwp.begin(), iwp.end(), ys.begin());
display(ys);
std::vector<int> zs;
zs.resize(4);
std::copy_if(xs.begin(), xs.end(), zs.begin(), is_even);
display(zs);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment