1// All the pointer_to_binary_function cases used to fail because g++ 2// couldn't handle converting an overloaded function to a class type. 3// The first one should still fail because it requires an implicit conversion 4// to pointer_to_binary_function, which has an `explicit' constructor. 5 6#include <vector> 7#include <algorithm> 8#include <functional> 9 10using namespace std; 11 12template <class T> class Expr 13{ 14public : 15 Expr(){}; 16 Expr(const T&){}; 17}; 18 19template <class T > 20inline bool compare(const Expr<T> a, const Expr<T> b){ return true; }; 21 22int main() 23{ 24 vector<int> a(3); 25 sort( a.begin(), a.end(), 26 static_cast<bool (*)(const Expr<int>,const Expr<int>)>(compare) ); 27 sort( a.begin(), a.end(), compare<int> ); 28 sort<vector<int>::iterator, 29 pointer_to_binary_function<const Expr<int>, const Expr<int>, bool> > 30 ( a.begin(), a.end(), compare ); // ERROR - constructor is explicit 31 sort( a.begin(), a.end(), 32 ptr_fun<const Expr<int>, const Expr<int>, bool> (compare) ); 33 sort( a.begin(), a.end(), 34 ptr_fun(compare<int>) ); 35 sort( a.begin(), a.end(), 36 pointer_to_binary_function<const Expr<int>, const Expr<int>, bool>(compare) ); 37 sort( a.begin(), a.end(), 38 pointer_to_binary_function<const Expr<int>, const Expr<int>, bool>(compare<int>) ); 39 sort( a.begin(), a.end(), 40 pointer_to_binary_function<const Expr<int>, const Expr<int>, bool>(compare<>) ); 41} 42