473,396 Members | 1,967 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,396 software developers and data experts.

Valarray/Pointer to first Element

Hello Group,

there is some memberfunc for std::valarray to return a pointer to the
first element in the array. How do i use this? Thanx a lot.

HAND Chris
Nov 2 '07 #1
10 6230
On Nov 2, 10:43 am, Chris Forone <4...@gmx.atwrote:
Hello Group,

there is some memberfunc for std::valarray to return a pointer to the
first element in the array. How do i use this? Thanx a lot.

HAND Chris
Correct me if I am wrong, but I don't believe any std container has
methods to give you a pointer to any of thier contents, and rightly
so. You can get a reference to it. Why would you want a pointer to the
first element? What type are you assuming its elements are? How would
you use it opposed to a reference?

Nov 2 '07 #2
On 2007-11-02 16:43, Chris Forone wrote:
Hello Group,

there is some memberfunc for std::valarray to return a pointer to the
first element in the array. How do i use this? Thanx a lot.
&val[0];

Where val is a valarray.
--
Erik Wikström
Nov 2 '07 #3
Christopher wrote:
On Nov 2, 10:43 am, Chris Forone <4...@gmx.atwrote:
>Hello Group,

there is some memberfunc for std::valarray to return a pointer to the
first element in the array. How do i use this? Thanx a lot.

HAND Chris

Correct me if I am wrong, but I don't believe any std container has
methods to give you a pointer to any of thier contents, and rightly
so. You can get a reference to it.
you can get the address of all the elements.
Why would you want a pointer to the
first element?
why not? For example, to apply the std library algorithms. A pointer to
an element of a valarray is a random-access iterator.
What type are you assuming its elements are?
well, for example, for a valarray<double>, I would expect double. :)
How would
you use it opposed to a reference?
one thing is a reference, another thing is a pointer.

Regards,

Zeppe
Nov 2 '07 #4
Erik Wikström schrieb:
On 2007-11-02 16:43, Chris Forone wrote:
>Hello Group,

there is some memberfunc for std::valarray to return a pointer to the
first element in the array. How do i use this? Thanx a lot.

&val[0];

Where val is a valarray.

This solution i have already. I have seen on a Website:

valarray::operator T *

operator T *();
operator const T *() const;

Both member functions return a pointer to the first element of the
controlled array, which must have at least one element.

But i dont know, how to apply this operator...

Thx!
Nov 2 '07 #5
On 2007-11-02 17:35, Chris Forone wrote:
Erik Wikström schrieb:
>On 2007-11-02 16:43, Chris Forone wrote:
>>Hello Group,

there is some memberfunc for std::valarray to return a pointer to the
first element in the array. How do i use this? Thanx a lot.

&val[0];

Where val is a valarray.

This solution i have already. I have seen on a Website:

valarray::operator T *

operator T *();
operator const T *() const;

Both member functions return a pointer to the first element of the
controlled array, which must have at least one element.

But i dont know, how to apply this operator...
Use static_cast:

double* p = static_cast<double*>(val);

where val is a valarray of doubles with at least one element.

--
Erik Wikström
Nov 2 '07 #6
Erik Wikström schrieb:
On 2007-11-02 17:35, Chris Forone wrote:
>Erik Wikström schrieb:
>>On 2007-11-02 16:43, Chris Forone wrote:
Hello Group,

there is some memberfunc for std::valarray to return a pointer to the
first element in the array. How do i use this? Thanx a lot.
&val[0];

Where val is a valarray.

This solution i have already. I have seen on a Website:

valarray::operator T *

operator T *();
operator const T *() const;

Both member functions return a pointer to the first element of the
controlled array, which must have at least one element.

But i dont know, how to apply this operator...

Use static_cast:

double* p = static_cast<double*>(val);

where val is a valarray of doubles with at least one element.
g++ (3.4.2) means invalid static_cast, but before i use reinterpret_cast
i will use &valarr[0] instead...

Thx.
Nov 2 '07 #7
On Nov 2, 5:27 pm, Zeppe <ze...@remove.all.this.long.comment.yahoo.it>
wrote:
Christopher wrote:
On Nov 2, 10:43 am, Chris Forone <4...@gmx.atwrote:
there is some memberfunc for std::valarray to return a
pointer to the first element in the array. How do i use
this? Thanx a lot.
Correct me if I am wrong, but I don't believe any std
container has methods to give you a pointer to any of thier
contents, and rightly so. You can get a reference to it.
You're wrong, of course. If you can get a reference, you can
get a pointer.
you can get the address of all the elements.
Of any of the elements. (At least, I think that's what you
mean; "all of the elements" is ambiguous, and can mean two
different things.)
Why would you want a pointer to the
first element?
why not? For example, to apply the std library algorithms. A
pointer to an element of a valarray is a random-access
iterator.
I think that valarray is guaranteed to be continuous. As is
std::vector, and (soon) std::basic_string. That's not true for
other containers, however, and a pointer to a given element is
not generally a random-access iterator into the container.
(Again, I think you know this, and were only refering to
valarray, but it's not clear.)

The most frequent need for a pointer is, of course, interfacing
with legacy code or with C. In which case, the type of the
container is constrained; if the C code expects a pointer to the
first element, you can use vector, I think valarray, and in
practice basic_string, but nothing else.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Nov 3 '07 #8
On Nov 2, 5:35 pm, Chris Forone <4...@gmx.atwrote:
Erik Wikström schrieb:On 2007-11-02 16:43, Chris Forone wrote:
there is some memberfunc for std::valarray to return a
pointer to the first element in the array. How do i use
this? Thanx a lot.
&val[0];
Where val is a valarray.
This solution i have already. I have seen on a Website:
valarray::operator T *
operator T *();
operator const T *() const;
Which Web site? It's not in the standard. In general, the
authors of the standard avoided implicit conversions.
Correctly---there are really very few cases where they dont'
cause problems.
Both member functions return a pointer to the first element of
the controlled array, which must have at least one element.
Neither member function exists.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Nov 3 '07 #9
James Kanze schrieb:
On Nov 2, 5:35 pm, Chris Forone <4...@gmx.atwrote:
>Erik Wikström schrieb:On 2007-11-02 16:43, Chris Forone wrote:
>>>there is some memberfunc for std::valarray to return a
pointer to the first element in the array. How do i use
this? Thanx a lot.
>> &val[0];
>>Where val is a valarray.
>This solution i have already. I have seen on a Website:
>valarray::operator T *
>operator T *();
operator const T *() const;

Which Web site? It's not in the standard. In general, the
authors of the standard avoided implicit conversions.
Correctly---there are really very few cases where they dont'
cause problems.
publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/standlib/ref/i26lt3bvalarray26gt3b.htm
>
>Both member functions return a pointer to the first element of
the controlled array, which must have at least one element.

Neither member function exists.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Thx a lot!
Nov 3 '07 #10
James Kanze schrieb:
On Nov 2, 5:27 pm, Zeppe <ze...@remove.all.this.long.comment.yahoo.it>
wrote:
>Christopher wrote:
>>On Nov 2, 10:43 am, Chris Forone <4...@gmx.atwrote:
>>>there is some memberfunc for std::valarray to return a
pointer to the first element in the array. How do i use
this? Thanx a lot.
>>Correct me if I am wrong, but I don't believe any std
container has methods to give you a pointer to any of thier
contents, and rightly so. You can get a reference to it.

You're wrong, of course. If you can get a reference, you can
get a pointer.
>you can get the address of all the elements.

Of any of the elements. (At least, I think that's what you
mean; "all of the elements" is ambiguous, and can mean two
different things.)
>>Why would you want a pointer to the
first element?
>why not? For example, to apply the std library algorithms. A
pointer to an element of a valarray is a random-access
iterator.

I think that valarray is guaranteed to be continuous. As is
std::vector, and (soon) std::basic_string. That's not true for
other containers, however, and a pointer to a given element is
not generally a random-access iterator into the container.
(Again, I think you know this, and were only refering to
valarray, but it's not clear.)

The most frequent need for a pointer is, of course, interfacing
with legacy code or with C. In which case, the type of the
container is constrained; if the C code expects a pointer to the
first element, you can use vector, I think valarray, and in
practice basic_string, but nothing else.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Thx a lot!
Nov 3 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Christian Brechbühler | last post by:
The template std::valarray behaves pretty much like a mathematical vector. Arithmetic operators apply elementwise. Now I'd like to extend this to a user-defined type, e.g., complex. ...
4
by: Jim West | last post by:
The following compiles with g++ 3.3.2, but fails with Intel icc 7.1 with the error: asdf.cc(6): error: expression must be an lvalue or a function designator f1(&arr); Is this undefined...
3
by: Peter | last post by:
Hi everybody, I am unfortunately stuck with a probably very simple problem. I made a class called Particle with a valarray (STL) as a class member. The code for the class goes like this: ...
1
by: suresh | last post by:
Namasivayah, Stroustrup says when indirect array is used for reordering a valarray the index cannot be repeated twice(page 679). But Nicolai Josuttis in his book on C++ standard library, page...
1
by: Oliver Block | last post by:
I have a (9x9) valarray std::valarray<int> va(81); va = 0; // fil all elements with zeros I am taking row slices like that: std::slice_array<int> slr = va; // r = row; a value between 1...
3
by: klucar | last post by:
I'll start off differently by showing what I know how to do: valarray<float> va(100, 0.0f); float* fp; fp = &va; some_c_function( fp, va.size() ); What I want to do though is quite the...
2
by: john | last post by:
Hi, in TC++PL3 on page 665, regarding valarray member functions, it is mentioned: "valarray operator-() const; // result= -v for every element // similarly: +, ~, !" I checked the web and...
43
by: john | last post by:
Hi, in TC++PL 3 on pages 674-675 it is mentioned: "Maybe your first idea for a two-dimensional vector was something like this: class Matrix { valarray< valarray<doublev; public: // ... };
2
by: Chris Forone | last post by:
hello group, is there a technical reason why slice_array do not have an index-operator? is it complicated to extend slice_array with such an index-operator? cheers, chris
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.