1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include <scoped_allocator> 11 #include <cassert> 12 13 #if __cplusplus >= 201103L 14 // #include <memory> 15 // 16 // template <class Alloc> 17 // struct allocator_traits 18 // { 19 // typedef Alloc allocator_type; 20 // typedef typename allocator_type::value_type 21 // value_type; 22 // 23 // typedef Alloc::pointer | value_type* pointer; 24 // typedef Alloc::const_pointer 25 // | pointer_traits<pointer>::rebind<const value_type> 26 // const_pointer; 27 // typedef Alloc::void_pointer 28 // | pointer_traits<pointer>::rebind<void> 29 // void_pointer; 30 // typedef Alloc::const_void_pointer 31 // | pointer_traits<pointer>::rebind<const void> 32 // const_void_pointer; 33 34 template <typename Alloc> 35 void test_pointer() 36 { 37 typename std::allocator_traits<Alloc>::pointer vp; 38 typename std::allocator_traits<Alloc>::const_pointer cvp; 39 40 static_assert(std::is_same<bool, decltype( vp == vp)>::value, ""); 41 static_assert(std::is_same<bool, decltype( vp != vp)>::value, ""); 42 static_assert(std::is_same<bool, decltype( vp > vp)>::value, ""); 43 static_assert(std::is_same<bool, decltype( vp >= vp)>::value, ""); 44 static_assert(std::is_same<bool, decltype( vp < vp)>::value, ""); 45 static_assert(std::is_same<bool, decltype( vp <= vp)>::value, ""); 46 47 static_assert(std::is_same<bool, decltype( vp == cvp)>::value, ""); 48 static_assert(std::is_same<bool, decltype(cvp == vp)>::value, ""); 49 static_assert(std::is_same<bool, decltype( vp != cvp)>::value, ""); 50 static_assert(std::is_same<bool, decltype(cvp != vp)>::value, ""); 51 static_assert(std::is_same<bool, decltype( vp > cvp)>::value, ""); 52 static_assert(std::is_same<bool, decltype(cvp > vp)>::value, ""); 53 static_assert(std::is_same<bool, decltype( vp >= cvp)>::value, ""); 54 static_assert(std::is_same<bool, decltype(cvp >= vp)>::value, ""); 55 static_assert(std::is_same<bool, decltype( vp < cvp)>::value, ""); 56 static_assert(std::is_same<bool, decltype(cvp < vp)>::value, ""); 57 static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, ""); 58 static_assert(std::is_same<bool, decltype(cvp <= vp)>::value, ""); 59 60 static_assert(std::is_same<bool, decltype(cvp == cvp)>::value, ""); 61 static_assert(std::is_same<bool, decltype(cvp != cvp)>::value, ""); 62 static_assert(std::is_same<bool, decltype(cvp > cvp)>::value, ""); 63 static_assert(std::is_same<bool, decltype(cvp >= cvp)>::value, ""); 64 static_assert(std::is_same<bool, decltype(cvp < cvp)>::value, ""); 65 static_assert(std::is_same<bool, decltype(cvp <= cvp)>::value, ""); 66 } 67 68 template <typename Alloc> 69 void test_void_pointer() 70 { 71 typename std::allocator_traits<Alloc>::void_pointer vp; 72 typename std::allocator_traits<Alloc>::const_void_pointer cvp; 73 74 static_assert(std::is_same<bool, decltype( vp == vp)>::value, ""); 75 static_assert(std::is_same<bool, decltype( vp != vp)>::value, ""); 76 static_assert(std::is_same<bool, decltype( vp > vp)>::value, ""); 77 static_assert(std::is_same<bool, decltype( vp >= vp)>::value, ""); 78 static_assert(std::is_same<bool, decltype( vp < vp)>::value, ""); 79 static_assert(std::is_same<bool, decltype( vp <= vp)>::value, ""); 80 81 static_assert(std::is_same<bool, decltype( vp == cvp)>::value, ""); 82 static_assert(std::is_same<bool, decltype(cvp == vp)>::value, ""); 83 static_assert(std::is_same<bool, decltype( vp != cvp)>::value, ""); 84 static_assert(std::is_same<bool, decltype(cvp != vp)>::value, ""); 85 static_assert(std::is_same<bool, decltype( vp > cvp)>::value, ""); 86 static_assert(std::is_same<bool, decltype(cvp > vp)>::value, ""); 87 static_assert(std::is_same<bool, decltype( vp >= cvp)>::value, ""); 88 static_assert(std::is_same<bool, decltype(cvp >= vp)>::value, ""); 89 static_assert(std::is_same<bool, decltype( vp < cvp)>::value, ""); 90 static_assert(std::is_same<bool, decltype(cvp < vp)>::value, ""); 91 static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, ""); 92 static_assert(std::is_same<bool, decltype(cvp <= vp)>::value, ""); 93 94 static_assert(std::is_same<bool, decltype(cvp == cvp)>::value, ""); 95 static_assert(std::is_same<bool, decltype(cvp != cvp)>::value, ""); 96 static_assert(std::is_same<bool, decltype(cvp > cvp)>::value, ""); 97 static_assert(std::is_same<bool, decltype(cvp >= cvp)>::value, ""); 98 static_assert(std::is_same<bool, decltype(cvp < cvp)>::value, ""); 99 static_assert(std::is_same<bool, decltype(cvp <= cvp)>::value, ""); 100 } 101 102 struct Foo { int x; }; 103 104 int main() 105 { 106 test_pointer<std::scoped_allocator_adaptor<std::allocator<char>>> (); 107 test_pointer<std::scoped_allocator_adaptor<std::allocator<int>>> (); 108 test_pointer<std::scoped_allocator_adaptor<std::allocator<Foo>>> (); 109 110 test_void_pointer<std::scoped_allocator_adaptor<std::allocator<char>>> (); 111 test_void_pointer<std::scoped_allocator_adaptor<std::allocator<int>>> (); 112 test_void_pointer<std::scoped_allocator_adaptor<std::allocator<Foo>>> (); 113 } 114 #else 115 int main() {} 116 #endif 117