ATLAS Offline Software
Loading...
Searching...
No Matches
RangedItr.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef DERIVATIONFRAMEWORKTRIGGER_RANGEDITR_H
6#define DERIVATIONFRAMEWORKTRIGGER_RANGEDITR_H
7
8
9#include <iterator> //std::distance, iterator_traits
10#include <type_traits>
11
12namespace DerivationFramework { namespace TriggerMatchingUtils {
17template <typename T>
18 class RangedItr {
19 protected:
20 using tr = std::iterator_traits<T>;
21 static_assert(std::is_base_of<std::bidirectional_iterator_tag, typename tr::iterator_category>::value, "Templated type must be a random access iterator");
22 public:
23 // A full implementation of this idea would allow for any input
24 // iterator type. For this version, just require at least bidirectional
25
26 using iterator_category = std::bidirectional_iterator_tag;
27 using value_type = typename tr::value_type;
28 using reference = typename tr::reference;
29 using pointer = typename tr::pointer;
30 using difference_type = typename tr::difference_type;
31
33 RangedItr() = default;
34
36 RangedItr(const T& begin, const T& end) :
38
40 RangedItr(const T& begin, const T& end, const T& position) :
41 m_begin(begin), m_end(end), m_position(position) {}
42
44 reference operator*() { return m_position.operator*(); }
45 pointer operator->() { return m_position.operator->(); }
46
48 ++m_position;
49 return *this;
50 }
52 RangedItr ret = *this;
53 ++m_position;
54 return ret;
55 }
56
58 --m_position;
59 return *this;
60 }
62 RangedItr ret = *this;
63 --m_position;
64 return ret;
65 }
66
67 bool operator==(const RangedItr& other) {
68 return m_begin == other.m_begin &&
69 m_end == other.m_end &&
70 m_position == other.m_position;
71 }
72
73 bool operator!=(const RangedItr& other) {
74 return !(*this == other);
75 }
76
78 bool exhausted() const { return m_position == m_end; }
79
82
85 RangedItr end() const { return RangedItr(m_begin, m_end, m_end); }
86 difference_type size() const { return std::distance(m_begin, m_end); }
87
89 operator T() const { return m_position; }
90 private:
94
95 }; //> end class RangedItr
96} } //> end namespace DerivationFramework::TriggerMatchingUtils
97#endif //> !DERIVATIONFRAMEWORKTRIGGER_RANGEDITR_H
RangedItr(const T &begin, const T &end)
Construct from a beginning and an end.
Definition RangedItr.h:36
bool exhausted() const
Is this iterator exhausted?
Definition RangedItr.h:78
RangedItr begin() const
Make this act as a range.
Definition RangedItr.h:84
RangedItr(const T &begin, const T &end, const T &position)
Construct from a beginning, an end and a starting position.
Definition RangedItr.h:40
std::bidirectional_iterator_tag iterator_category
Definition RangedItr.h:26
void restart()
Reset this iterator to its start.
Definition RangedItr.h:81
THE reconstruction tool.