How to initialize boost :: random :: discrete_distribution using double [];
I would like to initialize boost :: random :: discrete_distribution with double [] like this:
boost::random::discrete_distribution<>* distribution(double* _distr)
{
return new boost::random::discrete_distribution<>(_distr);
}
I know I can use a vector or statically sized table, but is there a way to overcome this without rewriting my _distr?
+3
source to share
1 answer
discrete_distribution<>
cannot take a simple argument double*
because it will have no way of knowing how long the array will be.
Instead, it accepts a range of iterators, but you will need 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 done in the documentation .
+1
source to share