]> git.ipfire.org Git - thirdparty/gcc.git/blame - 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
CommitLineData
99dee823 1// Copyright (C) 2020-2021 Free Software Foundation, Inc.
613c932f
PP
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-options "-std=gnu++2a" }
18// { dg-do run { target c++2a } }
19
20#include <algorithm>
21#include <cstring>
22#include <deque>
23#include <list>
24#include <memory>
25#include <span>
26#include <string>
27#include <vector>
28
29#include <testsuite_hooks.h>
30#include <testsuite_iterators.h>
31
144dfc68
PP
32using __gnu_test::test_range;
33using __gnu_test::input_iterator_wrapper_nocopy;
34
613c932f
PP
35namespace ranges = std::ranges;
36
37struct X
38{
39 X()
40 { ++count; }
41
42 ~X()
43 { --count; }
44
45 static inline int count = 0;
46};
47
48void
49test01()
50{
51 for (int k = 0; k < 3; k++)
52 {
53 constexpr int size = 1024;
54 auto buffer = std::unique_ptr<char[]>(new char[sizeof(X)*size]);
55 std::span<X> rx((X *)buffer.get(), size);
56
57 ranges::uninitialized_default_construct(rx);
58 VERIFY( X::count == size );
59
247f410b 60 auto i = rx.begin();
613c932f
PP
61 if (k == 0)
62 i = ranges::destroy(rx);
63 else if (k == 1)
64 i = ranges::destroy(rx.begin(), rx.end());
65 else if (k == 2)
66 i = ranges::destroy_n(rx.begin(), size);
67 else
68 __builtin_abort();
69
247f410b 70 VERIFY( i == rx.end() );
613c932f
PP
71 VERIFY( X::count == 0 );
72 }
73}
74
144dfc68
PP
75void
76test02()
77{
78 // LWG 3355
79 {
80 int x[3] = {0};
81 test_range<int, input_iterator_wrapper_nocopy> rx(x);
82 ranges::destroy(rx);
83 ranges::destroy_n(rx.begin(), 3);
84 }
85}
86
613c932f
PP
87int
88main()
89{
90 test01();
91}