-
-
Save fabiogaluppo/d008ec37e60c172a4a58 to your computer and use it in GitHub Desktop.
forward_iterator_with_predicate and test_efficiency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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