繁体   English   中英

std :: nullptr_t类型的prvalue

[英]prvalue of type std::nullptr_t

第4.10 / 1节N3797说:

空指针常量是值为零的整数文字(2.14.2)或类型为std :: nullptr_t的prvalue。

我认为nullptrstd::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()
  • 调用lambda返回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" : nullptrfalse ? 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM