]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_fill/constrained.cc
1 // Copyright (C) 2020-2021 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
;
38 test01(const T
& value
)
40 static_assert(std::equality_comparable
<T
>);
42 for (int k
= 0; k
< 6; k
++)
44 constexpr int size
= 1024;
45 auto buffer
= std::unique_ptr
<char[]>(new char[sizeof(T
)*size
]);
46 std::span
<T
> rx((T
*)buffer
.get(), size
);
50 i
= ranges::uninitialized_fill(rx
.begin(), rx
.end(), value
);
52 i
= ranges::uninitialized_fill(rx
, value
);
54 i
= ranges::uninitialized_fill_n(rx
.begin(), 1024, value
);
56 i
= ranges::uninitialized_fill(rx
.begin(), rx
.end(), value
);
58 i
= ranges::uninitialized_fill(std::as_const(rx
), value
);
60 i
= ranges::uninitialized_fill_n(rx
.begin(), 1024, value
);
64 VERIFY( i
== rx
.end() );
65 VERIFY( ranges::find_if(rx
, [&value
](const T
& v
) { return value
!= v
; }) == i
);
73 static constexpr int limit
= 67;
74 static inline int construct_count
= 0;
75 static inline int destruct_count
= 0;
83 if (construct_count
>= limit
)
97 template<bool test_sized
>
101 constexpr int size
= 100;
102 auto buffer
= std::unique_ptr
<char[]>(new char[sizeof(X
)*size
]);
103 test_forward_range
<X
> rx((X
*)buffer
.get(), (X
*)buffer
.get() + size
);
107 X::construct_count
= 0;
108 X::destruct_count
= 0;
109 if constexpr (test_sized
)
110 ranges::uninitialized_fill_n(rx
.begin(), size
, value
);
112 ranges::uninitialized_fill(rx
, value
);
113 VERIFY( false && "exception not thrown" );
115 catch (const X::exception
&)
117 VERIFY( X::construct_count
== X::limit
);
118 VERIFY( X::destruct_count
== X::limit
);
127 test01
<long long>(17);
129 test01
<double>(3.98);
130 test01
<std::vector
<char>>({'a', 'b', 'c', 'd'});
131 test01
<std::string
>("hello");
132 test01
<std::deque
<double>>({1.1,2.1,3.1});
133 test01
<std::list
<std::vector
<std::deque
<double>>>>({{{3.4},{1}},{{7.9}}});