Maxim Yegorushkin
11/21/2008 3:17:00 PM
On Nov 21, 2:55 pm, "Hicham Mouline" <hic...@mouline.org> wrote:
> Is there a way to allocate an array and initialize in the same statement?
As Pete already said, std::vector<double> d(n, NaN) is the easiest and
most recommended.
> double* d = new double[n];
> and assign immediately a value, say NaN
>
> what i'm doing now is just:
>
> for (size_t i=0; i<n; ++i)
> d[i] = NaN;
>
Another way:
double* d = std::fill_n(new double[n], n, NaN) - n;
Or (save a subtraction):
double* d;
std::fill_n((d = new double[n]), n, NaN);
--
Max