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 | | | | re: Valarray/Pointer to first Element
On Nov 2, 10:43 am, Chris Forone <4...@gmx.atwrote: Quote:
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? | | | | re: Valarray/Pointer to first Element
On 2007-11-02 16:43, Chris Forone wrote: Quote:
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 | | | | re: Valarray/Pointer to first Element
Christopher wrote: Quote:
On Nov 2, 10:43 am, Chris Forone <4...@gmx.atwrote: Quote:
>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. Quote:
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. Quote:
What type are you assuming its elements are?
well, for example, for a valarray<double>, I would expect double. :) Quote:
How would
you use it opposed to a reference?
one thing is a reference, another thing is a pointer.
Regards,
Zeppe | | | | re: Valarray/Pointer to first Element
Erik Wikström schrieb: Quote:
On 2007-11-02 16:43, Chris Forone wrote: Quote:
>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! | | | | re: Valarray/Pointer to first Element
On 2007-11-02 17:35, Chris Forone wrote: Quote:
Erik Wikström schrieb: Quote:
>On 2007-11-02 16:43, Chris Forone wrote: Quote:
>>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 | | | | re: Valarray/Pointer to first Element
Erik Wikström schrieb: Quote:
On 2007-11-02 17:35, Chris Forone wrote: Quote:
>Erik Wikström schrieb: Quote:
>>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. | | | | re: Valarray/Pointer to first Element
On Nov 2, 5:27 pm, Zeppe <ze...@remove.all.this.long.comment.yahoo.it>
wrote: Quote:
Christopher wrote: Quote:
On Nov 2, 10:43 am, Chris Forone <4...@gmx.atwrote:
Quote: Quote: Quote:
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.
Quote: Quote:
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. Quote:
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.) Quote: Quote:
Why would you want a pointer to the
first element?
Quote:
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:james.kanze@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 | | | | re: Valarray/Pointer to first Element
On Nov 2, 5:35 pm, Chris Forone <4...@gmx.atwrote: Quote:
Erik Wikström schrieb:On 2007-11-02 16:43, Chris Forone wrote: Quote: Quote:
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.
Quote: Quote:
Where val is a valarray.
Quote:
This solution i have already. I have seen on a Website:
Quote:
valarray::operator T *
Quote:
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. Quote:
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:james.kanze@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 | | | | re: Valarray/Pointer to first Element
James Kanze schrieb: Quote:
On Nov 2, 5:35 pm, Chris Forone <4...@gmx.atwrote: Quote:
>Erik Wikström schrieb:On 2007-11-02 16:43, Chris Forone wrote: Quote:
>>>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.
> > Quote: Quote:
>>Where val is a valarray.
> Quote:
>This solution i have already. I have seen on a Website:
> Quote:
>valarray::operator T *
> Quote:
>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 Quote:
> Quote:
>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:james.kanze@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! | | | | re: Valarray/Pointer to first Element
James Kanze schrieb: Quote:
On Nov 2, 5:27 pm, Zeppe <ze...@remove.all.this.long.comment.yahoo.it>
wrote: Quote:
>Christopher wrote: Quote:
>>On Nov 2, 10:43 am, Chris Forone <4...@gmx.atwrote:
> Quote: Quote:
>>>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.
> Quote: Quote:
>>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.
> Quote:
>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.)
> Quote: Quote:
>>Why would you want a pointer to the
>>first element?
> Quote:
>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:james.kanze@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! |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,414 network members.
|