[libcxx-commits] [libcxx] c5ba46e - [libcxx][test] MaybePOCCAAllocator should meet the Cpp17Allocator requirements

Casey Carter via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jun 25 11:04:10 PDT 2022


Author: Casey Carter
Date: 2022-06-25T11:02:42-07:00
New Revision: c5ba46ea1804dfefb22e6d2bb65ff1636d2cc8cd

URL: https://github.com/llvm/llvm-project/commit/c5ba46ea1804dfefb22e6d2bb65ff1636d2cc8cd
DIFF: https://github.com/llvm/llvm-project/commit/c5ba46ea1804dfefb22e6d2bb65ff1636d2cc8cd.diff

LOG: [libcxx][test] MaybePOCCAAllocator should meet the Cpp17Allocator requirements

Implement `rebind`, the rebinding constructor, and rebind-compatible comparison operators.

Differential Revision: https://reviews.llvm.org/D118279

Added: 
    

Modified: 
    libcxx/test/support/allocators.h

Removed: 
    


################################################################################
diff  --git a/libcxx/test/support/allocators.h b/libcxx/test/support/allocators.h
index f8e0c1b5e4cba..fce43acf129be 100644
--- a/libcxx/test/support/allocators.h
+++ b/libcxx/test/support/allocators.h
@@ -189,14 +189,26 @@ template <class T, bool POCCAValue>
 class MaybePOCCAAllocator {
     int id_ = 0;
     bool* copy_assigned_into_ = nullptr;
+
+    template<class, bool> friend class MaybePOCCAAllocator;
+
 public:
     typedef std::integral_constant<bool, POCCAValue> propagate_on_container_copy_assignment;
     typedef T value_type;
 
+    template <class U>
+    struct rebind {
+        typedef MaybePOCCAAllocator<U, POCCAValue> other;
+    };
+
     MaybePOCCAAllocator() = default;
     MaybePOCCAAllocator(int id, bool* copy_assigned_into)
         : id_(id), copy_assigned_into_(copy_assigned_into) {}
 
+    template <class U>
+    MaybePOCCAAllocator(const MaybePOCCAAllocator<U, POCCAValue>& that)
+        : id_(that.id_), copy_assigned_into_(that.copy_assigned_into_) {}
+
     MaybePOCCAAllocator(const MaybePOCCAAllocator&) = default;
     MaybePOCCAAllocator& operator=(const MaybePOCCAAllocator& a)
     {
@@ -218,12 +230,14 @@ class MaybePOCCAAllocator {
 
     int id() const { return id_; }
 
-    friend bool operator==(const MaybePOCCAAllocator& lhs, const MaybePOCCAAllocator& rhs)
+    template <class U>
+    friend bool operator==(const MaybePOCCAAllocator& lhs, const MaybePOCCAAllocator<U, POCCAValue>& rhs)
     {
         return lhs.id() == rhs.id();
     }
 
-    friend bool operator!=(const MaybePOCCAAllocator& lhs, const MaybePOCCAAllocator& rhs)
+    template <class U>
+    friend bool operator!=(const MaybePOCCAAllocator& lhs, const MaybePOCCAAllocator<U, POCCAValue>& rhs)
     {
         return !(lhs == rhs);
     }


        


More information about the libcxx-commits mailing list