Actually this is not possible (in pure C ++).
Detecting whether the type has a default constructor in SFINAE because it only includes an interface, but detects if implementation inclusion is trivial.
Therefore, the compiler must provide a specific property for this. You can find the list of built-in here , note that some of them are provided, because they require compiler intervention, while others can only be provided in order to have a single set or optimize the implementation of the standard library.
Most often you are looking for either __has_trivial_constructor , which is also supported by gcc and MSVC according to the comments or __is_trivially_constructible (specific to Clang). I must admit that I'm a little unsure of the former (what if the type has several constructors?), The latter can be used as:
template <typename T> struct has_trivial_default_constructor { static bool const value = __is_trivially_constructible(T); };
Matthieu M.
source share