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// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10
11// <queue>
12
13// template <class InputIterator, class Allocator>
14// stack(InputIterator, InputIterator, Allocator);
15
16#include <cassert>
17#include <stack>
18
19#include "test_allocator.h"
20
21using base_type = std::stack<int, std::deque<int, test_allocator<int>>>;
22
23class GetAlloc : public base_type {
24 test_allocator_statistics* stats;
25
26public:
27 GetAlloc(test_allocator_statistics& stats_, const int* begin, const int* end)
28 : base_type(begin, end, test_allocator<int>(&stats_)), stats(&stats_) {}
29 void check() {
30 assert(size() == 4);
31 assert(stats->alloc_count > 0);
32 }
33};
34
35int main(int, char**) {
36 const int a[] = {4, 3, 2, 1};
37 test_allocator_statistics stats{};
38 GetAlloc stack(stats, a, a + 4);
39 assert(stack.top() == 1);
40 stack.pop();
41 assert(stack.top() == 2);
42 stack.pop();
43 assert(stack.top() == 3);
44 stack.pop();
45 assert(stack.top() == 4);
46 stack.pop();
47 assert(stack.empty());
48
49 return 0;
50}
51

source code of libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_iterators.pass.cpp