Here is a declaration of nullptr_t
in <cstddef>
:
namespace std {
typedef decltype(nullptr) nullptr_t;
}
According to this, std::nullptr_t
is an alias for some unspecified fundamental type of which nullptr
is an instance. So the actual type of nullptr
doesn't have a name (well, the language does not give it a name, the name was given by standard library).
nullptr
itself is a keyword. But standard did not introduce a keyword for type of nullptr
. Instead using decltype(nullptr)
is offered.
What are reasons for doing this? I found it much confusing. You need to include header and specify std::
for just using a language built-in feature.
Is this to keep the set of C++ keywords as small as possible? Is this specifically for nullptr
or committee is going to declare all new types like this, so we would have namespace std { typedef decltype(false) bool; }
if such decision was made earlier?