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// <queue>
10
11// template <class Alloc>
12// queue(const container_type& c, const Alloc& a);
13
14#include <queue>
15#include <cassert>
16#include <cstddef>
17
18#include "test_macros.h"
19#include "test_allocator.h"
20
21template <class C>
22C make(int n) {
23 C c;
24 for (int i = 0; i < n; ++i)
25 c.push_back(i);
26 return c;
27}
28
29typedef std::deque<int, test_allocator<int> > C;
30
31struct test : public std::queue<int, C> {
32 typedef std::queue<int, C> base;
33
34 explicit test(const test_allocator<int>& a) : base(a) {}
35 test(const container_type& container, const test_allocator<int>& a) : base(container, a) {}
36#if TEST_STD_VER >= 11
37 test(container_type&& container, const test_allocator<int>& a) : base(std::move(container), 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
43int 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.front() == d[i]);
50 q.pop();
51 }
52
53 return 0;
54}
55

source code of libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_container_alloc.pass.cpp