]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/specialized_algorithms/uninitialized_fill_n/sizes.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / specialized_algorithms / uninitialized_fill_n / sizes.cc
CommitLineData
a945c346 1// Copyright (C) 2020-2024 Free Software Foundation, Inc.
c9dce3b1
JW
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// { dg-do run }
19
20#include <memory>
21#include <testsuite_hooks.h>
22
23void
24test01()
25{
26 int i[4] = { };
27 std::uninitialized_fill_n(i, 2.0001, 0xabcd);
28 VERIFY( i[0] == 0xabcd );
29 VERIFY( i[1] == 0xabcd );
30 VERIFY( i[2] == 0xabcd );
31 VERIFY( i[3] == 0 );
32}
33
f07fa7a3
JW
34// The standard only requires that n>0 and --n are valid expressions.
35struct Size
c9dce3b1 36{
f07fa7a3 37 int value;
c9dce3b1 38
f07fa7a3 39 void operator--() { --value; }
c9dce3b1 40
f07fa7a3
JW
41 int operator>(void*) { return value != 0; }
42};
c9dce3b1 43
f07fa7a3
JW
44void
45test02()
46{
c9dce3b1
JW
47 int i[5] = { };
48 Size n = {4};
49 std::uninitialized_fill_n(i, n, 0xdcba);
50 VERIFY( i[0] == 0xdcba );
51 VERIFY( i[1] == 0xdcba );
52 VERIFY( i[2] == 0xdcba );
53 VERIFY( i[3] == 0xdcba );
54 VERIFY( i[4] == 0 );
55}
56
57int
58main()
59{
60 test01();
61 test02();
62}