Click to See Complete Forum and Search --> : flipping a vector?


lab1
January 8th, 2007, 07:04 AM
Hello all,

What is the simplest code to use to "flip" an std::vector? The last element is the first and so on...

Thanks!

JohnW@Wessex
January 8th, 2007, 07:26 AM
std::reverse

treuss
January 8th, 2007, 08:11 AM
What is the simplest code to use to "flip" an std::vector? The last element is the first and so on...std::reverse if of course right, but there is hardly ever a need for reversing a vector, because you can iterate a vector back to front as well as front to back. So why waste CPU time on reversing it?

NMTop40
January 8th, 2007, 09:49 AM
Does std::reverse work on burgers too? I need to know for next time I'm out of computing work.

JohnW@Wessex
January 8th, 2007, 09:52 AM
Maybe you're passing it to a function (that you can't change) that requires it in the opposite order. I had a situation where data was in one order in the application, but an error correction library required it in reverse order. It may be that the data decodes in one order but the reverse makes more logical sense subjectively, and you don't want to use reverse iterators all over the place.

JohnW@Wessex
January 8th, 2007, 10:11 AM
Does std::reverse work on burgers too? I need to know for next time I'm out of computing work.

It would probably have to be std::flip