I have an array of points like this:
CArray<CPoint,CPoint> points;
And I need to reverse the order of the points. I've tried this method:
std::reverse( &points[0], &points[0] + points.GetSize() );
And it works. Then I've tried this other method:
std::reverse( &points[0], &points[points.GetUpperBound()] );
But it doesn't work: the last item is not ordered correctly. Why?
That is because STL algorithms take ranges in the form [b, e) (that is, e exclusive), whereas the function you used returns the position of the last actual last element.
It should be further noted that your second form is even more problematic in the case where the array is empty. The function, according to the documentation, returns -1 in this case. BOOM!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With