D
Derek Long
I believe that the following is valid c++:
#include <iostream>
template <typename CMP>
class Comparator
{
bool operator()(int x,int y)
{
return CMP(x,y);
};
};
typedef Comparator<&(operator <)> LessComp;
int main()
{
LessComp less;
std::cout << less(2,3) << "\n";
return 0;
};
Gnu c++ 3.4 disagrees with me, because the operator < is interpreted as
an opening bracket for a template argument that isn't ever completed. A
similar problem occurs with operator >, except that this is seen as the
closing bracket (even though it is inside an opened round bracket!).
Older versions of g++ are happy, but 3.4 is generally much closer to the
standard, so maybe I am wrong about this code being valid.
Can anyone enlighten me?
Many thanks
Derek
#include <iostream>
template <typename CMP>
class Comparator
{
bool operator()(int x,int y)
{
return CMP(x,y);
};
};
typedef Comparator<&(operator <)> LessComp;
int main()
{
LessComp less;
std::cout << less(2,3) << "\n";
return 0;
};
Gnu c++ 3.4 disagrees with me, because the operator < is interpreted as
an opening bracket for a template argument that isn't ever completed. A
similar problem occurs with operator >, except that this is seen as the
closing bracket (even though it is inside an opened round bracket!).
Older versions of g++ are happy, but 3.4 is generally much closer to the
standard, so maybe I am wrong about this code being valid.
Can anyone enlighten me?
Many thanks
Derek