brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · 2bd390a Raw
81 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// <deque>10 11// void pop_front()12 13#include "asan_testing.h"14#include <deque>15#include <cassert>16#include <cstddef>17 18#include "test_macros.h"19#include "min_allocator.h"20 21template <class C>22C make(int size, int start = 0) {23  const int b = 4096 / sizeof(int);24  int init    = 0;25  if (start > 0) {26    init = (start + 1) / b + ((start + 1) % b != 0);27    init *= b;28    --init;29  }30  C c(init, 0);31  for (int i = 0; i < init - start; ++i)32    c.pop_back();33  for (int i = 0; i < size; ++i)34    c.push_back(i);35  for (int i = 0; i < start; ++i)36    c.pop_front();37  return c;38}39 40template <class C>41void test(C& c1) {42  typedef typename C::iterator I;43  std::size_t c1_osize = c1.size();44  c1.pop_front();45  assert(c1.size() == c1_osize - 1);46  assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());47  LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1));48  I i = c1.begin();49  for (int j = 1; static_cast<std::size_t>(j) < c1.size(); ++j, ++i)50    assert(*i == j);51}52 53template <class C>54void testN(int start, int N) {55  if (N != 0) {56    C c1 = make<C>(N, start);57    test(c1);58  }59}60 61int main(int, char**) {62  {63    int rng[]   = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};64    const int N = sizeof(rng) / sizeof(rng[0]);65    for (int i = 0; i < N; ++i)66      for (int j = 0; j < N; ++j)67        testN<std::deque<int> >(rng[i], rng[j]);68  }69#if TEST_STD_VER >= 1170  {71    int rng[]   = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};72    const int N = sizeof(rng) / sizeof(rng[0]);73    for (int i = 0; i < N; ++i)74      for (int j = 0; j < N; ++j)75        testN<std::deque<int, min_allocator<int>> >(rng[i], rng[j]);76  }77#endif78 79  return 0;80}81