16 #include <type_traits>
68 void checkIntegralType() {
69 static_assert(std::is_integral<T>::value,
"Only integral types are supported.");
76 using difference_type =
typename std::make_signed<T>::type;
78 TSeq(T theEnd): fBegin(), fEnd(theEnd), fStep(1) {
81 TSeq(T theBegin, T theEnd, T theStep = 1):
82 fBegin(theBegin), fEnd(theEnd), fStep(theStep) {
86 class iterator:
public std::iterator<std::random_access_iterator_tag, T, difference_type> {
91 iterator(T start, T step): fCounter(start), fStep(step) {}
96 bool operator==(
const iterator &other)
const {
97 return fCounter == other.fCounter;
100 bool operator!=(
const iterator &other)
const {
101 return fCounter != other.fCounter;
104 iterator operator+(difference_type v)
const {
105 return iterator(fCounter + v * fStep, fStep);
108 iterator operator-(difference_type v)
const {
109 return iterator(fCounter - v * fStep, fStep);
112 difference_type operator-(
const iterator &other)
const {
113 return (fCounter - other.fCounter) / fStep;
116 iterator &operator++() {
120 iterator operator++(
int) {
126 iterator &operator--() {
130 iterator operator--(
int) {
136 iterator &operator+=(
const difference_type& v) {
140 iterator &operator-=(
const difference_type& v) {
145 bool operator <(
const iterator &other)
const {
146 return (other - *
this) > 0;
148 bool operator >(
const iterator &other)
const {
149 return other < *
this;
151 bool operator <=(
const iterator &other)
const {
152 return !(*
this > other);
154 bool operator >=(
const iterator &other)
const {
155 return !(other > *
this);
158 const T operator[](
const difference_type& v)
const{
163 iterator begin()
const {
164 return iterator(fBegin, fStep);
166 iterator end()
const {
167 auto isStepMultiple = (fEnd - fBegin) % fStep == 0;
168 auto theEnd = isStepMultiple ? fEnd : fStep * (((fEnd - fBegin) / fStep) + 1) + fBegin;
169 return iterator(theEnd, fStep);
172 T
const &front()
const {
176 T operator[](T s)
const {
177 return s * fStep + fBegin;
180 std::size_t size()
const {
181 return end() - begin();
189 return fEnd == fBegin;
194 using TSeqI = TSeq<int>;
195 using TSeqU = TSeq<unsigned int>;
196 using TSeqL = TSeq<long>;
197 using TSeqUL = TSeq<unsigned long>;
200 TSeq<T> MakeSeq(T end)
206 TSeq<T> MakeSeq(T begin, T end, T step = 1)
208 return TSeq<T>(begin, end, step);
220 std::string printValue(ROOT::TSeq<T> *val)
222 std::ostringstream ret;
223 ret <<
"A sequence of values: " << *val->begin()
224 <<
" <= i < " << *val->end();
225 auto step = val->step();
227 ret <<
" in steps of " << step;