Marshall Clow | 3ebf26f | 2014-03-11 04:32:12 +0000 | [diff] [blame] | 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> |
Marshall Clow | 6b913d7 | 2015-01-09 20:25:52 +0000 | [diff] [blame] | 11 | #include <memory> |
Marshall Clow | 3ebf26f | 2014-03-11 04:32:12 +0000 | [diff] [blame] | 12 | #include <cassert> |
| 13 | |
| 14 | #if __cplusplus >= 201103L |
| 15 | // #include <memory> |
| 16 | // |
| 17 | // template <class Alloc> |
| 18 | // struct allocator_traits |
| 19 | // { |
| 20 | // typedef Alloc allocator_type; |
| 21 | // typedef typename allocator_type::value_type |
| 22 | // value_type; |
| 23 | // |
| 24 | // typedef Alloc::pointer | value_type* pointer; |
| 25 | // typedef Alloc::const_pointer |
| 26 | // | pointer_traits<pointer>::rebind<const value_type> |
| 27 | // const_pointer; |
| 28 | // typedef Alloc::void_pointer |
| 29 | // | pointer_traits<pointer>::rebind<void> |
| 30 | // void_pointer; |
| 31 | // typedef Alloc::const_void_pointer |
| 32 | // | pointer_traits<pointer>::rebind<const void> |
| 33 | // const_void_pointer; |
| 34 | |
| 35 | template <typename Alloc> |
| 36 | void test_pointer() |
| 37 | { |
| 38 | typename std::allocator_traits<Alloc>::pointer vp; |
| 39 | typename std::allocator_traits<Alloc>::const_pointer cvp; |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 40 | |
Marshall Clow | 3ebf26f | 2014-03-11 04:32:12 +0000 | [diff] [blame] | 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 | static_assert(std::is_same<bool, decltype( vp <= vp)>::value, ""); |
| 47 | |
| 48 | static_assert(std::is_same<bool, decltype( vp == cvp)>::value, ""); |
| 49 | static_assert(std::is_same<bool, decltype(cvp == vp)>::value, ""); |
| 50 | static_assert(std::is_same<bool, decltype( vp != cvp)>::value, ""); |
| 51 | static_assert(std::is_same<bool, decltype(cvp != vp)>::value, ""); |
| 52 | static_assert(std::is_same<bool, decltype( vp > cvp)>::value, ""); |
| 53 | static_assert(std::is_same<bool, decltype(cvp > vp)>::value, ""); |
| 54 | static_assert(std::is_same<bool, decltype( vp >= cvp)>::value, ""); |
| 55 | static_assert(std::is_same<bool, decltype(cvp >= vp)>::value, ""); |
| 56 | static_assert(std::is_same<bool, decltype( vp < cvp)>::value, ""); |
| 57 | static_assert(std::is_same<bool, decltype(cvp < vp)>::value, ""); |
| 58 | static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, ""); |
| 59 | static_assert(std::is_same<bool, decltype(cvp <= vp)>::value, ""); |
| 60 | |
| 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 | static_assert(std::is_same<bool, decltype(cvp <= cvp)>::value, ""); |
| 67 | } |
| 68 | |
| 69 | template <typename Alloc> |
| 70 | void test_void_pointer() |
| 71 | { |
| 72 | typename std::allocator_traits<Alloc>::void_pointer vp; |
| 73 | typename std::allocator_traits<Alloc>::const_void_pointer cvp; |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 74 | |
Marshall Clow | 3ebf26f | 2014-03-11 04:32:12 +0000 | [diff] [blame] | 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 | static_assert(std::is_same<bool, decltype( vp <= vp)>::value, ""); |
| 81 | |
| 82 | static_assert(std::is_same<bool, decltype( vp == cvp)>::value, ""); |
| 83 | static_assert(std::is_same<bool, decltype(cvp == vp)>::value, ""); |
| 84 | static_assert(std::is_same<bool, decltype( vp != cvp)>::value, ""); |
| 85 | static_assert(std::is_same<bool, decltype(cvp != vp)>::value, ""); |
| 86 | static_assert(std::is_same<bool, decltype( vp > cvp)>::value, ""); |
| 87 | static_assert(std::is_same<bool, decltype(cvp > vp)>::value, ""); |
| 88 | static_assert(std::is_same<bool, decltype( vp >= cvp)>::value, ""); |
| 89 | static_assert(std::is_same<bool, decltype(cvp >= vp)>::value, ""); |
| 90 | static_assert(std::is_same<bool, decltype( vp < cvp)>::value, ""); |
| 91 | static_assert(std::is_same<bool, decltype(cvp < vp)>::value, ""); |
| 92 | static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, ""); |
| 93 | static_assert(std::is_same<bool, decltype(cvp <= vp)>::value, ""); |
| 94 | |
| 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 | static_assert(std::is_same<bool, decltype(cvp <= cvp)>::value, ""); |
| 101 | } |
| 102 | |
| 103 | struct Foo { int x; }; |
| 104 | |
| 105 | int main() |
| 106 | { |
Marshall Clow | 38d9005 | 2014-10-18 11:03:33 +0000 | [diff] [blame] | 107 | test_pointer<std::scoped_allocator_adaptor<std::allocator<char>>> (); |
| 108 | test_pointer<std::scoped_allocator_adaptor<std::allocator<int>>> (); |
| 109 | test_pointer<std::scoped_allocator_adaptor<std::allocator<Foo>>> (); |
Marshall Clow | 3ebf26f | 2014-03-11 04:32:12 +0000 | [diff] [blame] | 110 | |
Marshall Clow | 38d9005 | 2014-10-18 11:03:33 +0000 | [diff] [blame] | 111 | test_void_pointer<std::scoped_allocator_adaptor<std::allocator<char>>> (); |
| 112 | test_void_pointer<std::scoped_allocator_adaptor<std::allocator<int>>> (); |
| 113 | test_void_pointer<std::scoped_allocator_adaptor<std::allocator<Foo>>> (); |
Marshall Clow | 3ebf26f | 2014-03-11 04:32:12 +0000 | [diff] [blame] | 114 | } |
| 115 | #else |
| 116 | int main() {} |
| 117 | #endif |