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 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 typedef std::deque<int, test_allocator<int> > C;
32 
33 struct test
34     : public std::stack<int, C>
35 {
36     typedef std::stack<int, C> base;
37 
testtest38     explicit test(const test_allocator<int>& a) : base(a) {}
testtest39     test(const container_type& cont, const test_allocator<int>& a) : base(cont, a) {}
40 #if TEST_STD_VER >= 11
testtest41     test(container_type&& cont, const test_allocator<int>& a) : base(std::move(cont), a) {}
testtest42     test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {}
43 #endif
get_allocatortest44     test_allocator<int> get_allocator() {return c.get_allocator();}
45 };
46 
main(int,char **)47 int main(int, char**)
48 {
49     C d = make<C>(5);
50     test q(d, test_allocator<int>(4));
51     assert(q.get_allocator() == test_allocator<int>(4));
52     assert(q.size() == 5);
53     for (C::size_type i = 0; i < d.size(); ++i)
54     {
55         assert(q.top() == d[d.size() - i - 1]);
56         q.pop();
57     }
58 
59   return 0;
60 }
61