hastype.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_TYPE(MemType)                                   \
  template<typename, typename = std::void_t<>>                     \
  struct HasTypeT_##MemType                                        \
   : std::false_type { };                                          \
  template<typename T>                                             \
  struct HasTypeT_##MemType<T, std::void_t<typename T::MemType>>   \
   : std::true_type { } // ; intentionally skipped