c++ - 为什么没有 std::uses_allocator<std::optional>?

标签 c++ allocator

对于 std::variant 有 uses_allocator 的特化,但对于 std::optional 没有。为什么?

最佳答案

来自Standard 23.6.3.1 :

Implementations are not permitted to use additional storage, such as dynamic memory, to allocate its contained value.

因此不需要分配器。

尽管变体 23.7.3.1 也是如此:

Implementations are not permitted to use additional storage, such as dynamic memory, to allocate the contained value.

显然,uses_allocator 专门用于 std::variant was removed for C++17 (HT:@K-ballo!)。

关于c++ - 为什么没有 std::uses_allocator<std::optional>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45841511/

相关文章:

c++ - GCC 对 lambda 中的静态变量做了什么?

c++ - 漫谈 std::allocator

c++ - 强制 vector 的分配器指向特定位置

c++ - std::map 标准分配器性能与 block 分配器

c++ - boost 分配器无法在递归上下文中编译

c++ - 这是为 std::allocator 存储状态的正确方法吗?在本例中,由 Windows 上的共享内存支持?

c++ - 是否保证 std::vector 默认构造不会调用 new?

c++ - 指向数组的指针和指向数组第一个元素的指针之间的区别

c++ - 如何在 C++ 中打乱指针列表?

c++ - 将命令从 C++ 程序传递到终端的问题