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 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <deque> |
| 11 | |
| 12 | // void resize(size_type n); |
| 13 | |
| 14 | #include <deque> |
| 15 | #include <cassert> |
| 16 | |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 17 | #include "min_allocator.h" |
Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 +0000 | [diff] [blame] | 18 | |
| 19 | template <class C> |
| 20 | C |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 21 | make(int size, int start = 0 ) |
| 22 | { |
| 23 | const int b = 4096 / sizeof(int); |
| 24 | int init = 0; |
| 25 | if (start > 0) |
| 26 | { |
| 27 | init = (start+1) / b + ((start+1) % b != 0); |
| 28 | init *= b; |
| 29 | --init; |
| 30 | } |
Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 +0000 | [diff] [blame] | 31 | C c(init, 0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 32 | for (int i = 0; i < init-start; ++i) |
| 33 | c.pop_back(); |
| 34 | for (int i = 0; i < size; ++i) |
| 35 | c.push_back(i); |
| 36 | for (int i = 0; i < start; ++i) |
| 37 | c.pop_front(); |
| 38 | return c; |
Eric Fiselier | 5495e2e | 2015-02-10 17:20:18 +0000 | [diff] [blame^] | 39 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 40 | |
Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 +0000 | [diff] [blame] | 41 | template <class C> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 42 | void |
Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 +0000 | [diff] [blame] | 43 | test(C& c1, int size) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 44 | { |
Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 +0000 | [diff] [blame] | 45 | typedef typename C::const_iterator CI; |
Marshall Clow | 5134953 | 2014-07-08 15:19:40 +0000 | [diff] [blame] | 46 | typename C::size_type c1_osize = c1.size(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 47 | c1.resize(size); |
| 48 | assert(c1.size() == size); |
| 49 | assert(distance(c1.begin(), c1.end()) == c1.size()); |
| 50 | CI i = c1.begin(); |
| 51 | for (int j = 0; j < std::min(c1_osize, c1.size()); ++j, ++i) |
| 52 | assert(*i == j); |
| 53 | for (int j = c1_osize; j < c1.size(); ++j, ++i) |
| 54 | assert(*i == 0); |
| 55 | } |
| 56 | |
Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 +0000 | [diff] [blame] | 57 | template <class C> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 58 | void |
| 59 | testN(int start, int N, int M) |
| 60 | { |
Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 +0000 | [diff] [blame] | 61 | typedef typename C::const_iterator CI; |
| 62 | C c1 = make<C>(N, start); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 63 | test(c1, M); |
| 64 | } |
| 65 | |
| 66 | int main() |
| 67 | { |
Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 +0000 | [diff] [blame] | 68 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 69 | int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; |
| 70 | const int N = sizeof(rng)/sizeof(rng[0]); |
| 71 | for (int i = 0; i < N; ++i) |
| 72 | for (int j = 0; j < N; ++j) |
| 73 | for (int k = 0; k < N; ++k) |
Howard Hinnant | fcd8db7 | 2013-06-23 21:17:24 +0000 | [diff] [blame] | 74 | testN<std::deque<int> >(rng[i], rng[j], rng[k]); |
| 75 | } |
| 76 | #if __cplusplus >= 201103L |
| 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 | for (int k = 0; k < N; ++k) |
| 83 | testN<std::deque<int, min_allocator<int>>>(rng[i], rng[j], rng[k]); |
| 84 | } |
| 85 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 86 | } |