c++ - boost::icl::interval 和 boost::numeric::interval 是否有可用的适配层?
问题描述
我一直在我的代码中到处使用boost::numeric::interval 。现在我已经开始使用boost interval 容器库了。是否存在适配标头,因此我可以将 boost::numeric::interval 间隔放入 boost::icl 容器中?
我已经按照 boost::icl 的定制文档中的建议尝试了以下代码,但它没有与多行模板专业化失败消息一起编译。如果您想查看错误消息,可以在以下位置尝试实时代码
https://wandbox.org/permlink/P8VzcdbjQQzf43yU
我写的代码也在下面。
适配代码
#include <boost/icl/interval_set.hpp>
#include <boost/numeric/interval.hpp>
namespace boost{ namespace icl
{
// Class template interval_traits serves as adapter to register and customize your interval class
template<typename T>
struct interval_traits< boost::numeric::interval<T> >
{
typedef boost::numeric::interval<T> interval_type;
typedef T domain_type;
typedef std::less<T> domain_compare;
static interval_type construct(const domain_type& lo, const domain_type& up)
{ return interval_type(lo, up); }
//3.2 Selection of values
static domain_type lower(const interval_type& inter_val){ return inter_val.lower(); };
static domain_type upper(const interval_type& inter_val){ return inter_val.upper(); };
};
template<typename T>
struct interval_bound_type<boost::numeric::interval<T> > //4. Finally we define the interval borders.
{ // Choose between static_open (lo..up)
typedef interval_bound_type type; // static_left_open (lo..up]
BOOST_STATIC_CONSTANT(bound_type, value = boost::icl::interval_bounds::static_closed);
}; // and static_closed [lo..up]
}} // namespace boost icl
测试代码
int main()
{
boost::numeric::interval<double> i = boost::numeric::hull(1.0,2.0);
boost::icl::interval_set<double, std::less, boost::numeric::interval<double>> iSet;
iSet.insert(i);
}
解决方案
解决方案是使用
boost::icl::interval_bounds::static_left_open
boost::icl::interval_bounds::static_right_open
像下面
template<typename T>
struct interval_bound_type<boost::numeric::interval<T> >
{
typedef interval_bound_type type;
BOOST_STATIC_CONSTANT(bound_type, value =
boost::icl::interval_bounds::static_left_open);
};
定义区间类型时。interval_bounds 上的其他选项不起作用。
推荐阅读
- python - 尝试根据登录用户的用户名创建模型对象时出现 ValueError
- php - 如何使用 PHP 重新设置关联数组的键?
- python - 如何登录“https://github.com/NoMore201/googleplay-api”
- android - 在我的代码中向微调器添加约束
- gitlab-ci - 推送标签后的Gitlab
- react-native - 如何在 react-native 中传递道具以匹配子项中的状态属性
- java - 如何使用 lucene 进行精确搜索
- python - Pytorch 卷积层返回 Nan
- javascript - mdbreact 错误 - 元素类型无效:应为字符串(对于内置组件)
- ruby-on-rails - RoR 查找 HABTM 通过多个 id 加入