isdefaultconstructible3.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 "
issame.hpp
"
#include <type_traits>
// defines true_type and false_type
// helper to ignore any number of template parameters:
template<typename...> using VoidT = void;
// primary template:
template<typename, typename = VoidT<>>
struct IsDefaultConstructibleT : std::false_type
{
};
// partial specialization (may be SFINAE'd away):
template<typename T>
struct IsDefaultConstructibleT<T, VoidT<decltype(T())>> : std::true_type
{
};