libzypp  13.10.6
Iterator.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_BASE_ITERATOR_H
13 #define ZYPP_BASE_ITERATOR_H
14 
15 #include <iterator>
16 #include <utility>
17 
18 #include <boost/functional.hpp>
19 #include <boost/iterator/filter_iterator.hpp>
20 #include <boost/iterator/transform_iterator.hpp>
21 #include <boost/function_output_iterator.hpp>
22 
24 namespace zypp
25 {
26 
66 
93  using boost::filter_iterator;
94  using boost::make_filter_iterator;
95 
97  template<class _Filter, class _Container>
99  make_filter_begin( _Filter f, const _Container & c )
100  {
101  return make_filter_iterator( f, c.begin(), c.end() );
102  }
103 
105  template<class _Filter, class _Container>
107  make_filter_begin( const _Container & c )
108  {
109  return make_filter_iterator( _Filter(), c.begin(), c.end() );
110  }
111 
113  template<class _Filter, class _Container>
115  make_filter_end( _Filter f, const _Container & c )
116  {
117  return make_filter_iterator( f, c.end(), c.end() );
118  }
119 
121  template<class _Filter, class _Container>
123  make_filter_end( const _Container & c )
124  {
125  return make_filter_iterator( _Filter(), c.end(), c.end() );
126  }
127 
146  using boost::transform_iterator;
147  using boost::make_transform_iterator;
148 
152  template<class _Pair>
153  struct GetPairFirst : public std::unary_function<_Pair, const typename _Pair::first_type &>
154  {
155  const typename _Pair::first_type & operator()( const _Pair & pair_r ) const
156  { return pair_r.first; }
157  };
158 
162  template<class _Pair>
163  struct GetPairSecond : public std::unary_function<_Pair, const typename _Pair::second_type &>
164  {
165  const typename _Pair::second_type & operator()( const _Pair & pair_r ) const
166  { return pair_r.second; }
167  };
168 
207  template<class _Map>
209  {
211  typedef _Map MapType;
213  typedef typename _Map::key_type KeyType;
215  typedef transform_iterator<GetPairFirst<typename MapType::value_type>,
216  typename MapType::const_iterator> Key_const_iterator;
218  typedef typename _Map::mapped_type ValueType;
220  typedef transform_iterator<GetPairSecond<typename MapType::value_type>,
221  typename MapType::const_iterator> Value_const_iterator;
222  };
223 
225  template<class _Map>
227  { return make_transform_iterator( map_r.begin(), GetPairFirst<typename _Map::value_type>() ); }
228 
230  template<class _Map>
232  { return make_transform_iterator( map_r.end(), GetPairFirst<typename _Map::value_type>() ); }
233 
235  template<class _Map>
237  { return make_transform_iterator( map_r.begin(), GetPairSecond<typename _Map::value_type>() ); }
238 
240  template<class _Map>
242  { return make_transform_iterator( map_r.end(), GetPairSecond<typename _Map::value_type>() ); }
243 
245  template<class _Map>
246  inline typename MapKVIteratorTraits<_Map>::Key_const_iterator make_map_key_lower_bound( const _Map & map_r, const typename _Map::key_type & key_r )
247  { return make_transform_iterator( map_r.lower_bound( key_r ), GetPairFirst<typename _Map::value_type>() ); }
248 
250  template<class _Map>
251  inline typename MapKVIteratorTraits<_Map>::Key_const_iterator make_map_key_upper_bound( const _Map & map_r, const typename _Map::key_type & key_r )
252  { return make_transform_iterator( map_r.upper_bound( key_r ), GetPairFirst<typename _Map::value_type>() ); }
253 
255  template<class _Map>
256  inline typename MapKVIteratorTraits<_Map>::Value_const_iterator make_map_value_lower_bound( const _Map & map_r, const typename _Map::key_type & key_r )
257  { return make_transform_iterator( map_r.lower_bound( key_r ), GetPairSecond<typename _Map::value_type>() ); }
258 
260  template<class _Map>
261  inline typename MapKVIteratorTraits<_Map>::Value_const_iterator make_map_value_upper_bound( const _Map & map_r, const typename _Map::key_type & key_r )
262  { return make_transform_iterator( map_r.upper_bound( key_r ), GetPairSecond<typename _Map::value_type>() ); }
263 
278  using boost::function_output_iterator;
279  using boost::make_function_output_iterator;
280 
282 } // namespace zypp
285 #endif // ZYPP_BASE_ITERATOR_H
MapKVIteratorTraits< _Map >::Value_const_iterator make_map_value_end(const _Map &map_r)
Convenience to create the value iterator from container::end()
Definition: Iterator.h:241
Functor taking a std::pair returning std::pair.second .
Definition: Iterator.h:163
MapKVIteratorTraits< _Map >::Key_const_iterator make_map_key_lower_bound(const _Map &map_r, const typename _Map::key_type &key_r)
Convenience to create the key iterator from container::lower_bound()
Definition: Iterator.h:246
transform_iterator< GetPairFirst< typename MapType::value_type >, typename MapType::const_iterator > Key_const_iterator
The key iterator type.
Definition: Iterator.h:216
An iterator over the subset of elements of some sequence which satisfy a given predicate.
filter_iterator< _Filter, typename _Container::const_iterator > make_filter_begin(_Filter f, const _Container &c)
Convenience to create filter_iterator from container::begin().
Definition: Iterator.h:99
transform_iterator< GetPairSecond< typename MapType::value_type >, typename MapType::const_iterator > Value_const_iterator
The value iterator type.
Definition: Iterator.h:221
Functor taking a std::pair returning std::pair.first.
Definition: Iterator.h:153
const _Pair::first_type & operator()(const _Pair &pair_r) const
Definition: Iterator.h:155
MapKVIteratorTraits< _Map >::Value_const_iterator make_map_value_begin(const _Map &map_r)
Convenience to create the value iterator from container::begin()
Definition: Iterator.h:236
MapKVIteratorTraits< _Map >::Value_const_iterator make_map_value_lower_bound(const _Map &map_r, const typename _Map::key_type &key_r)
Convenience to create the value iterator from container::lower_bound()
Definition: Iterator.h:256
_Map MapType
The map type.
Definition: Iterator.h:211
MapKVIteratorTraits< _Map >::Key_const_iterator make_map_key_upper_bound(const _Map &map_r, const typename _Map::key_type &key_r)
Convenience to create the key iterator from container::upper_bound()
Definition: Iterator.h:251
MapKVIteratorTraits< _Map >::Key_const_iterator make_map_key_begin(const _Map &map_r)
Convenience to create the key iterator from container::begin()
Definition: Iterator.h:226
_Map::mapped_type ValueType
The maps value (mapped) type.
Definition: Iterator.h:218
const _Pair::second_type & operator()(const _Pair &pair_r) const
Definition: Iterator.h:165
_Map::key_type KeyType
The maps key type.
Definition: Iterator.h:213
MapKVIteratorTraits< _Map >::Value_const_iterator make_map_value_upper_bound(const _Map &map_r, const typename _Map::key_type &key_r)
Convenience to create the value iterator from container::upper_bound()
Definition: Iterator.h:261
filter_iterator< _Filter, typename _Container::const_iterator > make_filter_end(_Filter f, const _Container &c)
Convenience to create filter_iterator from container::end().
Definition: Iterator.h:115
MapKVIteratorTraits< _Map >::Key_const_iterator make_map_key_end(const _Map &map_r)
Convenience to create the key iterator from container::end()
Definition: Iterator.h:231
Traits for std::map key and value iterators.
Definition: Iterator.h:208