libzypp  17.3.0
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 TIterator, class TFilter, class TFunction>
30  inline int invokeOnEach( TIterator begin_r, TIterator end_r,
31  TFilter filter_r,
32  TFunction fnc_r )
33  {
34  int cnt = 0;
35  for ( TIterator 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 TIterator, class TFunction>
56  inline int invokeOnEach( TIterator begin_r, TIterator end_r,
57  TFunction fnc_r )
58  {
59  int cnt = 0;
60  for ( TIterator 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(TIterator begin_r, TIterator end_r, TFilter filter_r, TFunction fnc_r)
Iterate through [begin_r,end_r) and invoke fnc_r on each item that passes filter_r.
Definition: Algorithm.h:30
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1