在c ++ 17之前,如果您有类似的分配器,则Allocator<typename, size_t>可以使用rebind结构。但是现在,在C ++ 17中,不推荐使用rebind结构。从中构造an的解决方案allocator<T,size_t>是allocator<T2, size_t>什么?
只有std::allocator的rebind成员模板已被弃用。如果您使用自己的课程,则仍然可以定义rebind。
通过完成std::allocator_traits,例如:
using AllocatorForU = std::allocator_traits<AllocatorForT>::template rebind_alloc<U>;
Run Code Online (Sandbox Code Playgroud)
默认为rebind_alloc为AllocatorTemplate<T, OtherTypes...>IS AllocatorTemplate<U, OtherTypes...>,它适用于std::allocator,这就是为什么std::allocator<T>::rebind已经过时了。您必须为您的类定义它,因为它具有非类型模板参数。
| 归档时间: |
|
| 查看次数: |
142 次 |
| 最近记录: |