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> void emplace_front(Args&&... args); 13 14 #include <deque> 15 #include <cassert> 16 17 #include "../../../Emplaceable.h" 18 #include "min_allocator.h" 19 20 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 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 std::size_t c1_osize = c1.size(); 50 c1.emplace_front(Emplaceable(1, 2.5)); 51 assert(c1.size() == c1_osize + 1); 52 assert(distance(c1.begin(), c1.end()) == c1.size()); 53 I i = c1.begin(); 54 assert(*i == Emplaceable(1, 2.5)); 55 } 56 57 template <class C> 58 void 59 testN(int start, int N) 60 { 61 C c1 = make<C>(N, start); 62 test(c1); 63 } 64 65 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 66 67 int main() 68 { 69 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 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 #if __cplusplus >= 201103L 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, min_allocator<Emplaceable>> >(rng[i], rng[j]); 84 } 85 #endif 86 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 87 } 88