]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_fill_n/dr1339.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / specialized_algorithms / uninitialized_fill_n / dr1339.cc
1 // Copyright (C) 2014-2020 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 #include <memory>
19 #include <testsuite_hooks.h>
20
21 // test specialization for trivial types
22 void
23 test01()
24 {
25 const int N = 10;
26 int arr[N] = { };
27 const int n = 5;
28 const int over9000 = 9001;
29 int* end = std::uninitialized_fill_n(arr, n, over9000);
30 VERIFY( end = arr + n );
31 for (int i = 0; i < n; ++i)
32 VERIFY( arr[i] == over9000 );
33 for (int i = n; i < N; ++i)
34 VERIFY( arr[i] == 0 );
35 }
36
37 struct T
38 {
39 T() { }
40 T(const T&) { ++counter; }
41 static int counter;
42 };
43
44 int T::counter;
45
46 // test non-trivial
47 void
48 test02()
49 {
50 const int n = 5;
51 char* mem = new char[sizeof(T)*n];
52 T* p = reinterpret_cast<T*>(mem);
53 T* end = std::uninitialized_fill_n(p, n, T());
54 VERIFY( end = p + n );
55 VERIFY( T::counter == n );
56 delete[] mem;
57 }
58
59 int
60 main()
61 {
62 test01();
63 test02();
64 }