弃用std :: allocator< void> [英] Deprecation of std::allocator<void>

查看:221
本文介绍了弃用std :: allocator< void>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相关:为什么标准容器要求allocator_type :: value_type为元素类型?

据说自C ++ 17起不推荐使用以下内容:

It is said that the following has been deprecated since C++17:

template<>
struct allocator<void>;

我想知道是否不推荐使用它,因为仅主模板现在就可以容纳allocator<void>,或者不推荐使用allocator<void>的用例.

I wonder whether it is deprecated because the primary template alone is now able to accommodate allocator<void>, or the use-case of allocator<void> is deprecated.

如果是后者,我想知道为什么.我认为allocator<void>在指定未绑定到特定类型(因此仅是某些架构/元数据)的分配器时很有用.

If latter, I wonder why. I think allocator<void> is useful in specifying an allocator not bound to a specific type (so just some schema/metadata).

推荐答案

根据

类似地,定义std::allocator<void>以便各种模板 重新绑定的技巧可能在原始的C ++ 98库中起作用,但是它是 不是实际的分配器,因为它同时缺少allocatedeallocate 成员函数,默认情况下无法从 allocator_traits. C ++ 11和void_pointer消除了这种需求 和const_void_pointer在allocator_traits中键入别名.但是,我们 继续指定它,以避免破坏具有 根据C ++ 11,尚未升级为支持通用分配器.

Similarly, std::allocator<void> is defined so that various template rebinding tricks could work in the original C++98 library, but it is not an actual allocator, as it lacks both allocate and deallocate member functions, which cannot be synthesized by default from allocator_traits. That need went away with C++11 and the void_pointer and const_void_pointer type aliases in allocator_traits. However, we continue to specify it in order to avoid breaking old code that has not yet been upgraded to support generic allocators, per C++11.

这篇关于弃用std :: allocator&lt; void&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆