std::is_default_constructible, std::is_trivially_default_constructible, std::is_nothrow_default_constructible
Min standard notice:
Header: <type_traits>
- Provides the member constant value equal to std::is_constructible
::value.
# Declarations
template< class T >
struct is_default_constructible;
(since C++11)
template< class T >
struct is_trivially_default_constructible;
(since C++11)
template< class T >
struct is_nothrow_default_constructible;
(since C++11)
# Notes
In many implementations, std::is_nothrow_default_constructible also checks if the destructor throws because it is effectively noexcept(T()). Same applies to std::is_trivially_default_constructible, which, in these implementations, also requires that the destructor is trivial: GCC bug 51452, LWG issue 2116.
std::is_default_constructible
# Example
#include <string>
#include <type_traits>
struct S1
{
std::string str; // member has a non-trivial default constructor
};
static_assert(std::is_default_constructible_v<S1> == true);
static_assert(std::is_trivially_default_constructible_v<S1> == false);
struct S2
{
int n;
S2() = default; // trivial and non-throwing
};
static_assert(std::is_trivially_default_constructible_v<S2> == true);
static_assert(std::is_nothrow_default_constructible_v<S2> == true);
int main() {}