1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is dual licensed under the MIT and the University of Illinois Open 6// Source Licenses. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// <deque> 11 12// template <class... Args> iterator emplace(const_iterator p, Args&&... args); 13 14// UNSUPPORTED: c++98, c++03 15 16#include <deque> 17#include <cassert> 18#include <cstddef> 19 20#include "../../../Emplaceable.h" 21#include "min_allocator.h" 22 23 24template <class C> 25C 26make(int size, int start = 0 ) 27{ 28 const int b = 4096 / sizeof(int); 29 int init = 0; 30 if (start > 0) 31 { 32 init = (start+1) / b + ((start+1) % b != 0); 33 init *= b; 34 --init; 35 } 36 C c(init); 37 for (int i = 0; i < init-start; ++i) 38 c.pop_back(); 39 for (int i = 0; i < size; ++i) 40 c.push_back(Emplaceable()); 41 for (int i = 0; i < start; ++i) 42 c.pop_front(); 43 return c; 44} 45 46template <class C> 47void 48test(int P, C& c1) 49{ 50 typedef typename C::const_iterator CI; 51 std::size_t c1_osize = c1.size(); 52 CI i = c1.emplace(c1.begin() + P, Emplaceable(1, 2.5)); 53 assert(i == c1.begin() + P); 54 assert(c1.size() == c1_osize + 1); 55 assert(static_cast<std::size_t>(distance(c1.begin(), c1.end())) == c1.size()); 56 assert(*i == Emplaceable(1, 2.5)); 57} 58 59template <class C> 60void 61testN(int start, int N) 62{ 63 for (int i = 0; i <= 3; ++i) 64 { 65 if (0 <= i && i <= N) 66 { 67 C c1 = make<C>(N, start); 68 test(i, c1); 69 } 70 } 71 for (int i = N/2-1; i <= N/2+1; ++i) 72 { 73 if (0 <= i && i <= N) 74 { 75 C c1 = make<C>(N, start); 76 test(i, c1); 77 } 78 } 79 for (int i = N - 3; i <= N; ++i) 80 { 81 if (0 <= i && i <= N) 82 { 83 C c1 = make<C>(N, start); 84 test(i, c1); 85 } 86 } 87} 88 89 90int main() 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> >(rng[i], rng[j]); 98 } 99 { 100 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; 101 const int N = sizeof(rng)/sizeof(rng[0]); 102 for (int i = 0; i < N; ++i) 103 for (int j = 0; j < N; ++j) 104 testN<std::deque<Emplaceable, min_allocator<Emplaceable>> >(rng[i], rng[j]); 105 } 106} 107