3

How do I shift a discrete_interval using the Boost interval container library?

i.e. I want to subtract integer c from the lower() of the interval and from the upper() of the interval? Obviously I could create a new interval, but I'm looking for the canonical way to do this.

daj
  • 6,962
  • 9
  • 45
  • 79

1 Answers1

2

The canonical way is to construct a new interval and assign it to your interval because boost::lcl::discrete_interval is immutable (apart from the assignment operator). So to shift an interval you have to create a new interval with the desired lower and upper bounds and assign it to the old interval.

boost::icl::discrete_interval<int> interval;
interval = boost::icl::discrete_interval<int>::closed(3, 4);
David Brown
  • 13,336
  • 4
  • 38
  • 55
  • 1
    well at least I'm not going to spend anymore time trying to find a solution isn't there. Even if intervals are immutable, why not have a function which takes an interval and a constant of type T (of int in your case) and returns a new interval with the interval shifted over? This isn't hard to write, but it seems like it would make sense to have something like this in the API. – daj Jun 24 '13 at 18:35