문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top