Section 4.10/1 N3797 says:
A null pointer constant is an integer literal (2.14.2) with value zero or a prvalue of type std::nullptr_t.
I think nullptr
is a prvalue
of type std::nullptr_t
. Would you get a bit more examples of such prvalue
?
As with any type, there are various ways to get a prvalue of type std::nullptr_t
:
static_cast<std::nullptr_t>(0)
std::nullptr_t{}
std::nullptr_t
: std::nullptr_t f() { return {}; } f()
std::nullptr_t f() { return {}; } f()
std::nullptr_t
: []() -> std::nullptr_t { return {}; }()
[]() -> std::nullptr_t { return {}; }()
std::nullptr_t
prvalue: ("hello", nullptr)
std::nullptr_t
and the other side is of a different value category or is a throw-expression: false ? throw "oops" : nullptr
false ? throw "oops" : nullptr
, false ? std::move(nullptr) : nullptr
false ? std::move(nullptr) : nullptr
Because std::nullptr_t
does not participate in most operators, this is a reasonably exhaustative list; most other expressions with type std::nullptr_t
will yield glvalues.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.