17 #ifndef TRSL_PERSISTENT_FILTER_ITERATOR_23022003THW_HPP
18 #define TRSL_PERSISTENT_FILTER_ITERATOR_23022003THW_HPP
20 #include <boost/iterator.hpp>
21 #include <boost/iterator/iterator_adaptor.hpp>
22 #include <boost/iterator/iterator_categories.hpp>
24 #include <boost/type_traits/is_class.hpp>
25 #include <boost/static_assert.hpp>
29 template <
class Predicate,
class Iterator>
35 template <
class Predicate,
class Iterator>
38 typedef boost::iterator_adaptor<
42 ,
typename boost::mpl::if_<
43 boost::is_convertible<
44 typename boost::iterator_traversal<Iterator>::type
45 , boost::random_access_traversal_tag
48 , boost::forward_traversal_tag
50 , boost::forward_traversal_tag
92 template <
class Predicate,
class Iterator>
100 friend class boost::iterator_core_access;
105 persistent_filter_iterator(Predicate f, Iterator x, Iterator end_ = Iterator())
106 : super_t(x), m_predicate(f), m_end(end_)
111 persistent_filter_iterator(Iterator x, Iterator end_ = Iterator())
112 : super_t(x), m_predicate(), m_end(end_)
116 #if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
119 BOOST_STATIC_ASSERT(boost::is_class<Predicate>::value);
124 template<
class OtherIterator>
125 persistent_filter_iterator(
126 persistent_filter_iterator<Predicate, OtherIterator>
const& t
127 ,
typename boost::enable_if_convertible<OtherIterator, Iterator>::type* = 0
129 : super_t(t.base()), m_predicate(t.predicate()), m_end(t.end()) {}
131 Predicate predicate()
const {
return m_predicate; }
133 Iterator end()
const {
return m_end; }
147 void satisfy_predicate()
149 while (this->base() != this->m_end && !this->m_predicate(*this->base()))
150 ++(this->base_reference());
153 template<
class OtherIterator>
155 persistent_filter_iterator<Predicate, OtherIterator>
const& t
156 ,
typename boost::enable_if_convertible<OtherIterator, Iterator>::type* = 0
159 return (this->base() == t.base()) &&
161 ((this->base() == m_end) ||
162 (this->predicate() == t.predicate()));
167 Predicate m_predicate;
171 template <
class Predicate,
class Iterator>
172 persistent_filter_iterator<Predicate,Iterator>
173 make_persistent_filter_iterator(Predicate f, Iterator x, Iterator end = Iterator())
175 return persistent_filter_iterator<Predicate,Iterator>(f,x,end);
178 template <
class Predicate,
class Iterator>
179 persistent_filter_iterator<Predicate,Iterator>
180 make_persistent_filter_iterator(
181 typename boost::iterators::enable_if<
182 boost::is_class<Predicate>
185 , Iterator end = Iterator()
186 #
if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
191 return persistent_filter_iterator<Predicate,Iterator>(x,end);
196 #endif // TRSL_PERSISTENT_FILTER_ITERATOR_23022003THW_HPP