DateTimeException if this interval is
empty.
Warning:
func must be logically pure. Ideally, func
would be a function pointer to a pure function, but forcing
func to be pure is far too restrictive to be useful, and
in order to have the ease of use of having functions which generate functions to pass to fwdRange, func must be a delegate.
If func retains state which changes as it is called, then some algorithms will not work correctly, because the range's save will have failed to have really saved the range's state. To avoid such bugs, don't pass a delegate which is not logically pure to fwdRange. If func is given the same time point with two different calls, it must return the same result both times.
Of course, none of the functions in this module have this problem, so it's only relevant if when creating a custom delegate.
Example: -------------------- auto interval = Interval!Date(Date(2010, 9, 1), Date(2010, 9, 9)); auto func = delegate (scope const Date date) // For iterating over even-numbered days. { if ((date.day & 1) == 0) return date + dur!"days"(2);
return date + dur!"days"(1); }; auto range = interval.fwdRange(func);
// An odd day. Using PopFirst.yes would have made this Date(2010, 9, 2). assert(range.front == Date(2010, 9, 1));
range.popFront(); assert(range.front == Date(2010, 9, 2));
range.popFront(); assert(range.front == Date(2010, 9, 4));
range.popFront(); assert(range.front == Date(2010, 9, 6));
range.popFront(); assert(range.front == Date(2010, 9, 8));
range.popFront(); assert(range.empty); --------------------