[英]How to initialize boost::random::discrete_distribution using double[];
I would like to initialize boost::random::discrete_distribution with a double[] like this: 我想用double []初始化boost :: random :: discrete_distribution,如下所示:
boost::random::discrete_distribution<>* distribution(double* _distr)
{
return new boost::random::discrete_distribution<>(_distr);
}
I know I can use vector or statically sized table but is there a way to overcome that without rewriting my _distr? 我知道我可以使用矢量或静态大小的表但是有没有办法克服它而不重写我的_distr?
discrete_distribution<>
cannot take a plain double*
argument because it would have no way to know how long the array is. discrete_distribution<>
不能采用普通的double*
参数,因为它无法知道数组的长度。
Instead it takes an iterator range, but you'll have to specify the number of elements in your array: 相反,它需要一个迭代器范围,但您必须指定数组中的元素数量:
boost::random::discrete_distribution<>* distribution(double const* distr,
std::ptrdiff_t count)
{
return new boost::random::discrete_distribution<>(distr, distr + count);
}
As usual, this is made quite clear in the documentation . 像往常一样,这在文档中已经非常清楚了 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.