2#ifndef FS_RANGEITERATOR_H
3#define FS_RANGEITERATOR_H
10template <
class T = MathSize>
13 friend class iterable;
16 using iterator_category = std::bidirectional_iterator_tag;
17 using difference_type = int;
20 const value_type start,
22 const value_type increment,
23 const bool inclusive =
true
25 : start_(start), end_(end), increment_(increment), inclusive_(inclusive)
29 "Range is from {:f} to {:f} with step {:f} {:s}",
33 inclusive_ ?
"inclusive" :
"exclusive"
44 constexpr inline value_type operator*()
const {
return start_ + step_ * increment_; }
52 logging::check_fatal(*(*
this) < start_, [&]() {
54 "operator++() {:g} less than start value {:g} ({:+g}) for step {:d}",
64 logging::check_fatal(*
this > end(), [&]() {
66 "operator++() {:g} more than end value {:g} ({:+g}) for step {:d}",
83 logging::check_fatal(*(*
this) < start_, [&]() {
85 "operator++(int) {:g} less than start value {:g} ({:+g}) for step {:d}",
93 *(*this) += increment_;
95 logging::check_fatal(*
this > end(), [&]() {
97 "operator++(int) {:g} more than end value {:g} ({:+g}) for step {:d}",
106#ifndef DEBUG_ITERATOR
113 logging::check_fatal(*
this > end(), [&]() {
115 "operator--() {:g} more than end value {:g} ({:+g}) for step {:d}", *(*
this), *end(), step_
119 *(*this) -= increment_;
121 logging::check_fatal(*(*
this) < start_, [&]() {
123 "operator--() {:g} less than start value {:g} ({:+g}) for step {:d}",
132#ifndef DEBUG_ITERATOR
140 logging::check_fatal(*
this > end(), [&]() {
142 "operator--(int) {:g} more than end value {:g} ({:+g}) for step {:d}",
149 *(*this) -= increment_;
151 logging::check_fatal(*(*
this) < start_, [&]() {
153 "operator--(int) {:g} less than start value {:g} ({:+g}) for step {:d}",
162 constexpr inline difference_type operator-(
const RangeIterator& rhs)
const
164 return static_cast<difference_type
>(step_ - rhs.step_);
174 constexpr auto end()
const
178 this, end_ + (inclusive_ ? increment_ :
static_cast<value_type
>(0))
181 difference_type size()
const {
return end() - begin(); }
185 : start_(rhs->start_), end_(rhs->end_), increment_(rhs->increment_),
186 step_(
static_cast<difference_type
>((value - start_) / increment_)),
187 inclusive_(rhs->inclusive_)
191 value_type increment_{};
196 std::bidirectional_iterator<RangeIterator<MathSize>>,
197 "iterator must be an iterator!"
199static_assert(std::bidirectional_iterator<RangeIterator<int>>,
"iterator must be an iterator!");
201 const MathSize start,
204 const bool inclusive =
true
207 std::ignore = inclusive;
209 return vector<MathSize>{r.begin(), r.end()};
211inline auto range_int(
const int start,
const int end,
const int step,
const bool inclusive =
true)
213 std::ignore = inclusive;
214 auto r = RangeIterator<int>(start, end, step);
215 return vector<int>{r.begin(), r.end()};
222 const char* name_fct,
223 const char* name_param,
226 const MathSize epsilon,
230 logging::debug(
"Checking {:s}", name_fct);
233 const auto msg = std::format(
"{} ({} = {})", name_fct, name_param, v);
234 logging::check_tolerance(epsilon, fct_a(v), fct_b(v), msg.c_str());
235 logging::verbose(
"{:s}", msg);
Definition RangeIterator.h:12