[英]prvalue of type std::nullptr_t
第4.10 / 1节N3797说:
空指针常量是值为零的整数文字(2.14.2)或类型为std :: nullptr_t的prvalue。
我认为nullptr
是std::nullptr_t
类型的prvalue
。 你会得到更多关于这种prvalue
例子吗?
与任何类型一样,有多种方法可以获得类型为std::nullptr_t
的prvalue:
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
而另一方具有不同的值类别或者是throw-expression: false ? throw "oops" : nullptr
false ? throw "oops" : nullptr
, false ? std::move(nullptr) : nullptr
false ? std::move(nullptr) : nullptr
因为std::nullptr_t
不参与大多数运营商,所以这是一个相当std::nullptr_t
清单; 大多数其他类型为std::nullptr_t
将产生glvalues。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.