Skip to content

Instantly share code, notes, and snippets.

@detunized
Last active December 11, 2015 06:08
Show Gist options
  • Save detunized/4556813 to your computer and use it in GitHub Desktop.
Save detunized/4556813 to your computer and use it in GitHub Desktop.
Operator < detection
#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;
}
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