blob: e165d9836db00fcabe8623b9e85e19c14c6a4146 [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 <scoped_allocator>
Marshall Clow6b913d72015-01-09 20:25:52 +000011#include <memory>
Marshall Clow3ebf26f2014-03-11 04:32:12 +000012#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
35template <typename Alloc>
36void test_pointer()
37{
38 typename std::allocator_traits<Alloc>::pointer vp;
39 typename std::allocator_traits<Alloc>::const_pointer cvp;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070040
Marshall Clow3ebf26f2014-03-11 04:32:12 +000041 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
69template <typename Alloc>
70void test_void_pointer()
71{
72 typename std::allocator_traits<Alloc>::void_pointer vp;
73 typename std::allocator_traits<Alloc>::const_void_pointer cvp;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070074
Marshall Clow3ebf26f2014-03-11 04:32:12 +000075 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
103struct Foo { int x; };
104
105int main()
106{
Marshall Clow38d90052014-10-18 11:03:33 +0000107 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 Clow3ebf26f2014-03-11 04:32:12 +0000110
Marshall Clow38d90052014-10-18 11:03:33 +0000111 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 Clow3ebf26f2014-03-11 04:32:12 +0000114}
115#else
116int main() {}
117#endif