annotate libstdc++-v3/testsuite/25_algorithms/copy_backward/94013.cc @ 19:2b5abeee2509 default tip

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
1 // Copyright (C) 2020 Free Software Foundation, Inc.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
2 //
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
3 // This file is part of the GNU ISO C++ Library. This library is free
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
4 // software; you can redistribute it and/or modify it under the
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
5 // terms of the GNU General Public License as published by the
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
6 // Free Software Foundation; either version 3, or (at your option)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
7 // any later version.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
8
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
9 // This library is distributed in the hope that it will be useful,
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
12 // GNU General Public License for more details.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
13
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
14 // You should have received a copy of the GNU General Public License along
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
15 // with this library; see the file COPYING3. If not see
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
16 // <http://www.gnu.org/licenses/>.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
17
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
18 // { dg-do run }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
19
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
20 #include <algorithm>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
21 #include <testsuite_hooks.h>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
22
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
23 void
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
24 test01()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
25 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
26 volatile int i[2] = { 1, 2 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
27 volatile int j[2] = { 0, 0 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
28 int k[2] = { 0, 0 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
29
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
30 std::copy_backward(i, i+2, j+2);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
31 VERIFY( j[0] == 1 && j[1] == 2 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
32 std::copy_backward(i, i+2, k+2);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
33 VERIFY( k[0] == 1 && k[1] == 2 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
34 std::copy_backward(k+1, k+2, i+1);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
35 VERIFY( i[0] == 2 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
36
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
37 const volatile int* cj = j;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
38 std::copy_backward(cj, cj+2, i+2);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
39 VERIFY( i[0] == 1 && i[1] == 2 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
40 std::copy_backward(cj+1, cj+2, k+1);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
41 VERIFY( k[0] == 2 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
42 const int* ck = k;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
43 std::copy_backward(ck, ck+2, i+2);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
44 VERIFY( i[0] == 2 && i[1] == 2 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
45 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
46
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
47 void
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
48 test02()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
49 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
50 #if __cplusplus > 201703L
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
51 volatile int i[2] = { 1, 2 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
52 volatile int j[2] = { 0, 0 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
53 int k[2] = { 0, 0 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
54
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
55 std::ranges::copy_backward(i, i+2, j+2);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
56 VERIFY( j[0] == 1 && j[1] == 2 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
57 std::ranges::copy_backward(i, i+2, k+2);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
58 VERIFY( k[0] == 1 && k[1] == 2 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
59 std::ranges::copy_backward(k+1, k+2, i+1);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
60 VERIFY( i[0] == 2 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
61
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
62 const volatile int* cj = j;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
63 std::ranges::copy_backward(cj, cj+2, i+2);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
64 VERIFY( i[0] == 1 && i[1] == 2 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
65 std::ranges::copy_backward(cj+1, cj+2, k+1);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
66 VERIFY( k[0] == 2 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
67 const int* ck = k;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
68 std::ranges::copy_backward(ck, ck+2, i+2);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
69 VERIFY( i[0] == 2 && i[1] == 2 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
70 #endif
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
71 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
72
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
73 int
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
74 main()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
75 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
76 test01();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
77 test02();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
78 }