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
10
11// <stack>
12
13// template <class Alloc>
14// stack(stack&& q, const Alloc& a);
15
16#include <stack>
17#include <cassert>
18
19#include "test_macros.h"
20#include "test_allocator.h"
21#include "MoveOnly.h"
22
23
24template <class C>
25C
26make(int n)
27{
28 C c;
29 for (int i = 0; i < n; ++i)
30 c.push_back(MoveOnly(i));
31 return c;
32}
33
34typedef std::deque<MoveOnly, test_allocator<MoveOnly> > C;
35
36template <class T>
37struct test
38 : public std::stack<T, C>
39{
40 typedef std::stack<T, C> base;
41 typedef test_allocator<MoveOnly> allocator_type;
42 typedef typename base::container_type container_type;
43
44 explicit test(const allocator_type& a) : base(a) {}
45 test(const container_type& cont, const allocator_type& a) : base(cont, a) {}
46 test(container_type&& cont, const allocator_type& a) : base(std::move(cont), a) {}
47 test(test&& q, const allocator_type& a) : base(std::move(q), a) {}
48 allocator_type get_allocator() {return this->c.get_allocator();}
49};
50
51
52int main(int, char**)
53{
54 test<MoveOnly> q(make<C>(5), test_allocator<MoveOnly>(4));
55 test<MoveOnly> q2(std::move(q), test_allocator<MoveOnly>(5));
56 assert(q2.get_allocator() == test_allocator<MoveOnly>(5));
57 assert(q2.size() == 5);
58
59 return 0;
60}
61

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