libzypp: zypp-core/base/Iterable.h Source File

libzypp 17.38.6

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
17namespace zypp
18{
35 template <class TIterator>
36 class Iterable
37 {
38 public:
39 using size_type = size_t;
40 using iterator_type = TIterator;
41 using value_type = typename std::iterator_traits<iterator_type>::value_type;
42 using difference_type = typename std::iterator_traits<iterator_type>::difference_type;
43 using pointer = typename std::iterator_traits<iterator_type>::pointer;
44 using reference = typename std::iterator_traits<iterator_type>::reference;
45 using iterator_category = typename std::iterator_traits<iterator_type>::iterator_category;
46
48 Iterable()
49 {}
50
52 Iterable( iterator_type begin_r, iterator_type end_r )
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
63 iterator_type begin() const
64 { return _begin; }
65
66 iterator_type end() const
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:
82 iterator_type _begin;
83 iterator_type _end;
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::move(range_r) ); }
95} // namespace zypp
97#endif // ZYPP_BASE_ITERABLE_H
zypp::Iterable
Definition Iterable.h:37
zypp::Iterable::begin
iterator_type begin() const
Definition Iterable.h:63
zypp::Iterable::Iterable
Iterable()
Ctor taking the iterator pair.
Definition Iterable.h:48
zypp::Iterable::size
size_type size() const
Definition Iterable.h:72
zypp::Iterable< detail::RepositoryIterator >::_begin
iterator_type _begin
Definition Iterable.h:82
zypp::Iterable< detail::RepositoryIterator >::difference_type
typename std::iterator_traits< iterator_type >::difference_type difference_type
Definition Iterable.h:42
zypp::Iterable< detail::RepositoryIterator >::iterator_category
typename std::iterator_traits< iterator_type >::iterator_category iterator_category
Definition Iterable.h:45
zypp::Iterable::find
iterator_type find(const value_type &val_r) const
Definition Iterable.h:78
zypp::Iterable< detail::RepositoryIterator >::size_type
size_t size_type
Definition Iterable.h:39
zypp::Iterable< detail::RepositoryIterator >::iterator_type
detail::RepositoryIterator iterator_type
Definition Iterable.h:40
zypp::Iterable::empty
bool empty() const
Definition Iterable.h:69
zypp::Iterable< detail::RepositoryIterator >::value_type
typename std::iterator_traits< iterator_type >::value_type value_type
Definition Iterable.h:41
zypp::Iterable< detail::RepositoryIterator >::_end
iterator_type _end
Definition Iterable.h:83
zypp::Iterable< detail::RepositoryIterator >::pointer
typename std::iterator_traits< iterator_type >::pointer pointer
Definition Iterable.h:43
zypp::Iterable::Iterable
Iterable(std::pair< iterator_type, iterator_type > range_r)
Ctor taking the iterator pair.
Definition Iterable.h:58
zypp::Iterable::contains
bool contains(const value_type &val_r) const
Definition Iterable.h:75
zypp::Iterable::Iterable
Iterable(iterator_type begin_r, iterator_type end_r)
Ctor taking the iterator pair.
Definition Iterable.h:52
zypp::Iterable::end
iterator_type end() const
Definition Iterable.h:66
zypp::Iterable< detail::RepositoryIterator >::reference
typename std::iterator_traits< iterator_type >::reference reference
Definition Iterable.h:44
std
Definition ansi.h:855
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::makeIterable
Iterable< TIterator > makeIterable(TIterator &&begin_r, TIterator &&end_r)
relates: Iterable convenient construction.
Definition Iterable.h:88