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