By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,220 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,220 IT Pros & Developers. It's quick & easy.

valarrays and regular arrays

P: n/a
Hello all,

I am using valarrays of double in my code, but for using certain
functions I need to pass a normal array of double. What I did was
write something like this:

valarray<double> vad;
// somehow fill this valarray
double* da = new double[vad.size()];

for (long i = 0; i < vad.size(); ++i)
{
da[i] = vad[i];
}

This works fine. However I feel this not to be an elegant solution to
the proplem, is there a way to maybe directly cast a valarray into a
normal array, or is there another way to do this conversion more
efficiently?

Thanks in advance,

Sebastian
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"Sebastian Thiebes" <th*****@hhi.de> wrote in message
news:ca**********@news.cs.tu-berlin.de...
Hello all,

I am using valarrays of double in my code, but for using certain
functions I need to pass a normal array of double. What I did was
write something like this:

valarray<double> vad;
// somehow fill this valarray
double* da = new double[vad.size()];

for (long i = 0; i < vad.size(); ++i)
{
da[i] = vad[i];
}

This works fine. However I feel this not to be an elegant solution to
the proplem, is there a way to maybe directly cast a valarray into a
normal array, or is there another way to do this conversion more
efficiently?

Thanks in advance,

Sebastian


The simple &vad[0] does the trick.

some_function(&vad[0]);

john
Jul 22 '05 #2

P: n/a
John Harrison wrote:
The simple &vad[0] does the trick.

some_function(&vad[0]);


Thanks a lot! This is what I was hoping for,
a simple and elegant solution.

Seb
Jul 22 '05 #3

P: n/a
Sebastian Thiebes wrote:
Hello all,

I am using valarrays of double in my code, but for using certain
functions I need to pass a normal array of double. What I did was
write something like this:

valarray<double> vad;
// somehow fill this valarray
double* da = new double[vad.size()];

for (long i = 0; i < vad.size(); ++i)
{
da[i] = vad[i];
}

This works fine. However I feel this not to be an elegant solution to
the proplem, is there a way to maybe directly cast a valarray into a
normal array, or is there another way to do this conversion more
efficiently?

Thanks in advance,

Sebastian


You could do:

double* da = &vad[0];

HDH,
marc

Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.