libzypp  11.13.5
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 
283 } // namespace zypp
285 #endif // ZYPP_BASE_ITERATOR_H