tags:

views:

76

answers:

1
struct SimGenRequest {

    int wakeup_mfm_;
    double value_;

    bool operator < ( const SimGenRequest & r2 ) const 
        { return ( wakeup_mfm_ < r2.wakeup_mfm_ ) ; }

};

Use :

std::stable_sort ( all_requests_.begin ( ), all_requests_.end ( ) );

Works ( compiles ). But

struct SimGenRequest {

    int wakeup_mfm_;
    double value_;

};

bool CompareByWakeTime ( const SimGenRequest & r1, const SimGenRequest & r2 ) {
    return ( r1.wakeup_mfm_ < r2.wakeup_mfm_ ) ;
}

Use :

std::stable_sort ( all_requests_.begin ( ), all_requests_.end ( ), 
    CompareByWakeTime );

does not work. Any pointers ?

A: 

wrap that CompareByWakeTime in a ptr_fun like so

std::stable_sort( all_requests_.begin(), all_requests_.end(), ptr_fun( CompareByWakeTime ) );
wheaties