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 | // <stack> |
| 11 | |
| 12 | // template <class Alloc> |
| 13 | // stack(const container_type& c, const Alloc& a); |
| 14 | |
| 15 | #include <stack> |
| 16 | #include <cassert> |
| 17 | |
| 18 | #include "../../../../test_allocator.h" |
| 19 | |
| 20 | template <class C> |
| 21 | C |
| 22 | make(int n) |
| 23 | { |
| 24 | C c; |
| 25 | for (int i = 0; i < n; ++i) |
| 26 | c.push_back(i); |
| 27 | return c; |
| 28 | } |
| 29 | |
| 30 | typedef std::deque<int, test_allocator<int> > C; |
| 31 | |
| 32 | struct test |
| 33 | : public std::stack<int, C> |
| 34 | { |
| 35 | typedef std::stack<int, C> base; |
| 36 | |
| 37 | explicit test(const test_allocator<int>& a) : base(a) {} |
| 38 | test(const container_type& c, const test_allocator<int>& a) : base(c, a) {} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 39 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 40 | test(container_type&& c, const test_allocator<int>& a) : base(std::move(c), a) {} |
| 41 | test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {} |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 42 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 43 | test_allocator<int> get_allocator() {return c.get_allocator();} |
| 44 | }; |
| 45 | |
| 46 | int main() |
| 47 | { |
| 48 | C d = make<C>(5); |
| 49 | test q(d, test_allocator<int>(4)); |
| 50 | assert(q.get_allocator() == test_allocator<int>(4)); |
| 51 | assert(q.size() == 5); |
| 52 | for (int i = 0; i < d.size(); ++i) |
| 53 | { |
| 54 | assert(q.top() == d[d.size() - i - 1]); |
| 55 | q.pop(); |
| 56 | } |
| 57 | } |