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 stack& q, const Alloc& a); |
13 | |
14 | #include <stack> |
15 | #include <cassert> |
16 | |
17 | #include "test_macros.h" |
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(int(i)); |
27 | return c; |
28 | } |
29 | |
30 | typedef std::deque<int, test_allocator<int> > C; |
31 | |
32 | template <class T> |
33 | struct test |
34 | : public std::stack<T, C> |
35 | { |
36 | typedef std::stack<T, C> base; |
37 | typedef test_allocator<int> allocator_type; |
38 | typedef typename base::container_type container_type; |
39 | |
40 | explicit test(const allocator_type& a) : base(a) {} |
41 | test(const container_type& cont, const allocator_type& a) : base(cont, a) {} |
42 | test(const test& q, const allocator_type& a) : base(q, a) {} |
43 | allocator_type get_allocator() {return this->c.get_allocator();} |
44 | }; |
45 | |
46 | int main(int, char**) |
47 | { |
48 | test<int> q(make<C>(5), test_allocator<int>(4)); |
49 | test<int> q2(q, test_allocator<int>(5)); |
50 | assert(q2.get_allocator() == test_allocator<int>(5)); |
51 | assert(q2.size() == 5); |
52 | |
53 | return 0; |
54 | } |
55 | |