1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
13 #include <type_traits>
16 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
23 explicit A1(int id = 0) : id_(id) {}
27 int id() const {return id_;}
29 static bool copy_called;
30 static bool move_called;
31 static bool allocate_called;
32 static std::pair<T*, std::size_t> deallocate_called;
34 A1(const A1& a) : id_(a.id()) {copy_called = true;}
35 A1(A1&& a) : id_(a.id()) {move_called = true;}
38 A1(const A1<U>& a) : id_(a.id()) {copy_called = true;}
40 A1(A1<U>&& a) : id_(a.id()) {move_called = true;}
42 T* allocate(std::size_t n)
44 allocate_called = true;
48 void deallocate(T* p, std::size_t n)
50 deallocate_called = std::pair<T*, std::size_t>(p, n);
53 std::size_t max_size() const {return id_;}
56 template <class T> bool A1<T>::copy_called = false;
57 template <class T> bool A1<T>::move_called = false;
58 template <class T> bool A1<T>::allocate_called = false;
59 template <class T> std::pair<T*, std::size_t> A1<T>::deallocate_called;
61 template <class T, class U>
63 bool operator==(const A1<T>& x, const A1<U>& y)
65 return x.id() == y.id();
68 template <class T, class U>
70 bool operator!=(const A1<T>& x, const A1<U>& y)
80 explicit A2(int id = 0) : id_(id) {}
84 typedef unsigned size_type;
85 typedef int difference_type;
87 typedef std::true_type propagate_on_container_move_assignment;
89 int id() const {return id_;}
91 static bool copy_called;
92 static bool move_called;
93 static bool allocate_called;
95 A2(const A2& a) : id_(a.id()) {copy_called = true;}
96 A2(A2&& a) : id_(a.id()) {move_called = true;}
98 T* allocate(std::size_t n, const void* hint)
100 allocate_called = true;
105 template <class T> bool A2<T>::copy_called = false;
106 template <class T> bool A2<T>::move_called = false;
107 template <class T> bool A2<T>::allocate_called = false;
109 template <class T, class U>
111 bool operator==(const A2<T>& x, const A2<U>& y)
113 return x.id() == y.id();
116 template <class T, class U>
118 bool operator!=(const A2<T>& x, const A2<U>& y)
128 explicit A3(int id = 0) : id_(id) {}
130 typedef T value_type;
132 typedef std::true_type propagate_on_container_copy_assignment;
133 typedef std::true_type propagate_on_container_swap;
135 int id() const {return id_;}
137 static bool copy_called;
138 static bool move_called;
139 static bool constructed;
140 static bool destroy_called;
142 A3(const A3& a) : id_(a.id()) {copy_called = true;}
143 A3(A3&& a) : id_(a.id()) {move_called = true;}
145 template <class U, class ...Args>
146 void construct(U* p, Args&& ...args)
148 ::new (p) U(std::forward<Args>(args)...);
156 destroy_called = true;
159 A3 select_on_container_copy_construction() const {return A3(-1);}
162 template <class T> bool A3<T>::copy_called = false;
163 template <class T> bool A3<T>::move_called = false;
164 template <class T> bool A3<T>::constructed = false;
165 template <class T> bool A3<T>::destroy_called = false;
167 template <class T, class U>
169 bool operator==(const A3<T>& x, const A3<U>& y)
171 return x.id() == y.id();
174 template <class T, class U>
176 bool operator!=(const A3<T>& x, const A3<U>& y)
181 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
183 #endif // ALLOCATORS_H