@@ -40,23 +40,23 @@ TEST_CONSTEXPR_CXX20 bool tests()
40
40
}
41
41
42
42
#if TEST_STD_VER >= 23
43
- std::size_t min_bytes = 1000 ;
44
-
45
43
template <typename T>
46
44
struct increasing_allocator {
47
- using value_type = T;
48
- increasing_allocator () = default ;
45
+ using value_type = T;
46
+ std::size_t min_elements = 1000 ;
47
+ increasing_allocator () = default ;
48
+
49
49
template <typename U>
50
- increasing_allocator (const increasing_allocator<U>&) noexcept {}
51
- std::allocation_result<T*> allocate_at_least (std:: size_t n) {
52
- std::size_t allocation_amount = n * sizeof (T);
53
- if (allocation_amount < min_bytes )
54
- allocation_amount = min_bytes ;
55
- min_bytes += 1000 ;
56
- return { static_cast <T*>(:: operator new (allocation_amount)), allocation_amount / sizeof (T)} ;
50
+ constexpr increasing_allocator (const increasing_allocator<U>& other ) noexcept : min_elements(other.min_elements) {}
51
+
52
+ constexpr std::allocation_result<T*> allocate_at_least ( std::size_t n) {
53
+ if (n < min_elements )
54
+ n = min_elements ;
55
+ min_elements += 1000 ;
56
+ return std::allocator<T>{}. allocate_at_least (n) ;
57
57
}
58
- T* allocate (std::size_t n) { return allocate_at_least (n).ptr ; }
59
- void deallocate (T* p, std::size_t ) noexcept { :: operator delete ( static_cast < void *>(p) ); }
58
+ constexpr T* allocate (std::size_t n) { return allocate_at_least (n).ptr ; }
59
+ constexpr void deallocate (T* p, std::size_t n ) noexcept { std::allocator<T>{}. deallocate (p, n ); }
60
60
};
61
61
62
62
template <typename T, typename U>
@@ -65,24 +65,28 @@ bool operator==(increasing_allocator<T>, increasing_allocator<U>) {
65
65
}
66
66
67
67
// https://github.com/llvm/llvm-project/issues/95161
68
- void test_increasing_allocator () {
68
+ constexpr bool test_increasing_allocator () {
69
69
std::vector<bool , increasing_allocator<bool >> v;
70
70
v.push_back (1 );
71
71
std::size_t capacity = v.capacity ();
72
72
v.shrink_to_fit ();
73
73
assert (v.capacity () <= capacity);
74
74
assert (v.size () == 1 );
75
+
76
+ return true ;
75
77
}
76
78
#endif // TEST_STD_VER >= 23
77
79
78
80
int main (int , char **)
79
81
{
80
- tests ();
81
- #if TEST_STD_VER >= 23
82
- test_increasing_allocator ();
83
- #endif // TEST_STD_VER >= 23
82
+ tests ();
84
83
#if TEST_STD_VER > 17
85
84
static_assert (tests ());
86
85
#endif
86
+ #if TEST_STD_VER >= 23
87
+ test_increasing_allocator ();
88
+ static_assert (test_increasing_allocator ());
89
+ #endif // TEST_STD_VER >= 23
90
+
87
91
return 0 ;
88
92
}
0 commit comments