libzypp  17.31.31
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 
69  template <class Container, class Elem>
70  bool contains ( const Container &c, const Elem &elem )
71  {
72  return ( std::find( c.begin(), c.end(), elem ) != c.end() );
73  }
74 
75  template <class Container, class Fnc >
76  bool any_of ( const Container &c, Fnc &&cb )
77  {
78  return std::any_of( c.begin(), c.end(), std::forward<Fnc>(cb) );
79  }
80 
82 } // namespace zypp
84 #endif // ZYPP_BASE_ALGORITHM_H
bool contains(const Container &c, const Elem &elem)
Definition: Algorithm.h:70
bool any_of(const Container &c, Fnc &&cb)
Definition: Algorithm.h:76
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