CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #1
    Join Date
    Oct 2007
    Posts
    34

    [RESOLVED] Move elements from one container to another without loop

    Is there an algorithm in the STL to move elements similar to how std::copy works? I have read various places that the new C++ standard has a move algorithm. Unfortunately the compiler I use (g++ (GCC) 4.2.0) does not support any C++0x updates.

    I have a std:eque that I want to move a range from into an array. I am currently using something like this where

    data_array is an unsigned char pointer to a buffer being passed in by the caller
    dataQ is a std:eque<unsigned char> that is a member variable maintained within the class

    Code:
        for (int i = 0; i < numberBytesRequested; ++i)
        {
        	data_array[i] = dataQ.front();
        	dataQ.pop_front();
        }
    I'm concerned that executing this loop over and over again is going to be very inefficient. I am looking for a more efficient way to do this.

    Thanks for the help.
    Last edited by Yadrif; February 17th, 2012 at 03:38 PM. Reason: Added compiler version

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