对于 std::variant 有 uses_allocator 的特化,但对于 std::optional 没有。为什么?
最佳答案
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/