简体   繁体   English

使用C ++ Boost间隔容器库(ICL)时如何移动间隔?

[英]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? 如何使用Boost间隔容器库移动discrete_interval?

ie I want to subtract integer c from the lower() of the interval and from the upper() of the interval? 即我想从间隔的lower()和间隔的upper()中减去整数c? 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). 规范的方法是构造一个新的区间并将其分配给你的区间,因为boost::lcl::discrete_interval是不可变的(除了赋值运算符)。 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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