Pregunta

I would like to initialize boost::random::discrete_distribution with a double[] like this:

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?

¿Fue útil?

Solución

discrete_distribution<> cannot take a plain double* argument because it would have no way to know how long the array is.

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top