annotate libstdc++-v3/testsuite/25_algorithms/shift_right/1.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-options "-std=gnu++2a" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
19 // { dg-do run { target c++2a } }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
20
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
21 #include <algorithm>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
22 #include <testsuite_hooks.h>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
23 #include <testsuite_iterators.h>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
24
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
25 using __gnu_test::test_container;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
26 using __gnu_test::forward_iterator_wrapper;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
27 using __gnu_test::bidirectional_iterator_wrapper;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
28 using __gnu_test::random_access_iterator_wrapper;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
29
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
30 struct X
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
31 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
32 int a = -1;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
33 bool moved_from = false;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
34
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
35 X() = default;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
36
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
37 X(int a)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
38 : a(a)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
39 { }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
40
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
41 X(const X&) = delete;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
42 X& operator=(const X&) = delete;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
43
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
44 X(X&& other)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
45 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
46 if (this != &other)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
47 *this = std::move(other);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
48 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
49
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
50 X&
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
51 operator=(X&& other)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
52 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
53 a = other.a;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
54 other.moved_from = true;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
55 moved_from = false;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
56 return *this;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
57 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
58 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
59
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
60 template<int N, template<typename> typename Wrapper>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
61 void
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
62 test01()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
63 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
64 for (int n = 0; n < N+5; n++)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
65 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
66 X x[N];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
67 for (int i = 0; i < N; i++)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
68 x[i] = X(i);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
69 test_container<X, Wrapper> cx(x);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
70 auto out = std::shift_right(cx.begin(), cx.end(), n);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
71 if (n < N)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
72 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
73 VERIFY( out.ptr == x+n );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
74 for (int i = n; i < N; i++)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
75 VERIFY( x[i].a == i-n );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
76 for (int i = 0; i < std::min(n, N-n); i++)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
77 VERIFY( x[i].moved_from );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
78 for (int i = std::min(n, N-n); i < std::max(n, N-n); i++)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
79 VERIFY( !x[i].moved_from );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
80 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
81 else
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
82 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
83 VERIFY( out.ptr == x+N );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
84 for (int i = 0; i < N; i++)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
85 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
86 VERIFY( x[i].a == i );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
87 VERIFY( !x[i].moved_from );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
88 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
89 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
90 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
91 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
92
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
93 int
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
94 main()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
95 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
96 test01<23, forward_iterator_wrapper>();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
97 test01<23, bidirectional_iterator_wrapper>();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
98 test01<23, random_access_iterator_wrapper>();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
99
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
100 test01<24, forward_iterator_wrapper>();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
101 test01<24, bidirectional_iterator_wrapper>();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
102 test01<24, random_access_iterator_wrapper>();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
103 }