xref: /llvm-project/libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_iterators.pass.cpp (revision 59d246e55f56799ef47dcaae9788c0c3e77a2244)
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>
14 // stack(InputIterator, InputIterator);
15 
16 #include <cassert>
17 #include <stack>
18 
19 #include "test_allocator.h"
20 
21 static_assert(!std::is_constructible_v<std::stack<int>, int, int, std::allocator<int>>);
22 static_assert(!std::is_constructible_v<std::stack<int>, int*, int*, int>);
23 static_assert( std::is_constructible_v<std::stack<int, std::deque<int, test_allocator<int>>>, int*, int*, test_allocator<int>>);
24 static_assert(!std::is_constructible_v<std::stack<int, std::deque<int, test_allocator<int>>>, int*, int*, std::allocator<int>>);
25 
26 template <class T>
27 struct alloc : test_allocator<T> {
28   template <class U>
29   struct rebind {
30     using other = alloc<U>;
31   };
32   alloc(test_allocator_statistics* a);
33 };
34 static_assert(
35     std::is_constructible_v<std::stack<int, std::deque<int, alloc<int>>>, int*, int*, test_allocator_statistics*>);
36 
main(int,char **)37 int main(int, char**) {
38   const int a[] = {4, 3, 2, 1};
39   std::stack<int> stack(a, a + 4);
40   assert(stack.top() == 1);
41   stack.pop();
42   assert(stack.top() == 2);
43   stack.pop();
44   assert(stack.top() == 3);
45   stack.pop();
46   assert(stack.top() == 4);
47   stack.pop();
48   assert(stack.empty());
49 
50   return 0;
51 }
52