From 8ce2f240dba5bdd0ca47ac25f16f140d8d1744fc Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Tue, 27 May 2014 18:04:02 -0700 Subject: Was the bug in my code or in the compiler? Who knows? --- src/compat/iter.hpp | 14 ++++++++------ src/compat/iter_test.cpp | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/compat/iter.hpp b/src/compat/iter.hpp index 659aca9..08c139e 100644 --- a/src/compat/iter.hpp +++ b/src/compat/iter.hpp @@ -95,10 +95,12 @@ IteratorPair> value_range(T b, T e) } -template +template class FilterIterator { + F filter; C *container; + using InnerIterator = decltype(std::begin(*container)); InnerIterator impl; public: @@ -112,8 +114,8 @@ public: } } - FilterIterator(C *c) - : container(c), impl(std::begin(*c)) + FilterIterator(C *c, F f) + : filter(f), container(c), impl(std::begin(*c)) { post_adv(); } @@ -142,10 +144,10 @@ bool is_truthy(T v) return v; } -template -IteratorPair> filter_iterator(C *c) +template)*, class C> +IteratorPair> filter_iterator(C *c, F f=is_truthy) { - return {FilterIterator(c), FilterIterator(c)}; + return {FilterIterator(c, f), FilterIterator(c, f)}; } #endif // TMWA_COMPAT_ITER_HPP diff --git a/src/compat/iter_test.cpp b/src/compat/iter_test.cpp index f6f59d4..b9bfb6a 100644 --- a/src/compat/iter_test.cpp +++ b/src/compat/iter_test.cpp @@ -117,7 +117,7 @@ TEST(iterpair, filter1) int *expected_it = expected_arr; int *expected_end = expected_arr + 4; - for (int& i : filter_iterator(&arr)) + for (int& i : filter_iterator(&arr, is_odd_ref)) { EXPECT_EQ(i, *expected_it); ++expected_it; -- cgit v1.2.3-70-g09d2