1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/base/Iterator.h
12 #ifndef ZYPP_BASE_ITERATOR_H
13 #define ZYPP_BASE_ITERATOR_H
15 #include <boost/iterator/filter_iterator.hpp>
16 #include <boost/iterator/transform_iterator.hpp>
17 #include <boost/function_output_iterator.hpp>
19 ///////////////////////////////////////////////////////////////////
21 { /////////////////////////////////////////////////////////////////
23 /** \defgroup ITERATOR Boost.Iterator Library
25 * \see http://www.boost.org/libs/iterator/doc/index.html
27 * \li \b counting_iterator: an iterator over a sequence of
28 * consecutive values. Implements a "lazy sequence"
29 * \li \b filter_iterator: an iterator over the subset of elements
30 * of some sequence which satisfy a given predicate
31 * \li \b function_output_iterator: an output iterator wrapping a
32 * unary function object; each time an element is written into
33 * the dereferenced iterator, it is passed as a parameter to
34 * the function object.
35 * \li \b indirect_iterator: an iterator over the objects pointed-to
36 * by the elements of some sequence.
37 * \li \b permutation_iterator: an iterator over the elements of
38 * some random-access sequence, rearranged according to some
39 * sequence of integer indices.
40 * \li \b reverse_iterator: an iterator which traverses the elements
41 * of some bidirectional sequence in reverse. Corrects many of the shortcomings of C++98's std::reverse_iterator.
42 * \li \b shared_container_iterator: an iterator over elements of
43 * a container whose lifetime is maintained by a shared_ptr
44 * stored in the iterator.
45 * \li \b transform_iterator: an iterator over elements which are
46 * the result of applying some functional transformation to
47 * the elements of an underlying sequence. This component
48 * also replaces the old projection_iterator_adaptor.
49 * \li \b zip_iterator: an iterator over tuples of the elements
50 * at corresponding positions of heterogeneous underlying
53 * There are in fact more interesting iterator concepts
54 * available than the ones listed above. Have a look at them.
56 * Some of the iterator types are already dragged into namespace
57 * zypp. Feel free to add what's missing.
59 * \todo Separate them into individual zypp header files.
63 /** \class filter_iterator
64 * An iterator over the subset of elements of some sequence
65 * which satisfy a given predicate.
67 * Provides boost::filter_iterator and boost::make_filter_iterator
68 * convenience function.
69 * \see http://www.boost.org/libs/iterator/doc/filter_iterator.html
71 * template <class Predicate, class Iterator>
72 * filter_iterator<Predicate,Iterator>
73 * make_filter_iterator(Predicate f, Iterator x, Iterator end = Iterator());
75 * template <class Predicate, class Iterator>
76 * filter_iterator<Predicate,Iterator>
77 * make_filter_iterator(Iterator x, Iterator end = Iterator());
79 * Remember the deduction rules for template arguments.
81 * struct MyDefaultConstructibleFilter;
82 * make_filter_iterator<MyDefaultConstructibleFilter>( c.begin(), c.end() );
83 * make_filter_iterator( MyDefaultConstructibleFilter(), c.begin(), c.end() );
85 * make_filter_iterator( resfilter::ByName("foo"), c.begin(), c.end() );
89 using boost::filter_iterator;
90 using boost::make_filter_iterator;
92 /** Convenience to create filter_iterator from container::begin(). */
93 template<class _Filter, class _Container>
94 filter_iterator<_Filter, typename _Container::const_iterator>
95 make_filter_begin( _Filter f, const _Container & c )
97 return make_filter_iterator( f, c.begin(), c.end() );
100 /** Convenience to create filter_iterator from container::end(). */
101 template<class _Filter, class _Container>
102 filter_iterator<_Filter, typename _Container::const_iterator>
103 make_filter_end( _Filter f, const _Container & c )
105 return make_filter_iterator( f, c.end(), c.end() );
108 /** \class transform_iterator
109 * An iterator over elements which are the result of applying
110 * some functional transformation to the elements of an underlying
113 * Provides boost::transform_iterator and boost::make_transform_iterator
114 * convenience function.
115 * \see http://www.boost.org/libs/iterator/doc/transform_iterator.html
117 * template <class UnaryFunction, class Iterator>
118 * transform_iterator<UnaryFunction, Iterator>
119 * make_transform_iterator(Iterator it, UnaryFunction fun);
121 * template <class UnaryFunction, class Iterator>
122 * transform_iterator<UnaryFunction, Iterator>
123 * make_transform_iterator(Iterator it);
126 using boost::transform_iterator;
127 using boost::make_transform_iterator;
129 /** \class function_output_iterator
130 * An output iterator wrapping a unary function object; each time an
131 * element is written into the dereferenced iterator, it is passed as
132 * a parameter to the function object.
134 * Provides boost::function_output_iterator and boost::make_function_output_iterator
135 * convenience function.
136 * \see http://www.boost.org/libs/iterator/doc/function_output_iterator.html
138 * template <class UnaryFunction>
139 * function_output_iterator<UnaryFunction>
140 * make_function_output_iterator(const UnaryFunction& f = UnaryFunction());
143 using boost::function_output_iterator;
144 using boost::make_function_output_iterator;
147 /////////////////////////////////////////////////////////////////
149 ///////////////////////////////////////////////////////////////////
150 #endif // ZYPP_BASE_ITERATOR_H