|
11 | 11 |
|
12 | 12 | // void shrink_to_fit();
|
13 | 13 |
|
| 14 | +// XFAIL: FROZEN-CXX03-HEADERS-FIXME |
| 15 | + |
14 | 16 | #include <cassert>
|
| 17 | +#include <climits> |
15 | 18 | #include <vector>
|
16 | 19 |
|
17 | 20 | #include "increasing_allocator.h"
|
|
20 | 23 |
|
21 | 24 | TEST_CONSTEXPR_CXX20 bool tests() {
|
22 | 25 | {
|
23 |
| - std::vector<bool> v(100); |
| 26 | + using C = std::vector<bool>; |
| 27 | + C v(100); |
24 | 28 | v.push_back(1);
|
| 29 | + C::size_type before_cap = v.capacity(); |
| 30 | + v.clear(); |
25 | 31 | v.shrink_to_fit();
|
26 |
| - assert(v.capacity() >= 101); |
27 |
| - assert(v.size() >= 101); |
| 32 | + assert(v.capacity() <= before_cap); |
| 33 | + LIBCPP_ASSERT(v.capacity() == 0); // libc++ honors the shrink_to_fit request as a QOI matter |
| 34 | + assert(v.size() == 0); |
28 | 35 | }
|
29 |
| -#if TEST_STD_VER >= 11 |
30 | 36 | {
|
31 |
| - std::vector<bool, min_allocator<bool>> v(100); |
| 37 | + using C = std::vector<bool, min_allocator<bool> >; |
| 38 | + C v(100); |
32 | 39 | v.push_back(1);
|
| 40 | + C::size_type before_cap = v.capacity(); |
33 | 41 | v.shrink_to_fit();
|
34 | 42 | assert(v.capacity() >= 101);
|
35 |
| - assert(v.size() >= 101); |
| 43 | + assert(v.capacity() <= before_cap); |
| 44 | + assert(v.size() == 101); |
| 45 | + v.erase(v.begin() + 1, v.end()); |
| 46 | + v.shrink_to_fit(); |
| 47 | + assert(v.capacity() <= before_cap); |
| 48 | + LIBCPP_ASSERT(v.capacity() == C(1).capacity()); // libc++ honors the shrink_to_fit request as a QOI matter. |
| 49 | + assert(v.size() == 1); |
| 50 | + } |
| 51 | + |
| 52 | +#if defined(_LIBCPP_VERSION) |
| 53 | + { |
| 54 | + using C = std::vector<bool>; |
| 55 | + unsigned bits_per_word = static_cast<unsigned>(sizeof(C::__storage_type) * CHAR_BIT); |
| 56 | + C v(bits_per_word); |
| 57 | + v.push_back(1); |
| 58 | + assert(v.capacity() == bits_per_word * 2); |
| 59 | + assert(v.size() == bits_per_word + 1); |
| 60 | + v.pop_back(); |
| 61 | + v.shrink_to_fit(); |
| 62 | + assert(v.capacity() == bits_per_word); |
| 63 | + assert(v.size() == bits_per_word); |
| 64 | + } |
| 65 | + { |
| 66 | + using C = std::vector<bool>; |
| 67 | + unsigned bits_per_word = static_cast<unsigned>(sizeof(C::__storage_type) * CHAR_BIT); |
| 68 | + C v; |
| 69 | + v.reserve(bits_per_word * 2); |
| 70 | + v.push_back(1); |
| 71 | + assert(v.capacity() == bits_per_word * 2); |
| 72 | + assert(v.size() == 1); |
| 73 | + v.shrink_to_fit(); |
| 74 | + assert(v.capacity() == bits_per_word); |
| 75 | + assert(v.size() == 1); |
36 | 76 | }
|
37 | 77 | #endif
|
38 | 78 |
|
|
0 commit comments