brintos

brintos / llvm-project-archived public Read only

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