c++ - 移除 std::future 和 std::promise 的无效特化

标签 c++ c++11 c++14 future c++17

关于描述删除 std::future 和 std::promise 的无效特化的论文 P0241R0 .这可能是一个愚蠢的问题,但建议的解决方案是完全删除 void 特化,但是当人们想要实例化一个 std::future<void> 时,他们期望做什么?目的?

最佳答案

如引用文献中所述,这是可能的 if void were a regular type .

void get_value() {
    void x;
    return x;
}

这是它在其他一些语言中的工作方式,因此并非没有先例。在其他语言中,它被称为“单位”类型,因为它只有一个可能的值。 (其他语言也有“null”类型,它没有可能的值,所以如果你试图创建一个类型,你会得到一个错误。它被命名为“null”,但它与空指针无关。)

关于c++ - 移除 std::future 和 std::promise 的无效特化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44079787/

相关文章:

c++ - 如何在 C++ 中创建高效的二维网格?

multithreading - socket() 在 std::thread 中返回文件描述符 1

c++ - 错误 : 'anil' was not declared in this scope

c++ - 错误 : 'int_type' does not name a type - How to inherit typedefs and usings

c++ - 使用 libtar 压缩目录

c++ - 在 C++ 中调用指向成员函数的指针时出错

c++ - 为什么函数原型(prototype)在不需要时包含参数名称?

c++ - 如何在进入函数之前指定需要什么互斥锁

linux - Boost Spirit 3.0.0的安装步骤是怎样的?

c++ - 这些 vector 定义是 "constant initialization"吗?