1 // Copyright (C) 2018 Intel Corporation
3 // SPDX-License-Identifier: Apache-2.0
6 #ifndef UTIL_IOTA_RANGE_HPP
7 #define UTIL_IOTA_RANGE_HPP
17 inline namespace Range
20 template<typename T, std::int32_t step = 0>
23 static_assert(std::is_integral<T>::value,"T must be integral");
25 inline void check() const
35 else assert(!"Zero step");
37 assert(0 == ((to - from) % step));
42 inline bool operator==(iterator const& other) const
44 return value == other.value;
47 inline bool operator!=(iterator const& other) const
49 return value != other.value;
52 inline T const& operator*() const
57 inline iterator& operator++()
71 const T& front() const
83 inline iterator begin() const
89 inline iterator end() const
95 bool operator==(const IotaRange<T,step>& rhs) const
97 return from == rhs.from && to == rhs.to;
99 bool operator!=(const IotaRange<T,step>& rhs) const
101 return !(*this == rhs);
109 struct IotaRange<T,0>
111 static_assert(std::is_integral<T>::value,"T must be integral");
113 inline void check() const
123 else assert(!"Zero step");
125 assert(0 == ((to - from) % step));
130 inline bool operator==(iterator const& other) const
132 assert(step == other.step);
133 return value == other.value;
136 inline bool operator!=(iterator const& other) const
138 assert(step == other.step);
139 return value != other.value;
142 inline T const& operator*() const
147 inline iterator& operator++()
162 const T& front() const
174 inline iterator begin() const
180 inline iterator end() const
186 bool operator==(const IotaRange<T,0>& rhs) const
188 return from == rhs.from && to == rhs.to && step == rhs.step;
190 bool operator!=(const IotaRange<T,0>& rhs) const
192 return !(*this == rhs);
201 inline IotaRange<T, 1> iota()
202 { return { 0, std::numeric_limits<T>::max()}; }
205 inline IotaRange<T, 1> iota(const T to)
209 inline IotaRange<T, 1> iota(const T from, const T to)
210 { return {from, to}; }
213 inline IotaRange<T> iota(const T from, const T to, const T step)
214 { return {from, to, step}; }
220 #endif // UTIL_IOTA_RANGE_HPP