10#include <tracking/trackFindingCDC/utilities/GetIterator.h>
21 namespace TrackFindingCDC {
24 template<
class AIterator>
25 class Range :
public std::pair<AIterator, AIterator> {
29 using Super = std::pair<AIterator, AIterator>;
39 using Reference =
typename std::iterator_traits<AIterator>::reference;
42 using value_type =
typename std::iterator_traits<AIterator>::value_type;
49 template<
class AOtherIterator>
50 explicit Range(
const std::pair<AOtherIterator, AOtherIterator>& itPair)
51 :
Super(AIterator(itPair.first), AIterator(itPair.second))
55 template<
class Ts,
class ItT = GetIterator<Ts>>
65 {
return this->first; }
69 {
return this->second; }
77 {
return std::distance(
begin(),
end()); }
81 {
return *(
begin()); }
85 {
return *(
end() - 1); }
89 {
return *(
begin() + i); }
94 if (not(i <
size())) {
95 throw std::out_of_range(
"Range : Requested index " + std::to_string(i) +
" is out of bounds.");
102 {
return std::count(this->
begin(), this->
end(), t); }
107 template<
class AIterator>
114 template<
class AIterator>
115 Range<AIterator> asRange(AIterator
const& itBegin, AIterator
const& itEnd)
117 return Range<AIterator>(std::make_pair(itBegin, itEnd));
Represents a range of arithmetic types.
A pair of iterators usable with the range base for loop.
Iterator iterator
Iterator definition for stl.
Iterator begin() const
Begin of the range for range based for.
typename std::iterator_traits< AIterator >::reference Reference
The type the iterator references.
Range(const std::pair< AOtherIterator, AOtherIterator > &itPair)
Constructor to adapt a pair as returned by e.g. std::equal_range.
Range()=default
Default constructor for ROOT.
Iterator end() const
End of the range for range based for.
bool empty() const
Checks if the begin equals the end iterator, hence if the range is empty.
Reference back() const
Returns the dereferenced iterator before end()
Reference operator[](std::size_t i) const
Returns the object at index i.
bool count(Reference t)
Counts the number of equivalent items in the range.
std::pair< AIterator, AIterator > Super
Type of the base class.
Reference front() const
Returns the dereferenced iterator at begin()
AIterator Iterator
Iterator type of the range.
std::size_t size() const
Returns the total number of objects in this range.
Reference at(std::size_t i) const
Returns the object at index i.
typename std::iterator_traits< AIterator >::value_type value_type
The type behind the iterator (make it possible to use the range as a "list")
Range(const Ts &ts)
Constructor from another range.
Abstract base class for different kinds of events.