@@ -27,45 +27,45 @@ TEST_CONSTEXPR_CXX20 inline typename std::allocator_traits<Alloc>::size_type all
27
27
}
28
28
29
29
struct test_allocator_statistics {
30
- int time_to_throw = 0 ;
31
- int throw_after = INT_MAX;
30
+ int time_to_throw = 0 ;
31
+ int throw_after = INT_MAX;
32
32
int count = 0 ; // the number of active instances
33
33
int alloc_count = 0 ; // the number of allocations not deallocating
34
34
int allocated_size = 0 ; // the size of allocated elements
35
35
int construct_count = 0 ; // the number of times that ::construct was called
36
- int destroy_count = 0 ; // the number of times that ::destroy was called
37
- int copied = 0 ;
38
- int moved = 0 ;
39
- int converted = 0 ;
36
+ int destroy_count = 0 ; // the number of times that ::destroy was called
37
+ int copied = 0 ;
38
+ int moved = 0 ;
39
+ int converted = 0 ;
40
40
41
41
TEST_CONSTEXPR_CXX14 void clear () {
42
42
assert (count == 0 && " clearing leaking allocator data?" );
43
- count = 0 ;
44
- time_to_throw = 0 ;
45
- alloc_count = 0 ;
43
+ count = 0 ;
44
+ time_to_throw = 0 ;
45
+ alloc_count = 0 ;
46
46
allocated_size = 0 ;
47
47
construct_count = 0 ;
48
- destroy_count = 0 ;
49
- throw_after = INT_MAX;
48
+ destroy_count = 0 ;
49
+ throw_after = INT_MAX;
50
50
clear_ctor_counters ();
51
51
}
52
52
53
53
TEST_CONSTEXPR_CXX14 void clear_ctor_counters () {
54
- copied = 0 ;
55
- moved = 0 ;
54
+ copied = 0 ;
55
+ moved = 0 ;
56
56
converted = 0 ;
57
57
}
58
58
};
59
59
60
60
struct test_alloc_base {
61
61
TEST_CONSTEXPR static const int destructed_value = -1 ;
62
- TEST_CONSTEXPR static const int moved_value = INT_MAX;
62
+ TEST_CONSTEXPR static const int moved_value = INT_MAX;
63
63
};
64
64
65
65
template <class T >
66
66
class test_allocator {
67
- int data_ = 0 ; // participates in equality
68
- int id_ = 0 ; // unique identifier, doesn't participate in equality
67
+ int data_ = 0 ; // participates in equality
68
+ int id_ = 0 ; // unique identifier, doesn't participate in equality
69
69
test_allocator_statistics* stats_ = nullptr ;
70
70
71
71
template <class U >
@@ -95,21 +95,26 @@ class test_allocator {
95
95
TEST_CONSTEXPR explicit test_allocator (int data) TEST_NOEXCEPT : data_(data) {}
96
96
97
97
TEST_CONSTEXPR_CXX14 explicit test_allocator (int data, test_allocator_statistics* stats) TEST_NOEXCEPT
98
- : data_(data), stats_(stats) {
98
+ : data_(data),
99
+ stats_(stats) {
99
100
if (stats != nullptr )
100
101
++stats_->count ;
101
102
}
102
103
103
104
TEST_CONSTEXPR explicit test_allocator (int data, int id) TEST_NOEXCEPT : data_(data), id_(id) {}
104
105
105
106
TEST_CONSTEXPR_CXX14 explicit test_allocator (int data, int id, test_allocator_statistics* stats) TEST_NOEXCEPT
106
- : data_(data), id_(id), stats_(stats) {
107
+ : data_(data),
108
+ id_(id),
109
+ stats_(stats) {
107
110
if (stats_ != nullptr )
108
111
++stats_->count ;
109
112
}
110
113
111
114
TEST_CONSTEXPR_CXX14 test_allocator (const test_allocator& a) TEST_NOEXCEPT
112
- : data_(a.data_), id_(a.id_), stats_(a.stats_) {
115
+ : data_(a.data_),
116
+ id_(a.id_),
117
+ stats_(a.stats_) {
113
118
assert (a.data_ != test_alloc_base::destructed_value && a.id_ != test_alloc_base::destructed_value &&
114
119
" copying from destroyed allocator" );
115
120
if (stats_ != nullptr ) {
@@ -130,7 +135,9 @@ class test_allocator {
130
135
131
136
template <class U >
132
137
TEST_CONSTEXPR_CXX14 test_allocator (const test_allocator<U>& a) TEST_NOEXCEPT
133
- : data_(a.data_), id_(a.id_), stats_(a.stats_) {
138
+ : data_(a.data_),
139
+ id_(a.id_),
140
+ stats_(a.stats_) {
134
141
if (stats_ != nullptr ) {
135
142
++stats_->count ;
136
143
++stats_->converted ;
@@ -143,7 +150,7 @@ class test_allocator {
143
150
if (stats_ != nullptr )
144
151
--stats_->count ;
145
152
data_ = test_alloc_base::destructed_value;
146
- id_ = test_alloc_base::destructed_value;
153
+ id_ = test_alloc_base::destructed_value;
147
154
}
148
155
149
156
TEST_CONSTEXPR pointer address (reference x) const { return &x; }
@@ -197,8 +204,8 @@ class test_allocator {
197
204
198
205
template <>
199
206
class test_allocator <void > {
200
- int data_ = 0 ;
201
- int id_ = 0 ;
207
+ int data_ = 0 ;
208
+ int id_ = 0 ;
202
209
test_allocator_statistics* stats_ = nullptr ;
203
210
204
211
template <class U >
@@ -223,27 +230,30 @@ class test_allocator<void> {
223
230
TEST_CONSTEXPR explicit test_allocator (int data) TEST_NOEXCEPT : data_(data) {}
224
231
225
232
TEST_CONSTEXPR explicit test_allocator (int data, test_allocator_statistics* stats) TEST_NOEXCEPT
226
- : data_(data), stats_(stats)
227
- {}
233
+ : data_(data),
234
+ stats_(stats) {}
228
235
229
236
TEST_CONSTEXPR explicit test_allocator (int data, int id) : data_(data), id_(id) {}
230
237
231
238
TEST_CONSTEXPR_CXX14 explicit test_allocator (int data, int id, test_allocator_statistics* stats) TEST_NOEXCEPT
232
- : data_(data), id_(id), stats_(stats)
233
- {}
239
+ : data_(data),
240
+ id_(id),
241
+ stats_(stats) {}
234
242
235
243
TEST_CONSTEXPR_CXX14 explicit test_allocator (const test_allocator& a) TEST_NOEXCEPT
236
- : data_(a.data_), id_(a.id_), stats_(a.stats_)
237
- {}
244
+ : data_(a.data_),
245
+ id_(a.id_),
246
+ stats_(a.stats_) {}
238
247
239
248
template <class U >
240
249
TEST_CONSTEXPR_CXX14 test_allocator (const test_allocator<U>& a) TEST_NOEXCEPT
241
- : data_(a.data_), id_(a.id_), stats_(a.stats_)
242
- {}
250
+ : data_(a.data_),
251
+ id_(a.id_),
252
+ stats_(a.stats_) {}
243
253
244
254
TEST_CONSTEXPR_CXX20 ~test_allocator () TEST_NOEXCEPT {
245
255
data_ = test_alloc_base::destructed_value;
246
- id_ = test_alloc_base::destructed_value;
256
+ id_ = test_alloc_base::destructed_value;
247
257
}
248
258
249
259
TEST_CONSTEXPR int get_id () const { return id_; }
@@ -310,9 +320,9 @@ struct Tag_X {
310
320
TEST_CONSTEXPR Tag_X (Ctor_Tag, Args&&...) {}
311
321
312
322
// not DefaultConstructible, CopyConstructible or MoveConstructible.
313
- Tag_X () = delete ;
323
+ Tag_X () = delete ;
314
324
Tag_X (const Tag_X&) = delete ;
315
- Tag_X (Tag_X&&) = delete ;
325
+ Tag_X (Tag_X&&) = delete ;
316
326
317
327
// CopyAssignable.
318
328
TEST_CONSTEXPR_CXX14 Tag_X& operator =(const Tag_X&) { return *this ; };
@@ -329,7 +339,7 @@ struct Tag_X {
329
339
template <typename T>
330
340
class TaggingAllocator {
331
341
public:
332
- using value_type = T;
342
+ using value_type = T;
333
343
TaggingAllocator () = default ;
334
344
335
345
template <typename U>
@@ -356,13 +366,13 @@ class TaggingAllocator {
356
366
template <std::size_t MaxAllocs>
357
367
struct limited_alloc_handle {
358
368
std::size_t outstanding_ = 0 ;
359
- void * last_alloc_ = nullptr ;
369
+ void * last_alloc_ = nullptr ;
360
370
361
371
template <class T >
362
372
TEST_CONSTEXPR_CXX20 T* allocate (std::size_t N) {
363
373
if (N + outstanding_ > MaxAllocs)
364
374
TEST_THROW (std::bad_alloc ());
365
- auto alloc = std::allocator<T>().allocate (N);
375
+ auto alloc = std::allocator<T>().allocate (N);
366
376
last_alloc_ = alloc;
367
377
outstanding_ += N;
368
378
return alloc;
@@ -467,9 +477,6 @@ class limited_allocator {
467
477
TEST_CONSTEXPR_CXX20 pointer allocate (size_type n) { return handle_->template allocate <T>(n); }
468
478
TEST_CONSTEXPR_CXX20 void deallocate (pointer p, size_type n) { handle_->template deallocate <T>(p, n); }
469
479
TEST_CONSTEXPR size_type max_size () const { return N; }
470
-
471
- // In C++11, constexpr non-static member functions are implicitly const, but this is no longer the case since C++14.
472
- TEST_CONSTEXPR_CXX14 BuffT* getHandle () { return handle_.get (); }
473
480
TEST_CONSTEXPR const BuffT* getHandle () const { return handle_.get (); }
474
481
};
475
482
0 commit comments