Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame^] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure |
| 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 | // void assign(size_type n, const value_type& v); |
| 13 | |
| 14 | #include <deque> |
| 15 | #include <cassert> |
| 16 | |
| 17 | #include "../../../iterators.h" |
| 18 | |
| 19 | std::deque<int> |
| 20 | make(int size, int start = 0 ) |
| 21 | { |
| 22 | const int b = 4096 / sizeof(int); |
| 23 | int init = 0; |
| 24 | if (start > 0) |
| 25 | { |
| 26 | init = (start+1) / b + ((start+1) % b != 0); |
| 27 | init *= b; |
| 28 | --init; |
| 29 | } |
| 30 | std::deque<int> c(init, 0); |
| 31 | for (int i = 0; i < init-start; ++i) |
| 32 | c.pop_back(); |
| 33 | for (int i = 0; i < size; ++i) |
| 34 | c.push_back(i); |
| 35 | for (int i = 0; i < start; ++i) |
| 36 | c.pop_front(); |
| 37 | return c; |
| 38 | }; |
| 39 | |
| 40 | void |
| 41 | test(std::deque<int>& c1, int size, int v) |
| 42 | { |
| 43 | typedef std::deque<int> C; |
| 44 | typedef C::const_iterator CI; |
| 45 | std::size_t c1_osize = c1.size(); |
| 46 | c1.assign(size, v); |
| 47 | assert(c1.size() == size); |
| 48 | assert(distance(c1.begin(), c1.end()) == c1.size()); |
| 49 | for (CI i = c1.begin(); i != c1.end(); ++i) |
| 50 | assert(*i == v); |
| 51 | } |
| 52 | |
| 53 | void |
| 54 | testN(int start, int N, int M) |
| 55 | { |
| 56 | typedef std::deque<int> C; |
| 57 | typedef C::iterator I; |
| 58 | typedef C::const_iterator CI; |
| 59 | C c1 = make(N, start); |
| 60 | test(c1, M, -10); |
| 61 | } |
| 62 | |
| 63 | int main() |
| 64 | { |
| 65 | int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; |
| 66 | const int N = sizeof(rng)/sizeof(rng[0]); |
| 67 | for (int i = 0; i < N; ++i) |
| 68 | for (int j = 0; j < N; ++j) |
| 69 | for (int k = 0; k < N; ++k) |
| 70 | testN(rng[i], rng[j], rng[k]); |
| 71 | } |