Array indices, change the element order?
If I have a function that accepts an array as a parameter, e.g.
double DoStuff(int arr[])
Are there any ways of specifiying the indices of that array to effect a change in the array element order?
So doing something like...
double DoStuff(int arr[3,1,0,2])
or
double DoStuff(int arr[3], arr[1], arr[0], arr[2])
or
something similar?
I can of course create a new array with the elements in the revised order and pass that, but just wondered if there is a shortcut for this?
Re: Array indices, change the element order?
Not that I'm aware of.
If I really needed that type of access to an array (and I have as part of a MasterMind game), I would use a second array that would pass the indexes in the order needed.
That gives you a level of indirection, essentially replicating the functionality of pointers into the array.
double DoStuff(int arr[], int idx[])
Loop (example. by i) and access the array in idx order
arr[idx[i]]
Re: Array indices, change the element order?
If you are using c++11 then another possibility could be an initializer list. See http://www.cplusplus.com/reference/i...tializer_list/
Re: Array indices, change the element order?
How big is your array? Why don't you just pass a container to the function which contains the order of the read?