std::nullopt_t

From cppreference.com
< cpp‎ | utility‎ | optional
 
 
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)(C++20)(C++20)   
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)
Elementary string conversions
(C++17)
(C++17)
 
std::optional
Member functions
Observers
Monadic operations
Modifiers
Non-member functions
(C++17)(C++17)(C++17)(C++17)(C++17)(C++17)(C++20)
(C++17)
Deduction guides
Helper classes
(C++17)
nullopt_t
(C++17)
(C++17)
Helper objects
(C++17)
(C++17)
 
Defined in header <optional>
struct nullopt_t;
(since C++17)

std::nullopt_t is an empty class type used to indicate optional type with uninitialized state. In particular, std::optional has a constructor with nullopt_t as a single argument, which creates an optional that does not contain a value.

std::nullopt_t must be a non-aggregate LiteralType and cannot have a default constructor or an initializer-list constructor.

It must have a constexpr constructor that takes some implementation-defined literal type.

Notes

The constraints on nullopt_t's constructors exist to support both op = {}; and op = nullopt; as the syntax for disengaging an optional object.

A possible implementation of this class is

struct nullopt_t {
    constexpr explicit nullopt_t(int) {}
};

See also

(C++17)
an object of type nullopt_t
(constant)