Created
September 14, 2015 20:50
-
-
Save taketwo/0d840b7bff3139af7e87 to your computer and use it in GitHub Desktop.
A c++11 metafunction to check if a class has a method
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
// Create a metafunction "has_xxx_method" that can be used | |
// to check if a class has a method called "xxx". Note the | |
// limitation: only existence of parameterless methods can | |
// be checked this way. | |
// Credits: http://stackoverflow.com/a/21827727/1525865 | |
#define HAS_METHOD_DEF(xxx) \ | |
template<typename T> \ | |
constexpr auto has_ ## xxx ## _method(int) \ | |
-> decltype(std::declval<T>(). xxx (), bool()) \ | |
{ return true; } \ | |
template<typename T> \ | |
constexpr bool has_ ## xxx ## _method(...) \ | |
{ return false; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment