std::default_initializable(3)
πΈ NAME πΈ
okay bestie, welcome to the std::default_initializable(3) page from the C++ Standard Libary manual π«Ά and the name entry is literally std::default_initializable β std::default_initializable (yes, twice, and honestly? iconic).
β¨ Synopsis β¨
Itβs defined in header <concepts>, and itβs been a thing since C++20. The synopsis is giving exactly this:
Defined in header <concepts>
template< class T >
concept default_initializable = std::constructible_from<T> &&
(since C++20)
requires { T{}; } &&
/* T t; is well-formed, see below */;
So what does the default_initializable concept actually check? It checks whether variables of type T can be:
- value-initialized (
T()is well-formed); - direct-list-initialized from an empty initializer list (
T{}is well-formed); and - default-initialized (
T t;is well-formed).
And this part is important, no cap: access checking is performed as if in a context unrelated to T. Only the validity of the immediate context of the variable initialization is considered. π
π₯ Possible implementation π₯
Hereβs one possible implementation, and yes itβs lowkey minimal:
template<class T>
concept default_initializable =
std::constructible_from<T> &&
requires { T{}; } &&
requires { ::new T; };
π See also π
constructible_from(C++20) β specifies that a variable of the type can be constructed from or bound to a set of argument types (concept).is_default_constructible(C++11) β checks if a type has a default constructor (class template).is_trivially_default_constructible(C++11) β checks if a type has a default constructor (class template).is_nothrow_default_constructible(C++11) β checks if a type has a default constructor (class template).
mwah π thatβs the page! source/version/date vibes: http://cppreference.com, 2024.06.10, page std::default_initializable(3). bye bestie π«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms