102 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// template <class... Args> iterator emplace(const_iterator p, Args&&... args);12 13// UNSUPPORTED: c++0314 15#include "asan_testing.h"16#include <deque>17#include <cassert>18#include <cstddef>19 20#include "test_macros.h"21#include "../../../Emplaceable.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(Emplaceable());38 for (int i = 0; i < start; ++i)39 c.pop_front();40 return c;41}42 43template <class C>44void test(int P, C& c1) {45 typedef typename C::const_iterator CI;46 std::size_t c1_osize = c1.size();47 CI i = c1.emplace(c1.begin() + P, Emplaceable(1, 2.5));48 assert(i == c1.begin() + P);49 assert(c1.size() == c1_osize + 1);50 assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());51 assert(*i == Emplaceable(1, 2.5));52 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1));53}54 55template <class C>56void testN(int start, int N) {57 for (int i = 0; i <= 3; ++i) {58 if (0 <= i && i <= N) {59 C c1 = make<C>(N, start);60 test(i, c1);61 }62 }63 for (int i = N / 2 - 1; i <= N / 2 + 1; ++i) {64 if (0 <= i && i <= N) {65 C c1 = make<C>(N, start);66 test(i, c1);67 }68 }69 for (int i = N - 3; i <= N; ++i) {70 if (0 <= i && i <= N) {71 C c1 = make<C>(N, start);72 test(i, c1);73 }74 }75}76 77int main(int, char**) {78 {79 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};80 const int N = sizeof(rng) / sizeof(rng[0]);81 for (int i = 0; i < N; ++i)82 for (int j = 0; j < N; ++j)83 testN<std::deque<Emplaceable> >(rng[i], rng[j]);84 }85 {86 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};87 const int N = sizeof(rng) / sizeof(rng[0]);88 for (int i = 0; i < N; ++i)89 for (int j = 0; j < N; ++j)90 testN<std::deque<Emplaceable, min_allocator<Emplaceable>> >(rng[i], rng[j]);91 }92 {93 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};94 const int N = sizeof(rng) / sizeof(rng[0]);95 for (int i = 0; i < N; ++i)96 for (int j = 0; j < N; ++j)97 testN<std::deque<Emplaceable, safe_allocator<Emplaceable>> >(rng[i], rng[j]);98 }99 100 return 0;101}102