From 2410aeb608329ed57a31315effdfd5a751788616 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Sun, 18 May 2014 02:43:55 -0700 Subject: Convert login/char and login/admin server components to proto-v2 --- src/compat/iter.hpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/compat/iter.hpp') diff --git a/src/compat/iter.hpp b/src/compat/iter.hpp index 130bdf9..659aca9 100644 --- a/src/compat/iter.hpp +++ b/src/compat/iter.hpp @@ -94,4 +94,58 @@ IteratorPair> value_range(T b, T e) return {b, e}; } + +template +class FilterIterator +{ + C *container; + using InnerIterator = decltype(std::begin(*container)); + InnerIterator impl; +public: + void post_adv() + { + while (impl != std::end(*container)) + { + if (filter(*impl)) + break; + ++impl; + } + } + + FilterIterator(C *c) + : container(c), impl(std::begin(*c)) + { + post_adv(); + } + + void operator ++() + { + ++impl; + post_adv(); + } + + T operator *() + { + return *impl; + } + + friend + bool operator != (FilterIterator l, FilterIterator) + { + return l.impl != std::end(*l.container); + } +}; + +template +bool is_truthy(T v) +{ + return v; +} + +template +IteratorPair> filter_iterator(C *c) +{ + return {FilterIterator(c), FilterIterator(c)}; +} + #endif // TMWA_COMPAT_ITER_HPP -- cgit v1.2.3-60-g2f50