| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <vector> |
| 10 | |
| 11 | // void flip(); |
| 12 | |
| 13 | #include <cassert> |
| 14 | #include <memory> |
| 15 | #include <vector> |
| 16 | |
| 17 | #include "min_allocator.h" |
| 18 | #include "test_allocator.h" |
| 19 | #include "test_macros.h" |
| 20 | |
| 21 | template <typename Allocator> |
| 22 | TEST_CONSTEXPR_CXX20 void test_vector_flip(std::size_t n, Allocator a) { |
| 23 | std::vector<bool, Allocator> v(n, false, a); |
| 24 | for (std::size_t i = 0; i < n; ++i) |
| 25 | v[i] = i & 1; |
| 26 | std::vector<bool, Allocator> original = v; |
| 27 | v.flip(); |
| 28 | for (size_t i = 0; i < n; ++i) |
| 29 | assert(v[i] == !original[i]); |
| 30 | v.flip(); |
| 31 | assert(v == original); |
| 32 | } |
| 33 | |
| 34 | TEST_CONSTEXPR_CXX20 bool tests() { |
| 35 | // Test empty vectors |
| 36 | test_vector_flip(0, std::allocator<bool>()); |
| 37 | test_vector_flip(0, min_allocator<bool>()); |
| 38 | test_vector_flip(0, test_allocator<bool>(5)); |
| 39 | |
| 40 | // Test small vectors with different allocators |
| 41 | test_vector_flip(3, std::allocator<bool>()); |
| 42 | test_vector_flip(3, min_allocator<bool>()); |
| 43 | test_vector_flip(3, test_allocator<bool>(5)); |
| 44 | |
| 45 | // Test large vectors with different allocators |
| 46 | test_vector_flip(1000, std::allocator<bool>()); |
| 47 | test_vector_flip(1000, min_allocator<bool>()); |
| 48 | test_vector_flip(1000, test_allocator<bool>(5)); |
| 49 | |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | int main(int, char**) { |
| 54 | tests(); |
| 55 | #if TEST_STD_VER >= 20 |
| 56 | static_assert(tests()); |
| 57 | #endif |
| 58 | return 0; |
| 59 | } |
| 60 | |