hasmember.hpp

The following code example is taken from the book
C++ Templates - The Complete Guide, 2nd Edition
by David Vandevoorde, Nicolai M. Josuttis, and Douglas Gregor,
Addison-Wesley, 2017
© Copyright David Vandevoorde, Nicolai M. Josuttis, Douglas Gregor 2017


#include <type_traits>  // for true_type, false_type, and void_t

#define DEFINE_HAS_MEMBER(Member)                                   \
  template<typename, typename = std::void_t<>>                      \
  struct HasMemberT_##Member                                        \
   : std::false_type { };                                           \
  template<typename T>                                              \
  struct HasMemberT_##Member<T, std::void_t<decltype(&T::Member)>>  \
   : std::true_type { } // ; intentionally skipped