]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/stack/cons_from_iters.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / stack / cons_from_iters.cc
1 // Copyright (C) 2021-2022 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // { dg-options "-std=gnu++23" }
19 // { dg-do run { target c++23 } }
20
21 #include <stack>
22
23 #ifndef __cpp_lib_adaptor_iterator_pair_constructor
24 #error Feature test macro for iterator pair constructors is missing in <stack>
25 #elif __cpp_lib_adaptor_iterator_pair_constructor != 202106L
26 #error Feature test macro for iterator pair constructors has wrong value in <stack>
27 #endif
28
29 #include <testsuite_hooks.h>
30 #include <testsuite_allocator.h>
31
32 void
33 test_p1425r4()
34 {
35 const int vals[] = { 1, 2, 3, 7, 8, 9, 5, 6, 7 };
36
37 std::stack<int> s(std::begin(vals), std::end(vals));
38 VERIFY( s.size() == std::size(vals) );
39 VERIFY( s.top() == 7 );
40
41 using Alloc = __gnu_test::uneq_allocator<int>;
42
43 struct Stack : std::stack<int, std::deque<int, Alloc>>
44 {
45 using stack::stack;
46
47 Alloc get_allocator() const { return c.get_allocator(); }
48 };
49
50 Alloc a0, a1(1);
51 Stack s0(std::begin(vals), std::end(vals) - 1);
52 VERIFY( s0.size() == std::size(vals) - 1 );
53 VERIFY( s0.top() == 6 );
54 VERIFY( s0.get_allocator() == a0 );
55
56 Stack s1(std::begin(vals), std::end(vals) - 2, a1);
57 VERIFY( s1.size() == std::size(vals) - 2 );
58 VERIFY( s1.top() == 5 );
59 VERIFY( s1.get_allocator() == a1 );
60 }
61
62 int main()
63 {
64 test_p1425r4();
65 }