trsl logo
ppfilter_iterator.hpp
Go to the documentation of this file.
1 // (C) Copyright Renaud Detry 2008-2011.
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 
8 #ifndef TRSL_PPFILTER_ITERATOR_HPP
9 #define TRSL_PPFILTER_ITERATOR_HPP
10 
11 #include <trsl/error_handling.hpp>
12 #include <trsl/common.hpp>
13 
17 
18 namespace trsl
19 {
20  template<class Predicate, class ElementIterator>
22 
23  namespace detail
24  {
26  template<class Predicate, class ElementIterator>
28  {
29  typedef Predicate predicate_t;
30  typedef ElementIterator element_iterator;
31 
35 
36  typedef boost::iterator_adaptor<
39  typename boost::detail::iterator_traits<ElementIterator>::value_type,
40  boost::forward_traversal_tag,
41  typename boost::detail::iterator_traits<ElementIterator>::reference
42  > type;
43  };
44  }
45 
46 
57  template<class Predicate, class ElementIterator>
58  class ppfilter_iterator
59  : public detail::ppfilter_iterator_base<Predicate, ElementIterator>::type
60  {
62  typedef typename base_t::type super_t;
63 
64  friend class boost::iterator_core_access;
65 
66  typedef typename base_t::upstream_iterator upstream_iterator;
67  typedef typename base_t::downstream_iterator downstream_iterator;
68 
69  public:
70 
71  typedef typename base_t::element_iterator element_iterator;
72 
74  super_t(), predicate_()
75  {}
76 
80  explicit ppfilter_iterator(Predicate f,
81  ElementIterator first, ElementIterator last)
82  : super_t(), predicate_(f)
83  {
85  this->base_reference() = downstream_iterator(f, ui.begin(), ui.end());
86  }
87 
97  template<class OtherElementIterator>
100  typename boost::enable_if_convertible<OtherElementIterator, ElementIterator>::type* = 0) :
101  super_t(r.base()), predicate_(r.predicate_)
102  {}
103 
109  {
111  i.base_reference() =
112  downstream_iterator(predicate_,
113  this->base_reference().base().begin(),
114  this->base_reference().base().end());
115  return i;
116  }
117 
123  {
125  i.base_reference() = downstream_iterator(predicate_,
126  this->base_reference().base().end(),
127  this->base_reference().base().end());
128  return i;
129  }
130 
135  typename upstream_iterator::index_t index() const
136  { return this->base().base().index(); }
137 
141  Predicate predicate() const { return this->base_reference().predicate(); }
142 
143  private:
144 
145 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
146  template <class, class> friend class ppfilter_iterator;
147 #else
148  public:
149 #endif
150  // Need to store the predicate to implement begin().
151  // Else, a predicate_.reset() method would be required.
152  Predicate predicate_;
153  };
154 
155 } // namespace trsl
156 
157 #endif // include guard
trsl::reorder_iterator::begin
reorder_iterator< ElementIterator > begin() const
Returns a reorder_iterator pointing to the begining of the permutation.
Definition: reorder_iterator.hpp:152
common.hpp
trsl::ppfilter_iterator::predicate
Predicate predicate() const
Returns the persistent_filter_iterator predicate.
Definition: ppfilter_iterator.hpp:141
trsl::reorder_iterator::end
reorder_iterator< ElementIterator > end() const
Returns a reorder_iterator pointing to the end of the permutation.
Definition: reorder_iterator.hpp:164
trsl
Public namespace.
Definition: common.hpp:29
trsl::ppfilter_iterator::ppfilter_iterator
ppfilter_iterator(Predicate f, ElementIterator first, ElementIterator last)
Constructor.
Definition: ppfilter_iterator.hpp:80
random_permutation_iterator.hpp
trsl::ppfilter_iterator::begin
ppfilter_iterator< Predicate, ElementIterator > begin() const
Returns a ppfilter_iterator pointing to the begining of the range.
Definition: ppfilter_iterator.hpp:108
trsl::ppfilter_iterator
Random permutation, persistent filter iterator.
Definition: ppfilter_iterator.hpp:21
trsl::ppfilter_iterator::index
upstream_iterator::index_t index() const
Returns the index of the element that the iterator is currently pointing to.
Definition: ppfilter_iterator.hpp:135
error_handling.hpp
reorder_iterator.hpp
trsl::reorder_iterator
Provides an iterator over a permutation of a range.
Definition: reorder_iterator.hpp:31
trsl::ppfilter_iterator::end
ppfilter_iterator< Predicate, ElementIterator > end() const
Returns a ppfilter_iterator pointing to the end of the range.
Definition: ppfilter_iterator.hpp:122
trsl::detail::ppfilter_iterator_base
Used internally.
Definition: ppfilter_iterator.hpp:27
trsl::random_permutation_iterator
reorder_iterator< ElementIterator > random_permutation_iterator(ElementIterator first, ElementIterator last, unsigned permutationSize)
Constructs a reorder_iterator that will iterate through a random subset of size permutationSize of a ...
Definition: random_permutation_iterator.hpp:40
persistent_filter_iterator.hpp
trsl::persistent_filter_iterator
Adaptation of boost::filter_iterator to allow an element to be selected multiple times.
Definition: persistent_filter_iterator.hpp:30
© Copyright 2007-2011 Renaud Detry.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at www.boost.org/LICENSE_1_0.txt.)
Revised Wed Jan 8 2020 14:43:31.