]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/specialized_algorithms/destroy/constrained.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / specialized_algorithms / destroy / constrained.cc
1 // Copyright (C) 2020-2024 Free Software Foundation, Inc.
2 // This file is part of the GNU ISO C++ Library. This library is free
3 // software; you can redistribute it and/or modify it under the
4 // terms of the GNU General Public License as published by the
5 // Free Software Foundation; either version 3, or (at your option)
6 // any later version.
7
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12
13 // You should have received a copy of the GNU General Public License along
14 // with this library; see the file COPYING3. If not see
15 // <http://www.gnu.org/licenses/>.
16
17 // { dg-do run { target c++20 } }
18
19 #include <algorithm>
20 #include <cstring>
21 #include <deque>
22 #include <list>
23 #include <memory>
24 #include <span>
25 #include <string>
26 #include <vector>
27
28 #include <testsuite_hooks.h>
29 #include <testsuite_iterators.h>
30
31 using __gnu_test::test_range;
32 using __gnu_test::input_iterator_wrapper_nocopy;
33
34 namespace ranges = std::ranges;
35
36 struct X
37 {
38 X()
39 { ++count; }
40
41 ~X()
42 { --count; }
43
44 static inline int count = 0;
45 };
46
47 void
48 test01()
49 {
50 for (int k = 0; k < 3; k++)
51 {
52 constexpr int size = 1024;
53 auto buffer = std::unique_ptr<char[]>(new char[sizeof(X)*size]);
54 std::span<X> rx((X *)buffer.get(), size);
55
56 ranges::uninitialized_default_construct(rx);
57 VERIFY( X::count == size );
58
59 auto i = rx.begin();
60 if (k == 0)
61 i = ranges::destroy(rx);
62 else if (k == 1)
63 i = ranges::destroy(rx.begin(), rx.end());
64 else if (k == 2)
65 i = ranges::destroy_n(rx.begin(), size);
66 else
67 __builtin_abort();
68
69 VERIFY( i == rx.end() );
70 VERIFY( X::count == 0 );
71 }
72 }
73
74 void
75 test02()
76 {
77 // LWG 3355
78 {
79 int x[3] = {0};
80 test_range<int, input_iterator_wrapper_nocopy> rx(x);
81 ranges::destroy(rx);
82 ranges::destroy_n(rx.begin(), 3);
83 }
84 }
85
86 int
87 main()
88 {
89 test01();
90 }