1 // Copyright (C) 2020 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)
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.
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/>.
17 // { dg-options "-std=gnu++2a" }
18 // { dg-do run { target c++2a } }
29 #include <testsuite_hooks.h>
30 #include <testsuite_iterators.h>
32 using __gnu_test::test_forward_range;
34 namespace ranges = std::ranges;
40 static_assert(std::default_initializable<T>);
41 static_assert(std::equality_comparable<T>);
43 for (int k = 0; k < 6; k++)
45 constexpr int size = 1024;
46 auto buffer = std::unique_ptr<char[]>(new char[sizeof(T)*size]);
47 std::span<T> rx((T *)buffer.get(), size);
50 if constexpr (std::is_fundamental_v<T>)
52 std::memset(&t, 0xCC, sizeof(t));
58 i = ranges::uninitialized_default_construct(rx.begin(), rx.end());
60 i = ranges::uninitialized_default_construct(rx);
62 i = ranges::uninitialized_default_construct_n(rx.begin(), 1024);
63 else if constexpr (std::is_fundamental_v<T>)
66 i = ranges::uninitialized_default_construct(rx.cbegin(), rx.cend());
68 i = ranges::uninitialized_default_construct(std::as_const(rx));
70 i = ranges::uninitialized_default_construct_n(rx.cbegin(), 1024);
74 VERIFY( i == rx.cend() );
75 VERIFY( ranges::find_if(rx, [&t](const T& v) { return t != v; }) == i );
83 static constexpr int limit = 67;
84 static inline int construct_count = 0;
85 static inline int destruct_count = 0;
93 if (construct_count >= limit)
107 template<bool test_sized>
111 constexpr int size = 100;
112 auto buffer = std::unique_ptr<char[]>(new char[sizeof(X)*size]);
113 test_forward_range<X> rx((X *)buffer.get(), (X *)buffer.get() + size);
116 X::construct_count = 0;
117 X::destruct_count = 0;
118 if constexpr (test_sized)
119 ranges::uninitialized_default_construct_n(rx.begin(), size);
121 ranges::uninitialized_default_construct(rx);
122 VERIFY( false && "exception not thrown" );
124 catch (const X::exception&)
126 VERIFY( X::construct_count == X::limit );
127 VERIFY( X::destruct_count == X::limit );
139 test01<std::vector<char>>();
140 test01<std::string>();
141 test01<std::deque<double>>();
142 test01<std::list<std::vector<std::deque<double>>>>();
143 test01<std::unique_ptr<std::string>>();