简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM