| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <stack> |
| 10 | |
| 11 | // template <class Alloc> |
| 12 | // stack(const container_type& c, const Alloc& a); |
| 13 | |
| 14 | #include <stack> |
| 15 | #include <cassert> |
| 16 | #include <cstddef> |
| 17 | |
| 18 | #include "test_macros.h" |
| 19 | #include "test_allocator.h" |
| 20 | |
| 21 | template <class C> |
| 22 | C make(int n) { |
| 23 | C c; |
| 24 | for (int i = 0; i < n; ++i) |
| 25 | c.push_back(i); |
| 26 | return c; |
| 27 | } |
| 28 | |
| 29 | typedef std::deque<int, test_allocator<int> > C; |
| 30 | |
| 31 | struct test : public std::stack<int, C> { |
| 32 | typedef std::stack<int, C> base; |
| 33 | |
| 34 | explicit test(const test_allocator<int>& a) : base(a) {} |
| 35 | test(const container_type& cont, const test_allocator<int>& a) : base(cont, a) {} |
| 36 | #if TEST_STD_VER >= 11 |
| 37 | test(container_type&& cont, const test_allocator<int>& a) : base(std::move(cont), a) {} |
| 38 | test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {} |
| 39 | #endif |
| 40 | test_allocator<int> get_allocator() { return c.get_allocator(); } |
| 41 | }; |
| 42 | |
| 43 | int main(int, char**) { |
| 44 | C d = make<C>(n: 5); |
| 45 | test q(d, test_allocator<int>(4)); |
| 46 | assert(q.get_allocator() == test_allocator<int>(4)); |
| 47 | assert(q.size() == 5); |
| 48 | for (C::size_type i = 0; i < d.size(); ++i) { |
| 49 | assert(q.top() == d[d.size() - i - 1]); |
| 50 | q.pop(); |
| 51 | } |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |