prvalue of type std::nullptr_t
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
:[]() -> std::nullptr_t { return {}; }()
的lambda - 右侧为
std::nullptr_t
的逗号表达式prvalue:("hello", nullptr)
- 一个条件表达式,其中一侧具有类型
std::nullptr_t
,另一侧具有不同的值类别,或者是抛出表达式:false ? throw "oops" : nullptr
、false ? std::move(nullptr) : nullptr
由于std::nullptr_t
不参与大多数运算符,因此这是一个相当详尽的列表;类型为CCD_ 18的大多数其他表达式将产生glvalues。
相关文章:
- 为什么"weak.lock()"返回"nullptr" "auto weak=std::make_shared<int>(42);"的定义?
- 使用 nullptr 作为 std::unordered_map 的键有什么后果吗?
- 为什么 char 可以在 std::array 中初始化为 nullptr,而不是单独初始化?
- C++ - 向量中的 std::unique_ptr <> 为 nullptr
- std::rethrow_exception(nullptr) 未定义的行为还是bad_exception?
- std::string::c_str() 曾经返回 nullptr 吗?
- 'const std::string&s = nullptr' 如何作为可选参数工作
- 使用 std::可选标准化,我们可以停止在新代码中使用 nullptr 并弃用它吗?
- 一旦 std::weak_ptr 上的锁返回了 nullptr,它是否还会再次成为非 null
- std::unique_ptr 是否在其析构函数中将其基础指针设置为 nullptr?
- std :: malloc在失败时返回null或nullptr吗?
- 在C 11中,Dynamic_cast返回null或std :: nullptr会发生失败
- 在为其分配一个新值之前,应将`nullptr`分配给`sTD :: simelod_ptr`
- 为什么可以将NULLPTR分配给STD :: String
- C 如何检测何时将nullptr传递到预期std :: string的功能
- 为什么 empty() std::basic_string c_str() 不是 nullptr?
- 将 nullptr 分配给 std::string 是安全的
- std::将成员函数绑定到 nullptr 处的实例,导致看似随机的 this 指针
- 将 NULL/nullptr 转换为 std::function<>& 时失败
- 当使用const std::string&作为方法参数类型时,处理nullptr const char*的正确方法是什么?