![](/img/trans.png)
[英]Why is `std::reference_wrapper` deprecated in c++17 and removed in c++20?
[英]Why rebind<U>::other are deprecated in C++17 and removed in C++20?
我知道它只在 std::allocator 中被棄用和刪除。 我可以在我自己的分配器上實現它。 但為什么它被棄用?
rebind
是一種笨拙的 C++11 之前的方法,它采用T
的分配器類型並將其轉換為U
的分配器類型。 我說“pre-C++11”是因為 C++11 給了我們一個更方便的方法:模板別名。
allocator_traits
模板有一個成員模板別名rebind<U>
,它為它是一個特征的分配器計算Allocator<U>
。 如果可用,它可以使用分配器的rebind
成員,否則,它只會產生Allocator<U>
。
allocator_traits
有效地定義了許多std::allocator
過去提供的功能。 這使得std::allocator
的許多成員變得多余,因此它們已被棄用並刪除以支持基於traits
的默認值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.