libzypp  13.10.6
Algorithm.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_BASE_ALGORITHM_H
13 #define ZYPP_BASE_ALGORITHM_H
14 
15 #include <algorithm>
16 
18 namespace zypp
19 {
20 
29  template <class _Iterator, class _Filter, class _Function>
30  inline int invokeOnEach( _Iterator begin_r, _Iterator end_r,
31  _Filter filter_r,
32  _Function fnc_r )
33  {
34  int cnt = 0;
35  for ( _Iterator it = begin_r; it != end_r; ++it )
36  {
37  if ( filter_r( *it ) )
38  {
39  ++cnt;
40  if ( ! fnc_r( *it ) )
41  return -cnt;
42  }
43  }
44  return cnt;
45  }
46 
55  template <class _Iterator, class _Function>
56  inline int invokeOnEach( _Iterator begin_r, _Iterator end_r,
57  _Function fnc_r )
58  {
59  int cnt = 0;
60  for ( _Iterator it = begin_r; it != end_r; ++it )
61  {
62  ++cnt;
63  if ( ! fnc_r( *it ) )
64  return -cnt;
65  }
66  return cnt;
67  }
68 
70 } // namespace zypp
72 #endif // ZYPP_BASE_ALGORITHM_H
int invokeOnEach(_Iterator begin_r, _Iterator end_r, _Filter filter_r, _Function fnc_r)
Iterate through [begin_r,end_r) and invoke fnc_r on each item that passes filter_r.
Definition: Algorithm.h:30