Ok, what I have tried to do here is probably one of those "reasonable-looking but faulty" uses of STL.

Here is my "sample" code which illustrates the problem;


template < typename T >
class H
{
private:
map< string, T > m_map;
public:
template< typename Predicate >
RemoveCopyIf( H< T >& rhs, Predicate pr )
{
m_map.clear();
remove_copy_if( rhs.m_map.begin(), rhs.m_map.end(),
inserter( m_map, m_map.begin() ), pr );
}
void Insert( const string& s, const T& t )
{
m_map[s] = t;
}
};

class J
{
private:
int m_x;
public:
J( int x=0 ) : m_x( x )
{
}
int x() const { return m_x; }

// keep default copy constructor and operator=
template < typename K >
static bool IsOdd( const std:air< K, J > & kjPair )
{
return ( (kjPair.second.m_x & 1) != 0);
}
};

template < typename K >
bool IsOdd( const std:air< K, J > & kjPair )
{
return ( ( kjPair.second.x() & 1 ) != 0 );
}


int main()
{
H< J > h1;
H< J > h2;

h1.Insert( "one", J(1) );
h1.Insert( "two", J(2) );
h1.Insert( "three", J(3) );
h1.Insert( "four", J(4) );

h2.RemoveCopyIf( h1, J::IsOdd< string > ); // internal compiler error
h2.RemoveCopyIf( h1, IsOdd< string > ); // link error if above line commented out
return 0;
}



attempting to compile with VC6

My guess is that the predicate must be a proper function pointer for the predicate and the compiler can't find one. (Is that the cause?)

btw. in my real code I used the static member function with the key filled in (non-template) after the code above failed with the internal compiler error, and I also used Nicolai M. Josuttis's asso_inserter() implementation.

I just posted this here because I'm curious (and it would have been nice to do what I was trying above)

Add the below, for example, and the above works (whether as static in the class or in global space)


bool IsOdd( const std:air< string, J > & kjPair )
{
return ( ( kjPair.second.x() & 1 ) != 0 );
}





The best things come to those who rate