简体   繁体   中英

How to shift an interval when using the C++ Boost interval container library (ICL)?

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

ie 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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM