summaryrefslogtreecommitdiff
path: root/src/compat
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2014-05-27 18:04:02 -0700
committerBen Longbons <b.r.longbons@gmail.com>2014-05-27 18:04:02 -0700
commit8ce2f240dba5bdd0ca47ac25f16f140d8d1744fc (patch)
treec7e58cc4dbb261adcdb0db62b69da95189bccc98 /src/compat
parentaf4acff261d579428e8eef042cc5359fa392f725 (diff)
downloadtmwa-8ce2f240dba5bdd0ca47ac25f16f140d8d1744fc.tar.gz
tmwa-8ce2f240dba5bdd0ca47ac25f16f140d8d1744fc.tar.bz2
tmwa-8ce2f240dba5bdd0ca47ac25f16f140d8d1744fc.tar.xz
tmwa-8ce2f240dba5bdd0ca47ac25f16f140d8d1744fc.zip
Was the bug in my code or in the compiler? Who knows?
Diffstat (limited to 'src/compat')
-rw-r--r--src/compat/iter.hpp14
-rw-r--r--src/compat/iter_test.cpp2
2 files changed, 9 insertions, 7 deletions
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<ValueIterator<T>> value_range(T b, T e)
}
-template<class T, bool(*filter)(T), class C>
+template<class T, class F, class C>
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<class T, bool(*filter)(T)=is_truthy, class C>
-IteratorPair<FilterIterator<T, filter, C>> filter_iterator(C *c)
+template<class T, class F=decltype(is_truthy<T>)*, class C>
+IteratorPair<FilterIterator<T, F, C>> filter_iterator(C *c, F f=is_truthy<T>)
{
- return {FilterIterator<T, filter, C>(c), FilterIterator<T, filter, C>(c)};
+ return {FilterIterator<T, F, C>(c, f), FilterIterator<T, F, C>(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<int&, is_odd_ref>(&arr))
+ for (int& i : filter_iterator<int&>(&arr, is_odd_ref))
{
EXPECT_EQ(i, *expected_it);
++expected_it;