CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2001
    Posts
    1,029

    flipping a vector?

    Hello all,

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

    Thanks!

  2. #2
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: flipping a vector?

    std::reverse

  3. #3
    Join Date
    Jan 2004
    Location
    Düsseldorf, Germany
    Posts
    2,401

    Re: flipping a vector?

    Quote Originally Posted by lab1
    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?

  4. #4
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773

    Re: flipping a vector?

    Does std::reverse work on burgers too? I need to know for next time I'm out of computing work.

  5. #5
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: flipping a vector?

    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.

  6. #6
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: flipping a vector?

    Quote Originally Posted by NMTop40
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured