Skip to content

Instantly share code, notes, and snippets.

@cppcooper
Created March 15, 2022 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cppcooper/9b96a3164c3f658a4150ebd8391afdbe to your computer and use it in GitHub Desktop.
Save cppcooper/9b96a3164c3f658a4150ebd8391afdbe to your computer and use it in GitHub Desktop.
member detection with templates/macro
#include <type_traits>
#define DECLARE_HASA(what) \
template<typename T, typename = int> struct has_##what : std::false_type { };\
template<typename T> struct has_##what<T, decltype((void) T::what, 0)> : std::true_type {};
DECLARE_HASA(when) //declares above statement with 'when' replacing 'what'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment