1
+ // src/Beman/Execution26/tests/allocator-requirements-general.pass.cpp -*-C++-*-
2
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3
+
4
+ #include < Beman/Execution26/detail/simple-allocator.hpp>
5
+ #include < test/execution.hpp>
6
+
7
+ // ----------------------------------------------------------------------------
8
+
9
+ namespace
10
+ {
11
+ enum class size_type {};
12
+
13
+ struct non_allocator {};
14
+ struct no_allocate
15
+ {
16
+ using value_type = int ;
17
+ auto deallocate (int *, ::std::size_t ) -> void {}
18
+
19
+ auto operator == (no_allocate const &) const -> bool = default ;
20
+ };
21
+ struct no_deallocate
22
+ {
23
+ using value_type = int ;
24
+ auto allocate (::std::size_t n) -> int* { return new int [n]; }
25
+
26
+ auto operator == (no_deallocate const &) const -> bool = default ;
27
+ };
28
+
29
+ struct no_value_type
30
+ {
31
+ auto allocate (::std::size_t n) -> int* { return new int [n]; }
32
+ auto deallocate (int *, ::std::size_t ) -> void {}
33
+
34
+ auto operator == (no_value_type const &) const -> bool = default ;
35
+ };
36
+
37
+ struct allocate_return_type_mismatch
38
+ {
39
+ using value_type = long ;
40
+ auto allocate (::std::size_t n) -> int* { return new int [n]; }
41
+ auto deallocate (int *, ::std::size_t ) -> void {}
42
+
43
+ auto operator == (allocate_return_type_mismatch const &) const -> bool = default ;
44
+ };
45
+
46
+ struct allocate_size_type_mismatch
47
+ {
48
+ using value_type = int ; // -dk:TODO long;
49
+ auto allocate (size_type n) -> int* { return new int [::std::size_t (n)]; }
50
+ auto deallocate (int *, ::std::size_t ) -> void {}
51
+
52
+ auto operator == (allocate_size_type_mismatch const &) const -> bool = default ;
53
+ };
54
+
55
+ struct deallocate_object_type_mismatch
56
+ {
57
+ using value_type = int ;
58
+ auto allocate (::std::size_t n) -> int* { return new int [n]; }
59
+ auto deallocate (long *, ::std::size_t ) -> void {}
60
+
61
+ auto operator == (deallocate_object_type_mismatch const &) const -> bool = default ;
62
+ };
63
+
64
+ struct deallocate_size_type_mismatch
65
+ {
66
+ using value_type = int ;
67
+ auto allocate (::std::size_t n) -> int* { return new int [n]; }
68
+ auto deallocate (int *, size_type) -> void {}
69
+
70
+ auto operator == (deallocate_size_type_mismatch const &) const -> bool = default ;
71
+ };
72
+
73
+ struct not_copy_constructible
74
+ {
75
+ using value_type = int ;
76
+
77
+ not_copy_constructible (not_copy_constructible const &) = delete ;
78
+ auto allocate (::std::size_t n) -> int* { return new int [n]; }
79
+ auto deallocate (/* long*/ int *, ::std::size_t ) -> void {}
80
+
81
+ auto operator == (not_copy_constructible const &) const -> bool = default ;
82
+ };
83
+
84
+ struct not_equality_comparable
85
+ {
86
+ using value_type = int ;
87
+
88
+ auto allocate (::std::size_t n) -> int* { return new int [n]; }
89
+ auto deallocate (int *, ::std::size_t ) -> void {}
90
+
91
+ auto operator == (not_equality_comparable const &) const -> bool = delete ;
92
+ };
93
+
94
+ struct allocator
95
+ {
96
+ using value_type = int ;
97
+
98
+ auto allocate (::std::size_t n) -> int* { return new int [n]; }
99
+ auto deallocate (int * object, ::std::size_t ) -> void { delete[] object; }
100
+
101
+ auto operator == (allocator const &) const -> bool = default ;
102
+ };
103
+ }
104
+
105
+ auto main () -> int
106
+ {
107
+ static_assert (not test_detail::simple_allocator<non_allocator>);
108
+ static_assert (not test_detail::simple_allocator<no_allocate>);
109
+ static_assert (not test_detail::simple_allocator<no_deallocate>);
110
+ static_assert (not test_detail::simple_allocator<no_value_type>);
111
+ static_assert (not test_detail::simple_allocator<allocate_return_type_mismatch>);
112
+ static_assert (not test_detail::simple_allocator<allocate_size_type_mismatch>);
113
+ static_assert (not test_detail::simple_allocator<deallocate_object_type_mismatch>);
114
+ static_assert (not test_detail::simple_allocator<deallocate_size_type_mismatch>);
115
+ static_assert (not test_detail::simple_allocator<not_copy_constructible>);
116
+ static_assert (not test_detail::simple_allocator<not_equality_comparable>);
117
+
118
+ static_assert (test_detail::simple_allocator<allocator>);
119
+ }
0 commit comments