[英]Why rebind<U>::other are deprecated in C++17 and removed in C++20?
I know that it deprecated and removed only in std::allocator.我知道它只在 std::allocator 中被弃用和删除。 And I can implement it on my own allocators.
我可以在我自己的分配器上实现它。 But why it is deprecated?
但为什么它被弃用?
rebind
was a clunky, pre-C++11 way of taking an allocator type for T
and converting it into an allocator type for U
. rebind
是一种笨拙的 C++11 之前的方法,它采用T
的分配器类型并将其转换为U
的分配器类型。 I say "pre-C++11" because C++11 gave us a much more convenient way to do it: template aliases.我说“pre-C++11”是因为 C++11 给了我们一个更方便的方法:模板别名。
allocator_traits
template has a member template alias rebind<U>
that computes Allocator<U>
for the allocator it is a trait for. allocator_traits
模板有一个成员模板别名rebind<U>
,它为它是一个特征的分配器计算Allocator<U>
。 It can use the rebind
member of the allocator if it is available, otherwise, it just yields Allocator<U>
.如果可用,它可以使用分配器的
rebind
成员,否则,它只会产生Allocator<U>
。
allocator_traits
effectively defines a lot of functionality that std::allocator
used to provide. allocator_traits
有效地定义了许多std::allocator
过去提供的功能。 This made a lot of members of std::allocator
redundant, so they have been deprecated and removed in favor of the traits
-based defaults.这使得
std::allocator
的许多成员变得多余,因此它们已被弃用并删除以支持基于traits
的默认值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.