Created
February 5, 2017 05:01
-
-
Save Alexhuszagh/7fc6195f98b8cac85a10cdb5360767fe to your computer and use it in GitHub Desktop.
Sfinae detection for all compilers.
This file contains hidden or 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 <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