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
14 #include "test_macros.h"
15
16 // <memory>
17 //
18 // template <class Alloc>
19 // struct allocator_traits
20 // {
21 // typedef Alloc allocator_type;
22 // typedef typename allocator_type::value_type
23 // value_type;
24 //
25 // typedef Alloc::pointer | value_type* pointer;
26 // typedef Alloc::const_pointer
27 // | pointer_traits<pointer>::rebind<const value_type>
28 // const_pointer;
29 // typedef Alloc::void_pointer
30 // | pointer_traits<pointer>::rebind<void>
31 // void_pointer;
32 // typedef Alloc::const_void_pointer
33 // | pointer_traits<pointer>::rebind<const void>
34 // const_void_pointer;
35
36 template <typename Alloc>
test_pointer()37 void test_pointer()
38 {
39 typename std::allocator_traits<Alloc>::pointer vp;
40 typename std::allocator_traits<Alloc>::const_pointer cvp;
41
42 ((void)vp); // Prevent unused warning
43 ((void)cvp); // Prevent unused warning
44
45 static_assert(std::is_same<bool, decltype( vp == vp)>::value, "");
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
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 static_assert(std::is_same<bool, decltype( vp < cvp)>::value, "");
61 static_assert(std::is_same<bool, decltype(cvp < vp)>::value, "");
62 static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, "");
63 static_assert(std::is_same<bool, decltype(cvp <= vp)>::value, "");
64
65 static_assert(std::is_same<bool, decltype(cvp == cvp)>::value, "");
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 }
72
73 template <typename Alloc>
test_void_pointer()74 void test_void_pointer()
75 {
76 typename std::allocator_traits<Alloc>::void_pointer vp;
77 typename std::allocator_traits<Alloc>::const_void_pointer cvp;
78
79 ((void)vp); // Prevent unused warning
80 ((void)cvp); // Prevent unused warning
81
82 static_assert(std::is_same<bool, decltype( vp == vp)>::value, "");
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
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 static_assert(std::is_same<bool, decltype( vp > cvp)>::value, "");
94 static_assert(std::is_same<bool, decltype(cvp > vp)>::value, "");
95 static_assert(std::is_same<bool, decltype( vp >= cvp)>::value, "");
96 static_assert(std::is_same<bool, decltype(cvp >= vp)>::value, "");
97 static_assert(std::is_same<bool, decltype( vp < cvp)>::value, "");
98 static_assert(std::is_same<bool, decltype(cvp < vp)>::value, "");
99 static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, "");
100 static_assert(std::is_same<bool, decltype(cvp <= vp)>::value, "");
101
102 static_assert(std::is_same<bool, decltype(cvp == cvp)>::value, "");
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 }
109
110 struct Foo { int x; };
111
main(int,char **)112 int main(int, char**)
113 {
114 test_pointer<std::allocator<char>> ();
115 test_pointer<std::allocator<int>> ();
116 test_pointer<std::allocator<Foo>> ();
117
118 test_void_pointer<std::allocator<char>> ();
119 test_void_pointer<std::allocator<int>> ();
120 test_void_pointer<std::allocator<Foo>> ();
121
122 return 0;
123 }
124