Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading