MCPcopy Create free account
hub / github.com/Dobiasd/FunctionalPlus / Test_example_KeepIf

Function Test_example_KeepIf

examples/readme_perf_examples.cpp:23–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21bool is_odd_int(int x) { return x % 2 != 0; }
22
23void Test_example_KeepIf()
24{
25 typedef std::vector<int> Ints;
26 Ints values = { 24, 11, 65, 44, 80, 18, 73, 90, 69, 18 };
27
28 { // Version 1: hand written range based for loop
29 Ints odds;
30 for (int x : values)
31 if (is_odd_int(x))
32 odds.push_back(x);
33 }
34
35 { // Version 2: STL
36 Ints odds;
37 std::copy_if(std::begin(values), std::end(values),
38 std::back_inserter(odds), is_odd_int);
39 }
40
41 { // Version : FunctionalPlus
42 auto odds = fplus::keep_if(is_odd_int, values);
43 }
44}
45
46void run_n_times(std::function<std::vector<int>(std::vector<int>)> f,
47 std::size_t n, const std::string& name, const std::vector<int>& inList)

Callers

nothing calls this directly

Calls 2

is_odd_intFunction · 0.70
keep_ifFunction · 0.50

Tested by

no test coverage detected