Click here to Skip to main content
15,915,059 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralSTL question - Moving Items around in a list Pin
#realJSOP8-Jul-02 9:13
professional#realJSOP8-Jul-02 9:13 
GeneralRe: STL question - Moving Items around in a list Pin
Chris Losinger8-Jul-02 9:38
professionalChris Losinger8-Jul-02 9:38 
GeneralRe: STL question - Moving Items around in a list Pin
#realJSOP8-Jul-02 9:45
professional#realJSOP8-Jul-02 9:45 
GeneralRe: STL question - Moving Items around in a list Pin
Chris Losinger8-Jul-02 9:53
professionalChris Losinger8-Jul-02 9:53 
GeneralRe: STL question - Moving Items around in a list Pin
Tim Smith8-Jul-02 10:14
Tim Smith8-Jul-02 10:14 
GeneralRe: STL question - Moving Items around in a list Pin
Chris Losinger8-Jul-02 10:16
professionalChris Losinger8-Jul-02 10:16 
GeneralRe: STL question - Moving Items around in a list Pin
#realJSOP9-Jul-02 2:31
professional#realJSOP9-Jul-02 2:31 
GeneralRe: STL question - Moving Items around in a list Pin
jbarton9-Jul-02 5:23
jbarton9-Jul-02 5:23 
One solution would be to use stable_partition. This will reorder the list based on a predicate which returns true or false, without changing the relative order of any of the items in the same grouping.

The following example shows a simple implementation:

#include <iostream>
#include <list>
#include <algorithm>
#include <functional>


void PrintChar( char ch )
{
std::cout << "'" << ch << "'" << std::endl;
}


struct Partition : public std::unary_function< char, bool >
{
bool operator()( char ch )
{
return ( ch == 'B' || ch == 'E' || ch == 'F' );
}
};


int main(int argc, char* argv[])
{
std::list<char> myList;

myList.push_back( 'A' );
myList.push_back( 'B' );
myList.push_back( 'C' );
myList.push_back( 'D' );
myList.push_back( 'E' );
myList.push_back( 'F' );

std::cout << "before:" << std::endl;
std::for_each( myList.begin(), myList.end(), PrintChar );

std::stable_partition( myList.begin(), myList.end(), Partition() );

std::cout << "after:" << std::endl;
std::for_each( myList.begin(), myList.end(), PrintChar );

return 0;
}

Best regards,
John

GeneralGeting Explorer Drop Target - Help Pin
zarco18-Jul-02 8:43
zarco18-Jul-02 8:43 
GeneralHooking windows Pin
S van Leent8-Jul-02 7:59
S van Leent8-Jul-02 7:59 
GeneralRe: Hooking windows Pin
Oliver Daniel8-Jul-02 10:11
Oliver Daniel8-Jul-02 10:11 
GeneralRe: Hooking windows Pin
S van Leent9-Jul-02 1:43
S van Leent9-Jul-02 1:43 
GeneralWindows XP Socket BUG Pin
8-Jul-02 7:22
suss8-Jul-02 7:22 
GeneralRe: Windows XP Socket BUG Pin
Tim Smith8-Jul-02 10:12
Tim Smith8-Jul-02 10:12 
GeneralScreensaver problem Pin
jancsi8-Jul-02 7:08
jancsi8-Jul-02 7:08 
GeneralRe: Screensaver problem Pin
Gary Kirkham8-Jul-02 7:15
Gary Kirkham8-Jul-02 7:15 
GeneralRe: Screensaver problem Pin
Gary Kirkham8-Jul-02 7:16
Gary Kirkham8-Jul-02 7:16 
Generalunnamed registry keys Pin
Mel Stober8-Jul-02 6:22
Mel Stober8-Jul-02 6:22 
GeneralRe: unnamed registry keys Pin
DanielP8-Jul-02 6:36
DanielP8-Jul-02 6:36 
QuestionPrinting progress bar? Pin
dazinith8-Jul-02 6:20
dazinith8-Jul-02 6:20 
GeneralMemory Tracking Pin
NullStream8-Jul-02 6:08
NullStream8-Jul-02 6:08 
GeneralRe: Memory Tracking Pin
Chris Losinger8-Jul-02 6:12
professionalChris Losinger8-Jul-02 6:12 
GeneralRe: Memory Tracking Pin
NullStream8-Jul-02 6:59
NullStream8-Jul-02 6:59 
GeneralRe: Memory Tracking Pin
Chris Losinger8-Jul-02 11:48
professionalChris Losinger8-Jul-02 11:48 
GeneralSTL unicode/ANSI conversions Pin
8-Jul-02 5:54
suss8-Jul-02 5:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.