On Mar 7, 1:26 pm, "antani" <antani8...@yahoo.itwrote:

I need to implement a function with a argument that is a

compare function.

This compare function must be several for every

necessity. For example , I would like a compare function

to analyze element of list that are even or a compare

function to analyze odd element.

I almost choked on my coffee when my compiler didn't choke

on the following:

#include <iostream>

#include <ostream>

#include <list>

template < typename T >

bool fredle ( T x ) { return ( * x ) % 2 ; }

template < typename T >

bool bargle ( T x ) { return ! ( ( * x ) % 2 ) ; }

template < typename T >

bool quugle ( T x ) { return ! ( ( * x ) % 3 ) ; }

template < typename T >

bool xyzzle ( T x ) { return quugle ( -- x ) ; }

template < typename T >

void f

(

const T & l ,

bool ( * c ) ( typename T :: const_iterator )

)

{

for

(

typename T :: const_iterator i = l . begin ( ) ;

i != l . end ( ) ; ++ i

)

if ( ( * c ) ( i ) ) std :: cout << ( * i ) << " " ;

std :: cout << std :: endl ;

}

int main ( )

{

std :: list < int l ;

for ( int i = 0 ; i != 10 ; ++ i )

l . push_back ( i + 1 ) ;

f ( l , & fredle ) ;

f ( l , & bargle ) ;

f ( l , & quugle ) ;

f ( l , & xyzzle ) ;

}

Looks like a disaster waiting to happen to me.

--

Pavel Lepin