[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / support / allocators.h
blobeae51909ed69780a01d94bfba033d446368e739e
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef ALLOCATORS_H
10 #define ALLOCATORS_H
12 #include <type_traits>
13 #include <utility>
15 #include "test_macros.h"
17 #if TEST_STD_VER >= 11
19 template <class T>
20 class A1
22 int id_;
23 public:
24 explicit A1(int id = 0) TEST_NOEXCEPT : id_(id) {}
26 typedef T value_type;
28 int id() const {return id_;}
30 static bool copy_called;
31 static bool move_called;
32 static bool allocate_called;
33 static std::pair<T*, std::size_t> deallocate_called;
35 A1(const A1& a) TEST_NOEXCEPT : id_(a.id()) {copy_called = true;}
36 A1(A1&& a) TEST_NOEXCEPT : id_(a.id()) {move_called = true;}
37 A1& operator=(const A1& a) TEST_NOEXCEPT { id_ = a.id(); copy_called = true; return *this;}
38 A1& operator=(A1&& a) TEST_NOEXCEPT { id_ = a.id(); move_called = true; return *this;}
40 template <class U>
41 A1(const A1<U>& a) TEST_NOEXCEPT : id_(a.id()) {copy_called = true;}
42 template <class U>
43 A1(A1<U>&& a) TEST_NOEXCEPT : id_(a.id()) {move_called = true;}
45 T* allocate(std::size_t n)
47 allocate_called = true;
48 return (T*)n;
51 void deallocate(T* p, std::size_t n)
53 deallocate_called = std::pair<T*, std::size_t>(p, n);
56 std::size_t max_size() const {return id_;}
59 template <class T> bool A1<T>::copy_called = false;
60 template <class T> bool A1<T>::move_called = false;
61 template <class T> bool A1<T>::allocate_called = false;
62 template <class T> std::pair<T*, std::size_t> A1<T>::deallocate_called;
64 template <class T, class U>
65 inline
66 bool operator==(const A1<T>& x, const A1<U>& y)
68 return x.id() == y.id();
71 template <class T, class U>
72 inline
73 bool operator!=(const A1<T>& x, const A1<U>& y)
75 return !(x == y);
78 template <class T>
79 class A2
81 int id_;
82 public:
83 explicit A2(int id = 0) TEST_NOEXCEPT : id_(id) {}
85 typedef T value_type;
87 typedef unsigned size_type;
88 typedef int difference_type;
90 typedef std::true_type propagate_on_container_move_assignment;
92 int id() const {return id_;}
94 static bool copy_called;
95 static bool move_called;
96 static bool allocate_called;
98 A2(const A2& a) TEST_NOEXCEPT : id_(a.id()) {copy_called = true;}
99 A2(A2&& a) TEST_NOEXCEPT : id_(a.id()) {move_called = true;}
100 A2& operator=(const A2& a) TEST_NOEXCEPT { id_ = a.id(); copy_called = true; return *this;}
101 A2& operator=(A2&& a) TEST_NOEXCEPT { id_ = a.id(); move_called = true; return *this;}
103 T* allocate(std::size_t, const void* hint)
105 allocate_called = true;
106 return (T*) const_cast<void *>(hint);
110 template <class T> bool A2<T>::copy_called = false;
111 template <class T> bool A2<T>::move_called = false;
112 template <class T> bool A2<T>::allocate_called = false;
114 template <class T, class U>
115 inline
116 bool operator==(const A2<T>& x, const A2<U>& y)
118 return x.id() == y.id();
121 template <class T, class U>
122 inline
123 bool operator!=(const A2<T>& x, const A2<U>& y)
125 return !(x == y);
128 template <class T>
129 class A3
131 int id_;
132 public:
133 explicit A3(int id = 0) TEST_NOEXCEPT : id_(id) {}
135 typedef T value_type;
137 typedef std::true_type propagate_on_container_copy_assignment;
138 typedef std::true_type propagate_on_container_swap;
140 int id() const {return id_;}
142 static bool copy_called;
143 static bool move_called;
144 static bool constructed;
145 static bool destroy_called;
147 A3(const A3& a) TEST_NOEXCEPT : id_(a.id()) {copy_called = true;}
148 A3(A3&& a) TEST_NOEXCEPT : id_(a.id()) {move_called = true;}
149 A3& operator=(const A3& a) TEST_NOEXCEPT { id_ = a.id(); copy_called = true; return *this;}
150 A3& operator=(A3&& a) TEST_NOEXCEPT { id_ = a.id(); move_called = true; return *this;}
152 template <class U, class ...Args>
153 void construct(U* p, Args&& ...args)
155 ::new (p) U(std::forward<Args>(args)...);
156 constructed = true;
159 template <class U>
160 void destroy(U* p)
162 p->~U();
163 destroy_called = true;
166 A3 select_on_container_copy_construction() const {return A3(-1);}
169 template <class T> bool A3<T>::copy_called = false;
170 template <class T> bool A3<T>::move_called = false;
171 template <class T> bool A3<T>::constructed = false;
172 template <class T> bool A3<T>::destroy_called = false;
174 template <class T, class U>
175 inline
176 bool operator==(const A3<T>& x, const A3<U>& y)
178 return x.id() == y.id();
181 template <class T, class U>
182 inline
183 bool operator!=(const A3<T>& x, const A3<U>& y)
185 return !(x == y);
188 #endif // TEST_STD_VER >= 11
190 #endif // ALLOCATORS_H