Skip to content

Instantly share code, notes, and snippets.

@Alexhuszagh
Created February 5, 2017 05:01
Show Gist options
  • Select an option

  • Save Alexhuszagh/7fc6195f98b8cac85a10cdb5360767fe to your computer and use it in GitHub Desktop.

Select an option

Save Alexhuszagh/7fc6195f98b8cac85a10cdb5360767fe to your computer and use it in GitHub Desktop.
Sfinae detection for all compilers.
#include <utility>
class A
{
friend bool operator<(const A &lhs, const A &rhs)
{
return false;
}
};
class B: A
{};
template <typename T>
class HasLess {
template <typename U>
static char (&check (int))[1 + sizeof(decltype(std::declval<U>() < std::declval<U>()))];
template <typename>
static char (&check (...))[1];
public:
static constexpr const bool value = sizeof (check<T> (0)) != 1;
};
int main(void)
{
B b;
static_assert(HasLess<A>::value, "");
static_assert(!HasLess<B>::value, "");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment