Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. 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 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 19 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 20 | |
| 21 | std::deque<Emplaceable> |
| 22 | make(int size, int start = 0 ) |
| 23 | { |
| 24 | const int b = 4096 / sizeof(int); |
| 25 | int init = 0; |
| 26 | if (start > 0) |
| 27 | { |
| 28 | init = (start+1) / b + ((start+1) % b != 0); |
| 29 | init *= b; |
| 30 | --init; |
| 31 | } |
| 32 | std::deque<Emplaceable> c(init); |
| 33 | for (int i = 0; i < init-start; ++i) |
| 34 | c.pop_back(); |
| 35 | for (int i = 0; i < size; ++i) |
| 36 | c.push_back(Emplaceable()); |
| 37 | for (int i = 0; i < start; ++i) |
| 38 | c.pop_front(); |
| 39 | return c; |
| 40 | }; |
| 41 | |
| 42 | void |
| 43 | test(std::deque<Emplaceable>& c1) |
| 44 | { |
| 45 | typedef std::deque<Emplaceable> C; |
| 46 | typedef C::iterator I; |
| 47 | std::size_t c1_osize = c1.size(); |
| 48 | c1.emplace_front(Emplaceable(1, 2.5)); |
| 49 | assert(c1.size() == c1_osize + 1); |
| 50 | assert(distance(c1.begin(), c1.end()) == c1.size()); |
| 51 | I i = c1.begin(); |
| 52 | assert(*i == Emplaceable(1, 2.5)); |
| 53 | } |
| 54 | |
| 55 | void |
| 56 | testN(int start, int N) |
| 57 | { |
| 58 | typedef std::deque<Emplaceable> C; |
| 59 | C c1 = make(N, start); |
| 60 | test(c1); |
| 61 | } |
| 62 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 63 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 64 | |
| 65 | int main() |
| 66 | { |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 67 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 68 | int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; |
| 69 | const int N = sizeof(rng)/sizeof(rng[0]); |
| 70 | for (int i = 0; i < N; ++i) |
| 71 | for (int j = 0; j < N; ++j) |
| 72 | testN(rng[i], rng[j]); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 73 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 74 | } |