4 #define GAUDI_RANGE_H 1
13 #include "GaudiKernel/Kernel.h"
52 struct RangeBase_ {} ;
76 template <
class CONTAINER>
77 class Range_ :
public RangeBase_
81 typedef std::pair<
typename CONTAINER::const_iterator,
82 typename CONTAINER::const_iterator>
Base ;
88 typedef typename Container::value_type
value_type ;
89 typedef typename Container::const_iterator
iterator ;
93 typedef typename Container::const_reference
reference ;
96 typedef std::pair<iterator,iterator>
_Base ;
97 typedef Range_<Container>
_Self ;
107 Range_( iterator ibegin , iterator iend ) :
m_base ( ibegin , iend ) {}
119 Range_( iterator ibegin ) :
m_base( ibegin , ibegin ) {}
126 inline size_t size ()
const
127 {
return std::distance (
m_base.first ,
m_base.second ) ; }
142 std::advance ( i , -1 ) ;
147 inline Range_ slice(
long index1 ,
long index2 )
const
150 if (
empty() || index1 == index2 ) {
return Range_() ; }
152 if ( index1 < 0 ) { index1 +=
size () ; }
153 if ( index2 < 0 ) { index2 +=
size () ; }
155 if ( index1 < 0 ) {
return Range_ () ; }
156 if ( index2 < index1 ) {
return Range_ () ; }
158 if ( index1 > (
long) size () ) {
return Range_() ; }
159 if ( index2 > (
long) size () ) { index2 =
size() ; }
162 std::advance ( i1 , index1 ) ;
164 std::advance ( i2 , index2 ) ;
166 return Range_( i1 , i2 ) ;
176 std::advance ( i , index ) ;
184 {
return (*
this)( index ) ; }
192 if ( index < 0 || index >= (
long) size () )
194 return (*
this) ( index );
200 bool operator< (
const Range_& right )
const
202 return std::lexicographical_compare
203 ( begin () ,
end () , right.begin () , right.end () ) ;
206 bool operator< (
const Container& right )
const
208 return std::lexicographical_compare
209 ( begin () ,
end () , right.begin () , right.end () ) ;
217 if ( &right ==
this ) {
return true ; }
218 if ( right.size () !=
size () ) {
return false ; }
219 return std::equal ( begin () ,
end () , right.begin() ) ;
222 bool operator==(
const Container& right )
const
224 if ( right.size () !=
size () ) {
return false ; }
225 return std::equal ( begin () ,
end () , right.begin() ) ;
236 operator const Base& ()
const {
return base () ; }
274 template <
class CONTAINER>
277 range (
const CONTAINER& cnt )
278 {
return Range_<CONTAINER>( cnt.begin() , cnt.end() ) ; }
284 #endif // GAUDI_RANGE_H