Skip to content

Commit c5ba46e

Browse files
committed
[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
1 parent 1baf1fc commit c5ba46e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

libcxx/test/support/allocators.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,26 @@ template <class T, bool POCCAValue>
189189
class MaybePOCCAAllocator {
190190
int id_ = 0;
191191
bool* copy_assigned_into_ = nullptr;
192+
193+
template<class, bool> friend class MaybePOCCAAllocator;
194+
192195
public:
193196
typedef std::integral_constant<bool, POCCAValue> propagate_on_container_copy_assignment;
194197
typedef T value_type;
195198

199+
template <class U>
200+
struct rebind {
201+
typedef MaybePOCCAAllocator<U, POCCAValue> other;
202+
};
203+
196204
MaybePOCCAAllocator() = default;
197205
MaybePOCCAAllocator(int id, bool* copy_assigned_into)
198206
: id_(id), copy_assigned_into_(copy_assigned_into) {}
199207

208+
template <class U>
209+
MaybePOCCAAllocator(const MaybePOCCAAllocator<U, POCCAValue>& that)
210+
: id_(that.id_), copy_assigned_into_(that.copy_assigned_into_) {}
211+
200212
MaybePOCCAAllocator(const MaybePOCCAAllocator&) = default;
201213
MaybePOCCAAllocator& operator=(const MaybePOCCAAllocator& a)
202214
{
@@ -218,12 +230,14 @@ class MaybePOCCAAllocator {
218230

219231
int id() const { return id_; }
220232

221-
friend bool operator==(const MaybePOCCAAllocator& lhs, const MaybePOCCAAllocator& rhs)
233+
template <class U>
234+
friend bool operator==(const MaybePOCCAAllocator& lhs, const MaybePOCCAAllocator<U, POCCAValue>& rhs)
222235
{
223236
return lhs.id() == rhs.id();
224237
}
225238

226-
friend bool operator!=(const MaybePOCCAAllocator& lhs, const MaybePOCCAAllocator& rhs)
239+
template <class U>
240+
friend bool operator!=(const MaybePOCCAAllocator& lhs, const MaybePOCCAAllocator<U, POCCAValue>& rhs)
227241
{
228242
return !(lhs == rhs);
229243
}

0 commit comments

Comments
 (0)