473,387 Members | 1,304 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

valarrays and regular arrays

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
3 2668

"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: kaptain kernel | last post by:
can anyone translate this into plain english? preg_match_all("/(\w+)+/U", $text, $words);
16
by: Sims | last post by:
Hi, I need some help to split data using regular expression Consider the string '1,2,3', I can split it using, preg_split("/,/", '1,2,3') and i correctly get =1, =2,=3. Now if i have
10
by: Michael Aramini | last post by:
I need to represent 1D and 2D arrays of numeric or bool types in a C++ program. The sizes of the arrays in my intended application are dynamic in the sense that they are not known at compile time,...
7
by: Sally B. | last post by:
Hi, how would I go about doing the following: substitute all the strings 'the' and 'dog' in the 'mytext' id div only? The following doesn't work for 'the'. I also need to use regular expressions...
0
by: Larry Baxter | last post by:
We have some computationally intense code that would greatly benefit from any floating point performance enhancement we could find. We have tests valarrays vs vectors at all optimization levels...
5
by: askmeofit | last post by:
I'm a Phd student in statistics, and I'm writing computer code for the simulation of stochastic differential equations. Little background about my knowledge: I know C programming decently, and my...
0
by: peridian | last post by:
Hi, I wanted a web page where I could post code to, and have it appear in coloured formatting based on the context of the code. Most of the techniques I have seen for this involve complex use...
20
by: kosanovic | last post by:
Hello, I'm bad at regular expressions. Would somebody help me: I need to extract all URL to .jpg and .png pictures from a string containing an HTML file (DOM wouldn't work well in what I need). ...
4
by: Edward Jensen | last post by:
Hi, I have the following static arrays of different size in a class: in header: static double w2, x2; static double w3, x3; static double w4, x4; in GaussLegendre.cpp:
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.