Last active
December 11, 2015 06:08
-
-
Save detunized/4556813 to your computer and use it in GitHub Desktop.
Operator < detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <boost/type_traits/has_less.hpp> | |
#define HAS_LESS(type) (boost::has_less<type>::value \ | |
? #type ": has less" \ | |
: #type ": doesn't have less") | |
#define CHECK(type) (std::cout << HAS_LESS(type) << "\n") | |
struct A | |
{ | |
}; | |
bool operator <(A, A) | |
{ | |
return false; | |
} | |
struct B | |
{ | |
bool operator <(B) | |
{ | |
return false; | |
} | |
}; | |
struct C | |
{ | |
}; | |
int main() | |
{ | |
CHECK(void); | |
CHECK(int); | |
CHECK(std::string); | |
CHECK(A); | |
CHECK(B); | |
CHECK(C); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void: doesn't have less | |
int: has less | |
std::string: has less | |
A: has less | |
B: has less | |
C: doesn't have less |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment