blob: 5a8f7a28a042c47962c836ec5c3053308be5e9cd [file] [log] [blame]
Marshall Clow3ebf26f2014-03-11 04:32:12 +00001//===----------------------------------------------------------------------===//
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 <memory>
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
34template <typename Alloc>
35void test_pointer()
36{
37 typename std::allocator_traits<Alloc>::pointer vp;
38 typename std::allocator_traits<Alloc>::const_pointer cvp;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070039
Marshall Clow3ebf26f2014-03-11 04:32:12 +000040 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
68template <typename Alloc>
69void test_void_pointer()
70{
71 typename std::allocator_traits<Alloc>::void_pointer vp;
72 typename std::allocator_traits<Alloc>::const_void_pointer cvp;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070073
Marshall Clow3ebf26f2014-03-11 04:32:12 +000074 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
102struct Foo { int x; };
103
104int main()
105{
Marshall Clow38d90052014-10-18 11:03:33 +0000106 test_pointer<std::allocator<char>> ();
107 test_pointer<std::allocator<int>> ();
108 test_pointer<std::allocator<Foo>> ();
Marshall Clow3ebf26f2014-03-11 04:32:12 +0000109
Marshall Clow38d90052014-10-18 11:03:33 +0000110 test_void_pointer<std::allocator<char>> ();
111 test_void_pointer<std::allocator<int>> ();
112 test_void_pointer<std::allocator<Foo>> ();
Marshall Clow3ebf26f2014-03-11 04:32:12 +0000113}
114#else
115int main() {}
116#endif