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