1*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===// 2*0a6a1f1dSLionel Sambuc // 3*0a6a1f1dSLionel Sambuc // The LLVM Compiler Infrastructure 4*0a6a1f1dSLionel Sambuc // 5*0a6a1f1dSLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open 6*0a6a1f1dSLionel Sambuc // Source Licenses. See LICENSE.TXT for details. 7*0a6a1f1dSLionel Sambuc // 8*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===// 9*0a6a1f1dSLionel Sambuc 10*0a6a1f1dSLionel Sambuc #ifndef ALLOCATORS_H 11*0a6a1f1dSLionel Sambuc #define ALLOCATORS_H 12*0a6a1f1dSLionel Sambuc 13*0a6a1f1dSLionel Sambuc #include <type_traits> 14*0a6a1f1dSLionel Sambuc #include <utility> 15*0a6a1f1dSLionel Sambuc 16*0a6a1f1dSLionel Sambuc #include "test_macros.h" 17*0a6a1f1dSLionel Sambuc 18*0a6a1f1dSLionel Sambuc #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 19*0a6a1f1dSLionel Sambuc 20*0a6a1f1dSLionel Sambuc template <class T> 21*0a6a1f1dSLionel Sambuc class A1 22*0a6a1f1dSLionel Sambuc { 23*0a6a1f1dSLionel Sambuc int id_; 24*0a6a1f1dSLionel Sambuc public: id_(id)25*0a6a1f1dSLionel Sambuc explicit A1(int id = 0) TEST_NOEXCEPT : id_(id) {} 26*0a6a1f1dSLionel Sambuc 27*0a6a1f1dSLionel Sambuc typedef T value_type; 28*0a6a1f1dSLionel Sambuc id()29*0a6a1f1dSLionel Sambuc int id() const {return id_;} 30*0a6a1f1dSLionel Sambuc 31*0a6a1f1dSLionel Sambuc static bool copy_called; 32*0a6a1f1dSLionel Sambuc static bool move_called; 33*0a6a1f1dSLionel Sambuc static bool allocate_called; 34*0a6a1f1dSLionel Sambuc static std::pair<T*, std::size_t> deallocate_called; 35*0a6a1f1dSLionel Sambuc A1(const A1 & a)36*0a6a1f1dSLionel Sambuc A1(const A1& a) TEST_NOEXCEPT : id_(a.id()) {copy_called = true;} A1(A1 && a)37*0a6a1f1dSLionel Sambuc A1(A1&& a) TEST_NOEXCEPT : id_(a.id()) {move_called = true;} 38*0a6a1f1dSLionel Sambuc 39*0a6a1f1dSLionel Sambuc template <class U> A1(const A1<U> & a)40*0a6a1f1dSLionel Sambuc A1(const A1<U>& a) TEST_NOEXCEPT : id_(a.id()) {copy_called = true;} 41*0a6a1f1dSLionel Sambuc template <class U> A1(A1<U> && a)42*0a6a1f1dSLionel Sambuc A1(A1<U>&& a) TEST_NOEXCEPT : id_(a.id()) {move_called = true;} 43*0a6a1f1dSLionel Sambuc allocate(std::size_t n)44*0a6a1f1dSLionel Sambuc T* allocate(std::size_t n) 45*0a6a1f1dSLionel Sambuc { 46*0a6a1f1dSLionel Sambuc allocate_called = true; 47*0a6a1f1dSLionel Sambuc return (T*)n; 48*0a6a1f1dSLionel Sambuc } 49*0a6a1f1dSLionel Sambuc deallocate(T * p,std::size_t n)50*0a6a1f1dSLionel Sambuc void deallocate(T* p, std::size_t n) 51*0a6a1f1dSLionel Sambuc { 52*0a6a1f1dSLionel Sambuc deallocate_called = std::pair<T*, std::size_t>(p, n); 53*0a6a1f1dSLionel Sambuc } 54*0a6a1f1dSLionel Sambuc max_size()55*0a6a1f1dSLionel Sambuc std::size_t max_size() const {return id_;} 56*0a6a1f1dSLionel Sambuc }; 57*0a6a1f1dSLionel Sambuc 58*0a6a1f1dSLionel Sambuc template <class T> bool A1<T>::copy_called = false; 59*0a6a1f1dSLionel Sambuc template <class T> bool A1<T>::move_called = false; 60*0a6a1f1dSLionel Sambuc template <class T> bool A1<T>::allocate_called = false; 61*0a6a1f1dSLionel Sambuc template <class T> std::pair<T*, std::size_t> A1<T>::deallocate_called; 62*0a6a1f1dSLionel Sambuc 63*0a6a1f1dSLionel Sambuc template <class T, class U> 64*0a6a1f1dSLionel Sambuc inline 65*0a6a1f1dSLionel Sambuc bool operator==(const A1<T>& x, const A1<U>& y) 66*0a6a1f1dSLionel Sambuc { 67*0a6a1f1dSLionel Sambuc return x.id() == y.id(); 68*0a6a1f1dSLionel Sambuc } 69*0a6a1f1dSLionel Sambuc 70*0a6a1f1dSLionel Sambuc template <class T, class U> 71*0a6a1f1dSLionel Sambuc inline 72*0a6a1f1dSLionel Sambuc bool operator!=(const A1<T>& x, const A1<U>& y) 73*0a6a1f1dSLionel Sambuc { 74*0a6a1f1dSLionel Sambuc return !(x == y); 75*0a6a1f1dSLionel Sambuc } 76*0a6a1f1dSLionel Sambuc 77*0a6a1f1dSLionel Sambuc template <class T> 78*0a6a1f1dSLionel Sambuc class A2 79*0a6a1f1dSLionel Sambuc { 80*0a6a1f1dSLionel Sambuc int id_; 81*0a6a1f1dSLionel Sambuc public: id_(id)82*0a6a1f1dSLionel Sambuc explicit A2(int id = 0) TEST_NOEXCEPT : id_(id) {} 83*0a6a1f1dSLionel Sambuc 84*0a6a1f1dSLionel Sambuc typedef T value_type; 85*0a6a1f1dSLionel Sambuc 86*0a6a1f1dSLionel Sambuc typedef unsigned size_type; 87*0a6a1f1dSLionel Sambuc typedef int difference_type; 88*0a6a1f1dSLionel Sambuc 89*0a6a1f1dSLionel Sambuc typedef std::true_type propagate_on_container_move_assignment; 90*0a6a1f1dSLionel Sambuc id()91*0a6a1f1dSLionel Sambuc int id() const {return id_;} 92*0a6a1f1dSLionel Sambuc 93*0a6a1f1dSLionel Sambuc static bool copy_called; 94*0a6a1f1dSLionel Sambuc static bool move_called; 95*0a6a1f1dSLionel Sambuc static bool allocate_called; 96*0a6a1f1dSLionel Sambuc A2(const A2 & a)97*0a6a1f1dSLionel Sambuc A2(const A2& a) TEST_NOEXCEPT : id_(a.id()) {copy_called = true;} A2(A2 && a)98*0a6a1f1dSLionel Sambuc A2(A2&& a) TEST_NOEXCEPT : id_(a.id()) {move_called = true;} 99*0a6a1f1dSLionel Sambuc allocate(std::size_t n,const void * hint)100*0a6a1f1dSLionel Sambuc T* allocate(std::size_t n, const void* hint) 101*0a6a1f1dSLionel Sambuc { 102*0a6a1f1dSLionel Sambuc allocate_called = true; 103*0a6a1f1dSLionel Sambuc return (T*)hint; 104*0a6a1f1dSLionel Sambuc } 105*0a6a1f1dSLionel Sambuc }; 106*0a6a1f1dSLionel Sambuc 107*0a6a1f1dSLionel Sambuc template <class T> bool A2<T>::copy_called = false; 108*0a6a1f1dSLionel Sambuc template <class T> bool A2<T>::move_called = false; 109*0a6a1f1dSLionel Sambuc template <class T> bool A2<T>::allocate_called = false; 110*0a6a1f1dSLionel Sambuc 111*0a6a1f1dSLionel Sambuc template <class T, class U> 112*0a6a1f1dSLionel Sambuc inline 113*0a6a1f1dSLionel Sambuc bool operator==(const A2<T>& x, const A2<U>& y) 114*0a6a1f1dSLionel Sambuc { 115*0a6a1f1dSLionel Sambuc return x.id() == y.id(); 116*0a6a1f1dSLionel Sambuc } 117*0a6a1f1dSLionel Sambuc 118*0a6a1f1dSLionel Sambuc template <class T, class U> 119*0a6a1f1dSLionel Sambuc inline 120*0a6a1f1dSLionel Sambuc bool operator!=(const A2<T>& x, const A2<U>& y) 121*0a6a1f1dSLionel Sambuc { 122*0a6a1f1dSLionel Sambuc return !(x == y); 123*0a6a1f1dSLionel Sambuc } 124*0a6a1f1dSLionel Sambuc 125*0a6a1f1dSLionel Sambuc template <class T> 126*0a6a1f1dSLionel Sambuc class A3 127*0a6a1f1dSLionel Sambuc { 128*0a6a1f1dSLionel Sambuc int id_; 129*0a6a1f1dSLionel Sambuc public: id_(id)130*0a6a1f1dSLionel Sambuc explicit A3(int id = 0) TEST_NOEXCEPT : id_(id) {} 131*0a6a1f1dSLionel Sambuc 132*0a6a1f1dSLionel Sambuc typedef T value_type; 133*0a6a1f1dSLionel Sambuc 134*0a6a1f1dSLionel Sambuc typedef std::true_type propagate_on_container_copy_assignment; 135*0a6a1f1dSLionel Sambuc typedef std::true_type propagate_on_container_swap; 136*0a6a1f1dSLionel Sambuc id()137*0a6a1f1dSLionel Sambuc int id() const {return id_;} 138*0a6a1f1dSLionel Sambuc 139*0a6a1f1dSLionel Sambuc static bool copy_called; 140*0a6a1f1dSLionel Sambuc static bool move_called; 141*0a6a1f1dSLionel Sambuc static bool constructed; 142*0a6a1f1dSLionel Sambuc static bool destroy_called; 143*0a6a1f1dSLionel Sambuc A3(const A3 & a)144*0a6a1f1dSLionel Sambuc A3(const A3& a) TEST_NOEXCEPT : id_(a.id()) {copy_called = true;} A3(A3 && a)145*0a6a1f1dSLionel Sambuc A3(A3&& a) TEST_NOEXCEPT: id_(a.id()) {move_called = true;} 146*0a6a1f1dSLionel Sambuc 147*0a6a1f1dSLionel Sambuc template <class U, class ...Args> construct(U * p,Args &&...args)148*0a6a1f1dSLionel Sambuc void construct(U* p, Args&& ...args) 149*0a6a1f1dSLionel Sambuc { 150*0a6a1f1dSLionel Sambuc ::new (p) U(std::forward<Args>(args)...); 151*0a6a1f1dSLionel Sambuc constructed = true; 152*0a6a1f1dSLionel Sambuc } 153*0a6a1f1dSLionel Sambuc 154*0a6a1f1dSLionel Sambuc template <class U> destroy(U * p)155*0a6a1f1dSLionel Sambuc void destroy(U* p) 156*0a6a1f1dSLionel Sambuc { 157*0a6a1f1dSLionel Sambuc p->~U(); 158*0a6a1f1dSLionel Sambuc destroy_called = true; 159*0a6a1f1dSLionel Sambuc } 160*0a6a1f1dSLionel Sambuc select_on_container_copy_construction()161*0a6a1f1dSLionel Sambuc A3 select_on_container_copy_construction() const {return A3(-1);} 162*0a6a1f1dSLionel Sambuc }; 163*0a6a1f1dSLionel Sambuc 164*0a6a1f1dSLionel Sambuc template <class T> bool A3<T>::copy_called = false; 165*0a6a1f1dSLionel Sambuc template <class T> bool A3<T>::move_called = false; 166*0a6a1f1dSLionel Sambuc template <class T> bool A3<T>::constructed = false; 167*0a6a1f1dSLionel Sambuc template <class T> bool A3<T>::destroy_called = false; 168*0a6a1f1dSLionel Sambuc 169*0a6a1f1dSLionel Sambuc template <class T, class U> 170*0a6a1f1dSLionel Sambuc inline 171*0a6a1f1dSLionel Sambuc bool operator==(const A3<T>& x, const A3<U>& y) 172*0a6a1f1dSLionel Sambuc { 173*0a6a1f1dSLionel Sambuc return x.id() == y.id(); 174*0a6a1f1dSLionel Sambuc } 175*0a6a1f1dSLionel Sambuc 176*0a6a1f1dSLionel Sambuc template <class T, class U> 177*0a6a1f1dSLionel Sambuc inline 178*0a6a1f1dSLionel Sambuc bool operator!=(const A3<T>& x, const A3<U>& y) 179*0a6a1f1dSLionel Sambuc { 180*0a6a1f1dSLionel Sambuc return !(x == y); 181*0a6a1f1dSLionel Sambuc } 182*0a6a1f1dSLionel Sambuc 183*0a6a1f1dSLionel Sambuc #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 184*0a6a1f1dSLionel Sambuc 185*0a6a1f1dSLionel Sambuc #endif // ALLOCATORS_H 186