The whole beauty of this is that you get compile-time error, keeping you from potential errors.
Bot Boost MPL should do the trick. You might need to define something else besides operator, a flag, an empty class, or something similar to serve as condition, but other than that, it should be possible.
The problem with this is that you lose some compile-time safety, and you can easily get into situations where your comparison won't be performed.
Of course, I think this would work:
template < class A, class B>class Comparator{ bool compare( const A &a, const B &b ) { switch (op) { case LESS : return a < b; case MORE : return a > b; } }};template < >class Comparator< std::string, std::string >{ bool compare( const std::string &a, const std::string &b ) { return false; }};
So, you partially specialize template for comparison of strings in which there is no comparison performed.
This way, you can explicitly turn off comparison for arbitrary types without modifying them, plus retain compile-time checks for other classes.
The overriden template that doesn't do anything should get compiled out completely.