CKTIS / C++
std::nullptr_t — the type of nullptr
std::nullptr_t is the distinct type of the nullptr literal, made available by <cstddef>. It is not a pointer type: its values can produce null pointers, while the type itself lets function overloads recognize nullptr.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
#include <cstddef>
std::nullptr_t value = nullptr;
// std::nullptr_t is the same type as decltype(nullptr).std::nullptr_t is the type of the nullptr literal. The <cstddef> header makes this name available in namespace std; it denotes the same type as decltype(nullptr). Distinguish the type std::nullptr_t, the literal nullptr, and a pointer with a null value, such as a variable declared as int* pointer = nullptr;.
std::nullptr_t is neither a pointer type nor a pointer-to-member type. A value of this type can be implicitly converted to the null value of an appropriate pointer or pointer-to-member type. This conversion does not create an object to point to; the resulting null pointer must not be dereferenced.
The distinct type matters for function overloading. In the example, select(0) selects the int parameter, select(nullptr) selects std::nullptr_t, and select(pointer) selects int*, even though pointer holds a null value. Selection depends on the argument's type and conversion rules, not merely on whether a pointer is null. Do not treat NULL as another spelling of nullptr: that macro's definition is implementation-defined and can have an integer type.
You can verify the example locally in C++23 mode. The displayed code was run unchanged in an isolated environment, and its standard output matched the expected output exactly. The supplied sources are a living working draft, not a frozen C++23 publication. A compiler flag does not attest behavior in a production runtime environment.
Examples
#include <cstddef>
#include <iostream>
const char* select(int) { return "int"; }
const char* select(int*) { return "int*"; }
const char* select(std::nullptr_t) { return "nullptr_t"; }
int main() {
std::nullptr_t empty = nullptr;
int* pointer = empty;
std::cout << select(0) << '\n';
std::cout << select(nullptr) << '\n';
std::cout << select(pointer) << '\n';
std::cout << std::boolalpha << (pointer == nullptr) << '\n';
}
Result
int nullptr_t int* true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.