brintos

brintos / llvm-project-archived public Read only

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