//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // vector // vector& operator=(const vector& c); #include #include #include "min_allocator.h" #include "test_allocator.h" #include "test_macros.h" TEST_CONSTEXPR_CXX20 void test_copy_assignment(unsigned N) { // // Test with insufficient space where reallocation occurs during assignment // { // POCCA = true_type, thus copy-assign the allocator std::vector > l(N, true, other_allocator(5)); std::vector > l2(other_allocator(3)); l2 = l; assert(l2 == l); assert(l2.get_allocator() == other_allocator(5)); } { // POCCA = false_type, thus allocator is unchanged std::vector > l(N + 64, true, test_allocator(5)); std::vector > l2(10, false, test_allocator(3)); l2 = l; assert(l2 == l); assert(l2.get_allocator() == test_allocator(3)); } { // Stateless allocator std::vector > l(N + 64, true, min_allocator()); std::vector > l2(N / 2, false, min_allocator()); l2 = l; assert(l2 == l); assert(l2.get_allocator() == min_allocator()); } // // Test with sufficient size where no reallocation occurs during assignment // { // POCCA = false_type, thus allocator is unchanged std::vector > l(N, true, test_allocator(5)); std::vector > l2(N + 64, false, test_allocator(3)); l2 = l; assert(l2 == l); assert(l2.get_allocator() == test_allocator(3)); } { // POCCA = true_type, thus copy-assign the allocator std::vector > l(N, true, other_allocator(5)); std::vector > l2(N * 2, false, other_allocator(3)); l2.reserve(5); l2 = l; assert(l2 == l); assert(l2.get_allocator() == other_allocator(5)); } } TEST_CONSTEXPR_CXX20 bool tests() { test_copy_assignment(3); test_copy_assignment(18); test_copy_assignment(33); test_copy_assignment(65); test_copy_assignment(299); return true; } int main(int, char**) { tests(); #if TEST_STD_VER > 17 static_assert(tests()); #endif return 0; }