> It is only straightforward when you understand it! Just looked it up
> in the MSDN it it goes on about First, Middle and Last.
OK, 'first' is an iterator to the first item of the collection (in your
case, an array.) 'last' is an iterator to one past the last element in the
collection. Now, let me describe 'middle'.
std::rotate divides a range into two segments, and switches them in the
collection. For example, if you want to shift {1,2,3,4,5} two items to the
top, you would get {3,4,5,1,2}. Now, 'middle' is an iterator to the item at
the first place on the second part (in our example, 3.) The following code
implements the idea:
int array[] = {1,2,3,4,5};
std::rotate( array, // pointer to the first element
array + 2, // pointer to the first element in the second part
array + 5 // pointer to the last element );
> Imagine I have two arrays. int iNumMonths[5] and
> COleDateTime datTime[5]
>
> Now, I have int iNumChanges which states how many of those 5 items are
> used in the array
>
> Now, rotate up from item index 1 (for iNumChanges) and put item index
> 0 at pos (iNumMonths - 1)
>
> I don't quite understand the above algorithm and what it does....
Well, as you explain, your code must look like:
std::rotate( array,
array + iNumChanges,
array + sizeof(array) / sizeof(array[0]) );
> Do I have to use std:: ?
Yes. Alternatively you can do:
using std::rotate;
Or:
using namespace std;
And then use 'rotate' without 'std::'.
> Can you explain the parameters?
I think it must be clear now.
-------------
Ehsan Akhgari
Farda Technology (http://www.farda-tech.com/)
List Owner: [EMAIL PROTECTED]
[ Email: [EMAIL PROTECTED] ]
[ WWW: http://www.beginthread.com/Ehsan ]
Under conditions of peace the warlike man attacks himself.
-Beyond Good And Evil, F. W. Nietzsche
_______________________________________________
msvc mailing list
[EMAIL PROTECTED]
See http://beginthread.com/mailman/listinfo/msvc_beginthread.com for subscription
changes, and list archive.