Click here to Skip to main content
15,905,148 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: std::sort( Ran first, Ran last, Cmp cmp) Pin
Maxwell Chen9-May-04 20:20
Maxwell Chen9-May-04 20:20 
GeneralRe: std::sort( Ran first, Ran last, Cmp cmp) Pin
Laing,James9-May-04 21:51
Laing,James9-May-04 21:51 
GeneralRe: std::sort( Ran first, Ran last, Cmp cmp) Pin
Milton Karimbekallil10-May-04 18:11
Milton Karimbekallil10-May-04 18:11 
GeneralRe: std::sort( Ran first, Ran last, Cmp cmp) Pin
Mike Dimmick10-May-04 1:43
Mike Dimmick10-May-04 1:43 
GeneralRe: std::sort( Ran first, Ran last, Cmp cmp) Pin
Paul Ranson10-May-04 4:14
Paul Ranson10-May-04 4:14 
GeneralRe: std::sort( Ran first, Ran last, Cmp cmp) Pin
Laing,James10-May-04 9:42
Laing,James10-May-04 9:42 
GeneralRe: std::sort( Ran first, Ran last, Cmp cmp) Pin
Laing,James10-May-04 9:58
Laing,James10-May-04 9:58 
GeneralRe: std::sort( Ran first, Ran last, Cmp cmp) Pin
Paul Ranson10-May-04 10:39
Paul Ranson10-May-04 10:39 
You may consider this too ugly...
template <typename C, typename S> struct MemFunCmp_t
{
    bool (C::*pmf_ )( const S&, const S& ) ;
    C& rC_ ;

    MemFunCmp_t ( C& rC, bool (C::*f)( const S&, const S& )) : rC_ ( rC ), pmf_ ( f )
    {
    }
    bool operator () ( const S& l, const S& r )
    {
        return (rC_.*pmf_) ( l, r ) ;
    }
} ;

template <typename C, typename S> MemFunCmp_t< C, S > MemFunCmp ( C& c, bool (C::*f)( const S&, const S&))
{
    return MemFunCmp_t <C, S>( c, f ) ;
}

class Sort2
{
private :
    std::vector<int> v_ ;

    bool Cmp2 ( const int& l, const int& r )
    {
        return l > r ;
    }
public :
    Sort2 ()
    {
        v_.resize ( 10 ) ;
        for ( int i = 0; i < 10; ++i )
        {
            v_ [ i ] = i ;
        }
    }
    void DoSomething ()
    {
        std::sort ( v_.begin (), v_.end (), MemFunCmp ( *this, Cmp2 )) ;
    }
    void PrintV_ ()
    {
        for ( unsigned i = 0; i < v_.size (); ++i )
        {
            std::cout << v_ [ i ] << " " ;
        }
        std::cout << "\n" ;
    }
} ;

int main()
{
    Sort2 s ;
    s.PrintV_ () ;
    s.DoSomething () ;
    s.PrintV_ () ;

    return 0;
}

But I think it does what you're asking for.

It builds and runs on VC7.1, I believe it's standard C++. YMMV.

Paul
GeneralRe: std::sort( Ran first, Ran last, Cmp cmp) Pin
Laing,James11-May-04 9:35
Laing,James11-May-04 9:35 
GeneralDialogs Pin
Member 6226669-May-04 10:51
Member 6226669-May-04 10:51 
GeneralRe: Dialogs Pin
Christian Graus9-May-04 13:03
protectorChristian Graus9-May-04 13:03 
Generalsnapping windows Pin
Roman Nurik9-May-04 9:19
Roman Nurik9-May-04 9:19 
GeneralRe: snapping windows Pin
KalliMan9-May-04 10:24
KalliMan9-May-04 10:24 
GeneralRe: snapping windows Pin
Antony M Kancidrowski10-May-04 2:01
Antony M Kancidrowski10-May-04 2:01 
GeneralSetFocus for a chosen Edit Control in MFC Pin
robert_s9-May-04 9:01
robert_s9-May-04 9:01 
GeneralRe: SetFocus for a chosen Edit Control in MFC Pin
KalliMan9-May-04 10:15
KalliMan9-May-04 10:15 
GeneralRe: SetFocus for a chosen Edit Control in MFC Pin
toxcct9-May-04 10:23
toxcct9-May-04 10:23 
GeneralRe: SetFocus for a chosen Edit Control in MFC Pin
robert_s9-May-04 12:07
robert_s9-May-04 12:07 
GeneralRe: SetFocus for a chosen Edit Control in MFC Pin
David Crow10-May-04 3:06
David Crow10-May-04 3:06 
Questioncd writer programming.how? Pin
Mohsen Saad9-May-04 8:59
Mohsen Saad9-May-04 8:59 
AnswerRe: cd writer programming.how? Pin
Anthony_Yio10-May-04 1:19
Anthony_Yio10-May-04 1:19 
GeneralDymanic windows Pin
Alton Williams9-May-04 4:44
Alton Williams9-May-04 4:44 
GeneralRe: Dymanic windows Pin
Jens Doose10-May-04 0:11
Jens Doose10-May-04 0:11 
GeneralDymanic windows (clarified) Pin
Alton Williams13-May-04 3:29
Alton Williams13-May-04 3:29 
GeneralRe: Dymanic windows (clarified) Pin
Jens Doose13-May-04 3:39
Jens Doose13-May-04 3:39 

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.