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