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 | // queue(InputIterator, InputIterator, const Allocator&); |
15 | |
16 | #include <cassert> |
17 | #include <queue> |
18 | |
19 | #include "test_allocator.h" |
20 | |
21 | using base_type = std::queue<int, std::deque<int, test_allocator<int>>>; |
22 | |
23 | class GetAlloc : public base_type { |
24 | test_allocator_statistics* stats; |
25 | |
26 | public: |
27 | explicit 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 | |
35 | int main(int, char**) { |
36 | const int a[] = {4, 3, 2, 1}; |
37 | test_allocator_statistics stats{}; |
38 | GetAlloc queue(stats, a, a + 4); |
39 | assert(queue.front() == 4); |
40 | queue.pop(); |
41 | assert(queue.front() == 3); |
42 | queue.pop(); |
43 | assert(queue.front() == 2); |
44 | queue.pop(); |
45 | assert(queue.front() == 1); |
46 | queue.pop(); |
47 | assert(queue.empty()); |
48 | |
49 | return 0; |
50 | } |
51 | |