[ create a new paste ] login | about

Link: http://codepad.org/oPiZmjlV    [ raw code | output | fork ]

C++, pasted on Dec 17:
#include <functional>       // less, function, bind
#include <list>             // list
#include <string>           // string
using namespace std;

template< class Type >
bool isLess( Type const&a, Type const& b )
{
    return less< Type >()( a, b );
}

template< class Type, class Func >
bool isLess( Type const& a, Type const& b, Func const& f )
{
    return isLess( f( a ), f( b ) );
}

template< class Type, class Func >
function< bool (*)( Type const&, Type const& ) > lessFunc( Func f )
{
    return bind( isLess< Type, Func >, f );
}

size_t myConvertFunc( string const& s )
{
    return s.length();
}

int main()
{
    list<string>    L;
    
    L.sort( lessFunc< string >( myConvertFunc ) );
}


Output:
1
2
Line 19: error: expected constructor, destructor, or type conversion before '<' token
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: