[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
This commit is contained in:
Casey Carter 2022-01-06 18:45:28 -08:00
parent 1baf1fc276
commit c5ba46ea18
1 changed files with 16 additions and 2 deletions

View File

@ -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 @@ public:
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);
}