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 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: c++03 |
10 | |
11 | #include <memory> |
12 | #include <cassert> |
13 | #include <type_traits> |
14 | |
15 | #include "test_macros.h" |
16 | |
17 | // <memory> |
18 | // |
19 | // template <class Alloc> |
20 | // struct allocator_traits |
21 | // { |
22 | // typedef Alloc allocator_type; |
23 | // typedef typename allocator_type::value_type |
24 | // value_type; |
25 | // |
26 | // typedef Alloc::pointer | value_type* pointer; |
27 | // typedef Alloc::const_pointer |
28 | // | pointer_traits<pointer>::rebind<const value_type> |
29 | // const_pointer; |
30 | // typedef Alloc::void_pointer |
31 | // | pointer_traits<pointer>::rebind<void> |
32 | // void_pointer; |
33 | // typedef Alloc::const_void_pointer |
34 | // | pointer_traits<pointer>::rebind<const void> |
35 | // const_void_pointer; |
36 | |
37 | template <typename Alloc> |
38 | void test_pointer() |
39 | { |
40 | typename std::allocator_traits<Alloc>::pointer vp; |
41 | typename std::allocator_traits<Alloc>::const_pointer cvp; |
42 | |
43 | ((void)vp); // Prevent unused warning |
44 | ((void)cvp); // Prevent unused warning |
45 | |
46 | static_assert(std::is_same<bool, decltype( vp == vp)>::value, "" ); |
47 | static_assert(std::is_same<bool, decltype( vp != vp)>::value, "" ); |
48 | static_assert(std::is_same<bool, decltype( vp > vp)>::value, "" ); |
49 | static_assert(std::is_same<bool, decltype( vp >= vp)>::value, "" ); |
50 | static_assert(std::is_same<bool, decltype( vp < vp)>::value, "" ); |
51 | static_assert(std::is_same<bool, decltype( vp <= vp)>::value, "" ); |
52 | |
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 | static_assert(std::is_same<bool, decltype( vp >= cvp)>::value, "" ); |
60 | static_assert(std::is_same<bool, decltype(cvp >= vp)>::value, "" ); |
61 | static_assert(std::is_same<bool, decltype( vp < cvp)>::value, "" ); |
62 | static_assert(std::is_same<bool, decltype(cvp < vp)>::value, "" ); |
63 | static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, "" ); |
64 | static_assert(std::is_same<bool, decltype(cvp <= vp)>::value, "" ); |
65 | |
66 | static_assert(std::is_same<bool, decltype(cvp == cvp)>::value, "" ); |
67 | static_assert(std::is_same<bool, decltype(cvp != cvp)>::value, "" ); |
68 | static_assert(std::is_same<bool, decltype(cvp > cvp)>::value, "" ); |
69 | static_assert(std::is_same<bool, decltype(cvp >= cvp)>::value, "" ); |
70 | static_assert(std::is_same<bool, decltype(cvp < cvp)>::value, "" ); |
71 | static_assert(std::is_same<bool, decltype(cvp <= cvp)>::value, "" ); |
72 | } |
73 | |
74 | template <typename Alloc> |
75 | void test_void_pointer() |
76 | { |
77 | typename std::allocator_traits<Alloc>::void_pointer vp; |
78 | typename std::allocator_traits<Alloc>::const_void_pointer cvp; |
79 | |
80 | ((void)vp); // Prevent unused warning |
81 | ((void)cvp); // Prevent unused warning |
82 | |
83 | static_assert(std::is_same<bool, decltype( vp == vp)>::value, "" ); |
84 | static_assert(std::is_same<bool, decltype( vp != vp)>::value, "" ); |
85 | static_assert(std::is_same<bool, decltype( vp > vp)>::value, "" ); |
86 | static_assert(std::is_same<bool, decltype( vp >= vp)>::value, "" ); |
87 | static_assert(std::is_same<bool, decltype( vp < vp)>::value, "" ); |
88 | static_assert(std::is_same<bool, decltype( vp <= vp)>::value, "" ); |
89 | |
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 | static_assert(std::is_same<bool, decltype( vp > cvp)>::value, "" ); |
95 | static_assert(std::is_same<bool, decltype(cvp > vp)>::value, "" ); |
96 | static_assert(std::is_same<bool, decltype( vp >= cvp)>::value, "" ); |
97 | static_assert(std::is_same<bool, decltype(cvp >= vp)>::value, "" ); |
98 | static_assert(std::is_same<bool, decltype( vp < cvp)>::value, "" ); |
99 | static_assert(std::is_same<bool, decltype(cvp < vp)>::value, "" ); |
100 | static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, "" ); |
101 | static_assert(std::is_same<bool, decltype(cvp <= vp)>::value, "" ); |
102 | |
103 | static_assert(std::is_same<bool, decltype(cvp == cvp)>::value, "" ); |
104 | static_assert(std::is_same<bool, decltype(cvp != cvp)>::value, "" ); |
105 | static_assert(std::is_same<bool, decltype(cvp > cvp)>::value, "" ); |
106 | static_assert(std::is_same<bool, decltype(cvp >= cvp)>::value, "" ); |
107 | static_assert(std::is_same<bool, decltype(cvp < cvp)>::value, "" ); |
108 | static_assert(std::is_same<bool, decltype(cvp <= cvp)>::value, "" ); |
109 | } |
110 | |
111 | struct Foo { int x; }; |
112 | |
113 | int main(int, char**) |
114 | { |
115 | test_pointer<std::allocator<char>> (); |
116 | test_pointer<std::allocator<int>> (); |
117 | test_pointer<std::allocator<Foo>> (); |
118 | |
119 | test_void_pointer<std::allocator<char>> (); |
120 | test_void_pointer<std::allocator<int>> (); |
121 | test_void_pointer<std::allocator<Foo>> (); |
122 | |
123 | return 0; |
124 | } |
125 | |