libzypp  17.14.0
Iterable.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
11 #ifndef ZYPP_BASE_ITERABLE_H
12 #define ZYPP_BASE_ITERABLE_H
13 
14 #include <iterator>
15 
17 namespace zypp
18 {
35  template <class TIterator>
36  class Iterable
37  {
38  public:
39  typedef size_t size_type;
40  typedef TIterator iterator_type;
41  typedef typename std::iterator_traits<iterator_type>::value_type value_type;
42  typedef typename std::iterator_traits<iterator_type>::difference_type difference_type;
43  typedef typename std::iterator_traits<iterator_type>::pointer pointer;
44  typedef typename std::iterator_traits<iterator_type>::reference reference;
45  typedef typename std::iterator_traits<iterator_type>::iterator_category iterator_category;
46 
49  {}
50 
53  : _begin( std::move(begin_r) )
54  , _end( std::move(end_r) )
55  {}
56 
58  Iterable( std::pair<iterator_type,iterator_type> range_r )
59  : _begin( std::move(range_r.first) )
60  , _end( std::move(range_r.second) )
61  {}
62 
64  { return _begin; }
65 
67  { return _end; }
68 
69  bool empty() const
70  { return( _begin == _end ); }
71 
72  size_type size() const
73  { size_type ret = 0; for ( iterator_type i = _begin; i != _end; ++i ) ++ret; return ret; }
74 
75  bool contains( const value_type & val_r ) const
76  { return( find( val_r ) != _end ); }
77 
78  iterator_type find( const value_type & val_r ) const
79  { iterator_type ret = _begin; for ( ; ret != _end; ++ret ) if ( *ret == val_r ) break; return ret; }
80 
81  private:
84  };
85 
87  template <class TIterator>
88  Iterable<TIterator> makeIterable( TIterator && begin_r, TIterator && end_r )
89  { return Iterable<TIterator>( std::forward<TIterator>(begin_r), std::forward<TIterator>(end_r) ); }
90 
92  template <class TIterator>
93  Iterable<TIterator> makeIterable( std::pair<TIterator,TIterator> && range_r )
94  { return Iterable<TIterator>( std::forward<std::pair<TIterator,TIterator>>(range_r) ); }
95 } // namespace zypp
97 #endif // ZYPP_BASE_ITERABLE_H
iterator_type _begin
Definition: Iterable.h:82
iterator_type end() const
Definition: Iterable.h:66
bool empty() const
Definition: Iterable.h:69
Iterable< TIterator > makeIterable(std::pair< TIterator, TIterator > &&range_r)
Definition: Iterable.h:93
Definition: Arch.h:344
iterator_type find(const value_type &val_r) const
Definition: Iterable.h:78
Iterable(iterator_type begin_r, iterator_type end_r)
Ctor taking the iterator pair.
Definition: Iterable.h:52
bool contains(const value_type &val_r) const
Definition: Iterable.h:75
iterator_type begin() const
Definition: Iterable.h:63
iterator_type _end
Definition: Iterable.h:83
std::iterator_traits< iterator_type >::difference_type difference_type
Definition: Iterable.h:42
TIterator iterator_type
Definition: Iterable.h:40
Iterable(std::pair< iterator_type, iterator_type > range_r)
Ctor taking the iterator pair.
Definition: Iterable.h:58
Iterable< TIterator > makeIterable(TIterator &&begin_r, TIterator &&end_r)
Definition: Iterable.h:88
std::iterator_traits< iterator_type >::reference reference
Definition: Iterable.h:44
std::iterator_traits< iterator_type >::iterator_category iterator_category
Definition: Iterable.h:45
std::iterator_traits< iterator_type >::value_type value_type
Definition: Iterable.h:41
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
size_t size_type
Definition: Iterable.h:39
size_type size() const
Definition: Iterable.h:72
Iterable()
Ctor taking the iterator pair.
Definition: Iterable.h:48
std::iterator_traits< iterator_type >::pointer pointer
Definition: Iterable.h:43