"Filtering" a buffer(a std::deque here)-Which method is better?

This is a discussion on "Filtering" a buffer(a std::deque here)-Which method is better? within the C++ Programming forums, part of the General Programming Boards category; What I did.. Code: for (auto temp :mybuffer) { if(some_condition) <do something with temp> else newbuffer.push_back(temp) } mybuffer = newbuffer; ...

  1. #1
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,526

    "Filtering" a buffer(a std::deque here)-Which method is better?

    What I did..
    Code:
    for (auto temp :mybuffer)
    {
        if(some_condition)
             <do something with temp>
        else
              newbuffer.push_back(temp)
    }
    mybuffer = newbuffer;
    And what I thought could work better but could not find a way, without using an invalid iterator.
    1.Iterate through the extent of the original size of 'mybuffer'
    2.instead of pushing the temp 's which do not satisfy some_condition into a new buffer, push them on the back of my_buffer itself .

    Are the two ways essentially same, or is the later better(In that case, suggest an elegant way of doing so)?
    Or is there a process even better ?
    Manasij Mukherjee | gcc-4.9.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,270
    I would consider if one or more standard generic algorithms could come in handy here. Things like std::remove_if and std:artition come to mind.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 23
    Last Post: 10-26-2008, 04:59 AM
  2. what's a "dynamic buffer"?
    By MK27 in forum C Programming
    Replies: 22
    Last Post: 08-08-2008, 09:48 AM
  3. Best "Menu" method?
    By SSJMetroid in forum Game Programming
    Replies: 11
    Last Post: 12-08-2005, 12:05 AM
  4. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  5. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21