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 // UNSUPPORTED: c++98, c++03 11 12 // <deque> 13 14 // template <class... Args> reference emplace_front(Args&&... args); 15 16 #include <deque> 17 #include <cassert> 18 19 #include "../../../Emplaceable.h" 20 #include "min_allocator.h" 21 22 template <class C> 23 C 24 make(int size, int start = 0 ) 25 { 26 const int b = 4096 / sizeof(int); 27 int init = 0; 28 if (start > 0) 29 { 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(Emplaceable()); 39 for (int i = 0; i < start; ++i) 40 c.pop_front(); 41 return c; 42 } 43 44 template <class C> 45 void 46 test(C& c1) 47 { 48 typedef typename C::iterator I; 49 typedef typename C::reference Ref; 50 std::size_t c1_osize = c1.size(); 51 Ref res_ref = c1.emplace_front(Emplaceable(1, 2.5)); 52 assert(c1.size() == c1_osize + 1); 53 assert(distance(c1.begin(), c1.end()) == c1.size()); 54 I i = c1.begin(); 55 assert(*i == Emplaceable(1, 2.5)); 56 assert(&res_ref == &(*i)); 57 } 58 59 template <class C> 60 void 61 testN(int start, int N) 62 { 63 C c1 = make<C>(N, start); 64 test(c1); 65 } 66 67 68 int main() 69 { 70 { 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<Emplaceable> >(rng[i], rng[j]); 76 } 77 { 78 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; 79 const int N = sizeof(rng)/sizeof(rng[0]); 80 for (int i = 0; i < N; ++i) 81 for (int j = 0; j < N; ++j) 82 testN<std::deque<Emplaceable, min_allocator<Emplaceable>> >(rng[i], rng[j]); 83 } 84 } 85