brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · 7bf8bdb Raw
84 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <vector>10// vector<bool>11 12// vector& operator=(const vector& c);13 14#include <cassert>15#include <vector>16 17#include "min_allocator.h"18#include "test_allocator.h"19#include "test_macros.h"20 21TEST_CONSTEXPR_CXX20 void test_copy_assignment(unsigned N) {22  //23  // Test with insufficient space where reallocation occurs during assignment24  //25  { // POCCA = true_type, thus copy-assign the allocator26    std::vector<bool, other_allocator<bool> > l(N, true, other_allocator<bool>(5));27    std::vector<bool, other_allocator<bool> > l2(other_allocator<bool>(3));28    l2 = l;29    assert(l2 == l);30    assert(l2.get_allocator() == other_allocator<bool>(5));31  }32  { // POCCA = false_type, thus allocator is unchanged33    std::vector<bool, test_allocator<bool> > l(N + 64, true, test_allocator<bool>(5));34    std::vector<bool, test_allocator<bool> > l2(10, false, test_allocator<bool>(3));35    l2 = l;36    assert(l2 == l);37    assert(l2.get_allocator() == test_allocator<bool>(3));38  }39  { // Stateless allocator40    std::vector<bool, min_allocator<bool> > l(N + 64, true, min_allocator<bool>());41    std::vector<bool, min_allocator<bool> > l2(N / 2, false, min_allocator<bool>());42    l2 = l;43    assert(l2 == l);44    assert(l2.get_allocator() == min_allocator<bool>());45  }46 47  //48  // Test with sufficient size where no reallocation occurs during assignment49  //50  { // POCCA = false_type, thus allocator is unchanged51    std::vector<bool, test_allocator<bool> > l(N, true, test_allocator<bool>(5));52    std::vector<bool, test_allocator<bool> > l2(N + 64, false, test_allocator<bool>(3));53    l2 = l;54    assert(l2 == l);55    assert(l2.get_allocator() == test_allocator<bool>(3));56  }57  { // POCCA = true_type, thus copy-assign the allocator58    std::vector<bool, other_allocator<bool> > l(N, true, other_allocator<bool>(5));59    std::vector<bool, other_allocator<bool> > l2(N * 2, false, other_allocator<bool>(3));60    l2.reserve(5);61    l2 = l;62    assert(l2 == l);63    assert(l2.get_allocator() == other_allocator<bool>(5));64  }65}66 67TEST_CONSTEXPR_CXX20 bool tests() {68  test_copy_assignment(3);69  test_copy_assignment(18);70  test_copy_assignment(33);71  test_copy_assignment(65);72  test_copy_assignment(299);73 74  return true;75}76 77int main(int, char**) {78  tests();79#if TEST_STD_VER > 1780  static_assert(tests());81#endif82  return 0;83}84