Connecting Tech Pros Worldwide Help | Site Map

Repeating index - Indirect arrays - valarray

  #1  
Old August 19th, 2005, 04:25 PM
suresh
Guest
 
Posts: n/a
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 567, says, index may occur
twice.

g++ version 3.3.5 compiles code with repeated index without any
complaint.

My questions are

1. Can we repeat the index in the index array for reordering a
valarray?
2. Can I get a reordered array which is larger than the original array
by repeating indices. (It works in g++, but I am not sure of
portability)

Thank you,
suresh


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

  #2  
Old August 23rd, 2005, 07:55 AM
Carl Barron
Guest
 
Posts: n/a

re: Repeating index - Indirect arrays - valarray


In article <1124437899.494084.326510@g44g2000cwa.googlegroups .com>,
suresh <suresh.amritapuri@gmail.com> wrote:
[color=blue]
> 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 567, says, index may occur
> twice.
>
> g++ version 3.3.5 compiles code with repeated index without any
> complaint.
>
> My questions are
>
> 1. Can we repeat the index in the index array for reordering a
> valarray?
> 2. Can I get a reordered array which is larger than the original array
> by repeating indices. (It works in g++, but I am not sure of
> portability)
>[/color]
section 26.3.9.2 states its undefined behavior in the example in par
3:
[ Example:
int addr [] = {2 , 3 , 1 , 4 , 4};
valarray <size_t > indirect (addr , 5);
valarray <double > a (0. , 10) , b (1. , 5);
a[ indirect ] = b;
results in undefined behavior since element 4 is specified twice in the
indirection. ‹end example ]

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

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
JavaScript associative arrays not ordered? Rene Nyffenegger answers 41 August 24th, 2006 11:25 AM
Array in javascript Leszek answers 104 February 20th, 2006 01:45 PM
type of array index? shmartonak@ticnet.com answers 29 November 14th, 2005 08:58 PM
comp.lang.c Changes to Answers to Frequently Asked Questions (FAQ) Steve Summit answers 1 November 14th, 2005 11:18 AM
Query on arrays of controls Dr John Stockton answers 17 July 20th, 2005 01:30 PM