brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.5 KiB · 70c1e78 Raw
98 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// iterator insert(const_iterator position, const value_type& x);13 14#include <vector>15#include <cassert>16#include <cstddef>17 18#include "test_macros.h"19#include "min_allocator.h"20 21TEST_CONSTEXPR_CXX20 bool tests() {22  {23    std::vector<bool> v(100);24    std::vector<bool>::iterator i = v.insert(v.cbegin() + 10, 1);25    assert(v.size() == 101);26    assert(i == v.begin() + 10);27    std::size_t j;28    for (j = 0; j < 10; ++j)29      assert(v[j] == 0);30    assert(v[j] == 1);31    for (++j; j < v.size(); ++j)32      assert(v[j] == 0);33  }34  {35    std::vector<bool> v(100);36    while (v.size() < v.capacity())37      v.push_back(false);38    std::size_t sz                = v.size();39    std::vector<bool>::iterator i = v.insert(v.cbegin() + 10, 1);40    assert(v.size() == sz + 1);41    assert(i == v.begin() + 10);42    std::size_t j;43    for (j = 0; j < 10; ++j)44      assert(v[j] == 0);45    assert(v[j] == 1);46    for (++j; j < v.size(); ++j)47      assert(v[j] == 0);48  }49  {50    std::vector<bool> v(100);51    while (v.size() < v.capacity())52      v.push_back(false);53    v.pop_back();54    v.pop_back();55    std::size_t sz                = v.size();56    std::vector<bool>::iterator i = v.insert(v.cbegin() + 10, 1);57    assert(v.size() == sz + 1);58    assert(i == v.begin() + 10);59    std::size_t j;60    for (j = 0; j < 10; ++j)61      assert(v[j] == 0);62    assert(v[j] == 1);63    for (++j; j < v.size(); ++j)64      assert(v[j] == 0);65  }66#if TEST_STD_VER >= 1167  {68    std::vector<bool, explicit_allocator<bool>> v(10);69    std::vector<bool, explicit_allocator<bool>>::iterator i = v.insert(v.cbegin() + 10, 1);70    assert(v.size() == 11);71    assert(i == v.begin() + 10);72    assert(*i == 1);73  }74  {75    std::vector<bool, min_allocator<bool>> v(100);76    std::vector<bool, min_allocator<bool>>::iterator i = v.insert(v.cbegin() + 10, 1);77    assert(v.size() == 101);78    assert(i == v.begin() + 10);79    std::size_t j;80    for (j = 0; j < 10; ++j)81      assert(v[j] == 0);82    assert(v[j] == 1);83    for (++j; j < v.size(); ++j)84      assert(v[j] == 0);85  }86#endif87 88  return true;89}90 91int main(int, char**) {92  tests();93#if TEST_STD_VER > 1794  static_assert(tests());95#endif96  return 0;97}98