View source code
Display the source code in std/datetime/interval.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Function std.datetime.interval.NegInfInterval.bwdRange

Returns a range which iterates backwards over the interval, starting at end, using func to generate each successive time point.

NegInfIntervalRange!TP bwdRange (
  TP delegate(scope const TP) func,
  PopFirst popFirst =
) const;

The range's front is the interval's end. func is used to generate the next front when popFront is called. If popFirst is PopFirst.yes, then popFront is called before the range is returned (so that front is a time point which func would generate).

If func ever generates a time point greater than or equal to the current front of the range, then a DateTimeException will be thrown.

There are helper functions in this module which generate common delegates to pass to bwdRange. Their documentation starts with "Range-generating function," to make them easily searchable.


func The function used to generate the time points of the range over the interval.
popFirst Whether popFront should be called on the range before returning it.


DateTimeException if this interval is empty.


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 for custom delegates.


auto interval = NegInfInterval!Date(Date(2010, 9, 9));
auto func = delegate (scope const Date date) //For iterating over even-numbered days.
                if (( & 1) == 0)
                    return date - dur!"days"(2);

                return date - dur!"days"(1);
auto range = interval.bwdRange(func);

assert(range.front == Date(2010, 9, 9)); //An odd day. Using PopFirst.yes would have made this Date(2010, 9, 8).

assert(range.front == Date(2010, 9, 8));

assert(range.front == Date(2010, 9, 6));

assert(range.front == Date(2010, 9, 4));

assert(range.front == Date(2010, 9, 2));



Jonathan M Davis


Boost License 1.0.