Home > Net >  Why rebind<U>::other are deprecated in C 17 and removed in C 20?
Why rebind<U>::other are deprecated in C 17 and removed in C 20?

Time:11-11

I know that it deprecated and removed only in std::allocator. And I can implement it on my own allocators. But why it is deprecated?

CodePudding user response:

rebind was a clunky, pre-C 11 way of taking an allocator type for T and converting it into an allocator type for U. I say "pre-C 11" because C 11 gave us a much more convenient way to do it: template aliases.

allocator_traits template has a member template alias rebind<U> that computes Allocator<U> for the allocator it is a trait for. It can use the rebind member of the allocator if it is available, otherwise, it just yields Allocator<U>.

allocator_traits effectively defines a lot of functionality that std::allocator used to provide. This made a lot of members of std::allocator redundant, so they have been deprecated and removed in favor of the traits-based defaults.

  • Related