Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. And I can implement it on my own allocators. But why it is deprecated?

like image 243
dasfex Avatar asked Sep 06 '25 03:09

dasfex


1 Answers

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.

like image 195
Nicol Bolas Avatar answered Sep 07 '25 21:09

Nicol Bolas