C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

valarray, why no begin() / end()?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
christopher diggins
Guest





PostPosted: Sat Jun 04, 2005 2:27 am    Post subject: valarray, why no begin() / end()? Reply with quote



Does any one know why there is no begin() / end() functions for valarray?

--
Christopher Diggins
http://www.cdiggins.com


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Gabriel Dos Reis
Guest





PostPosted: Sat Jun 04, 2005 12:25 pm    Post subject: Re: valarray, why no begin() / end()? Reply with quote



"christopher diggins" <cdiggins (AT) videotron (DOT) ca> writes:

Quote:
Does any one know why there is no begin() / end() functions for valarray?

Because they are thought of as "whole thingy" collections rather than
sequences.
You might argue that associative containers are not sequences, but the
difference here is that, fundamentally valarrays are supposed to
support single instruction multiple data (SIMD) operations and being
free of some form of alias.
In such a perspective, begin() and end() operations are barrely
relevant.

--
Gabriel Dos Reis
[email]gdr (AT) integrable-solutions (DOT) net[/email]

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
christopher diggins
Guest





PostPosted: Sat Jun 04, 2005 6:14 pm    Post subject: Re: valarray, why no begin() / end()? Reply with quote



"Gabriel Dos Reis" <gdr (AT) integrable-solutions (DOT) net> wrote

Quote:
"christopher diggins" <cdiggins (AT) videotron (DOT) ca> writes:

| Does any one know why there is no begin() / end() functions for
valarray?

Because they are thought of as "whole thingy" collections rather than
sequences.
You might argue that associative containers are not sequences, but the
difference here is that, fundamentally valarrays are supposed to
support single instruction multiple data (SIMD) operations and being
free of some form of alias.
In such a perspective, begin() and end() operations are barrely
relevant.

Does this mean then that usage such as:

std::valarray<int> v(10);
int* first = &v[0];
int* end = &v[v.size()];

is not recommned because it creates an alias?

Thank you for your help!

-Christopher Diggins


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Gabriel Dos Reis
Guest





PostPosted: Sun Jun 05, 2005 9:30 am    Post subject: Re: valarray, why no begin() / end()? Reply with quote

"christopher diggins" <cdiggins (AT) videotron (DOT) ca> writes:

Quote:
"Gabriel Dos Reis" <gdr (AT) integrable-solutions (DOT) net> wrote in message
news:m3d5r2hf2t.fsf (AT) uniton (DOT) integrable-solutions.net...
"christopher diggins" <cdiggins (AT) videotron (DOT) ca> writes:

| Does any one know why there is no begin() / end() functions for
valarray?

Because they are thought of as "whole thingy" collections rather than
sequences.
You might argue that associative containers are not sequences, but the
difference here is that, fundamentally valarrays are supposed to
support single instruction multiple data (SIMD) operations and being
free of some form of alias.
In such a perspective, begin() and end() operations are barrely
relevant.

Does this mean then that usage such as:

std::valarray<int> v(10);
int* first = &v[0];
int* end = &v[v.size()];
^^^^^^^^^^^^


Parenthetical note: I think you wanted to say &v[0] + v.size();

Quote:
is not recommned because it creates an alias?

You can create pointers into valarray<>s as long as you obey other C++
rules, it is just that they are not thought of actively supporting
aliasing.

--
Gabriel Dos Reis
[email]gdr (AT) integrable-solutions (DOT) net[/email]

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Jerry Coffin
Guest





PostPosted: Mon Jun 06, 2005 7:25 am    Post subject: Re: valarray, why no begin() / end()? Reply with quote

In article <hO2oe.28092$3N5.594359 (AT) weber (DOT) videotron.net>,
[email]cdiggins (AT) videotron (DOT) ca[/email] says...
Quote:
Does any one know why there is no begin() / end() functions for valarray?

Because valarray is not a container, in the usual sense of the word.
The primary idea of valarray was to provide something that was
sufficiently restricted to allow optimizations that were considered
impossible (or at least unlikely) with general containers.

--
Later,
Jerry.

The universe is a figment of its own imagination.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Clark S. Cox III
Guest





PostPosted: Fri Jun 10, 2005 10:18 am    Post subject: Re: valarray, why no begin() / end()? Reply with quote

On 2005-06-05 05:30:45 -0400, Gabriel Dos Reis
<gdr (AT) integrable-solutions (DOT) net> said:

Quote:
"christopher diggins" <cdiggins (AT) videotron (DOT) ca> writes:

| "Gabriel Dos Reis" <gdr (AT) integrable-solutions (DOT) net> wrote in message
| news:m3d5r2hf2t.fsf (AT) uniton (DOT) integrable-solutions.net...
| > "christopher diggins" <cdiggins (AT) videotron (DOT) ca> writes:
|
| > | Does any one know why there is no begin() / end() functions for
| > valarray?
|
| > Because they are thought of as "whole thingy" collections rather than
| > sequences.
| > You might argue that associative containers are not sequences, but the
| > difference here is that, fundamentally valarrays are supposed to
| > support single instruction multiple data (SIMD) operations and being
| > free of some form of alias.
| > In such a perspective, begin() and end() operations are barrely
| > relevant.
|
| Does this mean then that usage such as:
|
| std::valarray<int> v(10);
| int* first = &v[0];
| int* end = &v[v.size()];
^^^^^^^^^^^^

Parenthetical note: I think you wanted to say &v[0] + v.size();

And the difference is?

#include <valarray>
#include <iostream>

using namespace std;

int main()
{
valarray<int> arr(20);
for(size_t i=0; i {
cout << boolalpha
<< (&arr[i] == &arr[0] + i)
<< endl;
}
return 0;
}


--
Clark S. Cox, III
[email]clarkcox3 (AT) gmail (DOT) com[/email]


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Gabriel Dos Reis
Guest





PostPosted: Fri Jun 10, 2005 4:32 pm    Post subject: Re: valarray, why no begin() / end()? Reply with quote

"Clark S. Cox III" <clarkcox3 (AT) gmail (DOT) com> writes:

[...]

Quote:
| Does this mean then that usage such as:
|
| std::valarray<int> v(10);
| int* first = &v[0];
| int* end = &v[v.size()];
^^^^^^^^^^^^

Parenthetical note: I think you wanted to say &v[0] + v.size();

And the difference is?

there is no element at v.size() whose address is being taken.

--
Gabriel Dos Reis
[email]gdr (AT) integrable-solutions (DOT) net[/email]

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Maciej Sobczak
Guest





PostPosted: Fri Jun 10, 2005 4:33 pm    Post subject: Re: valarray, why no begin() / end()? Reply with quote

Hi,

Clark S. Cox III wrote:

Quote:
| int* end = &v[v.size()];
^^^^^^^^^^^^

Parenthetical note: I think you wanted to say &v[0] + v.size();

And the difference is?

The difference is that v[v.size()] is already undefined behaviour.

You can reach past-the-end pointer (with pointer arithmetic), but you
cannot take the address of past-the-end element. There is no such element.

On popular platforms it might not be a problem, though.


--
Maciej Sobczak : http://www.msobczak.com/
Programming : http://www.msobczak.com/prog/

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.