24 #ifndef util_PairIter_hpp
25 #define util_PairIter_hpp
39 template<
class IterType ,
41 typename std::iterator_traits< IterType >::iterator_category >
51 template<
class IterType >
52 class PairIter< IterType , std::random_access_iterator_tag >
53 :
public std::pair< IterType , IterType >
56 typedef std::pair< IterType , IterType > Pair ;
58 typedef std::iterator_traits< IterType > Traits ;
63 typedef IterType iterator ;
64 typedef typename Traits::value_type value_type ;
65 typedef typename Traits::pointer pointer ;
66 typedef typename Traits::reference reference ;
67 typedef typename Traits::difference_type difference_type ;
68 typedef size_t size_type ;
74 PairIter() : Pair() { Pair::second = Pair::first ; }
78 PairIter(
const Pair & rhs ) : Pair( rhs ) {}
80 Self & operator = (
const Self & rhs )
81 { Pair::first = rhs.first ; Pair::second = rhs.second ;
return *this ; }
83 Self & operator = (
const Pair & rhs )
84 { Pair::first = rhs.first ; Pair::second = rhs.second ;
return *this ; }
88 bool operator == (
const Self & rhs )
const
89 {
return Pair::first == rhs.first && Pair::second == rhs.second ; }
91 bool operator != (
const Self & rhs )
const
92 {
return Pair::first != rhs.first || Pair::second != rhs.second ; }
94 bool operator == (
const Pair & rhs )
const
95 {
return Pair::first == rhs.first && Pair::second == rhs.second ; }
97 bool operator != (
const Pair & rhs )
const
98 {
return Pair::first != rhs.first || Pair::second != rhs.second ; }
102 Self & operator ++ () { ++ Pair::first ;
return *this ; }
104 Self operator ++ (
int) {
Self tmp(*
this); ++ Pair::first ;
return tmp ; }
106 reference operator * ()
const {
return * Pair::first ; }
107 pointer operator -> ()
const {
return & * Pair::first ; }
112 reference front()
const {
return * Pair::first ; }
113 reference back()
const {
return Pair::second[-1] ; }
115 iterator begin()
const {
return Pair::first ; }
116 iterator end()
const {
return Pair::second ; }
118 template<
class Iterator>
119 PairIter( Iterator i , Iterator e ) : Pair(i,e) {}
121 template<
class Container>
123 PairIter(
const Container & c ) : Pair( c.begin() , c.end() ) {}
125 template<
class Container>
127 PairIter( Container & c ) : Pair( c.begin() , c.end() ) {}
129 bool empty ()
const {
return ! ( Pair::first < Pair::second ) ; }
131 operator bool ()
const {
return Pair::first < Pair::second ; }
133 reference operator [] (
size_t n )
const {
return Pair::first[n] ; }
137 const difference_type d = std::distance( Pair::first , Pair::second );
138 return d < 0 ? 0 : (size_t) d ;
Pair of begin and end iterators wrapped to provide a container-like view of the span.
Pair of begin and end iterators wrapped to provide a container-like view of the span.