]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/25_algorithms/rotate_copy/constrained.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / rotate_copy / constrained.cc
CommitLineData
99dee823 1// Copyright (C) 2020-2021 Free Software Foundation, Inc.
bc464641
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::test_range;
27using __gnu_test::forward_iterator_wrapper;
28using __gnu_test::random_access_iterator_wrapper;
29
30namespace ranges = std::ranges;
31
32struct X
33{
34 int i;
35 X () : i(0) { }
36 X (int a) : i(a) { }
37
38 friend bool
39 operator==(const X& lhs, const X& rhs)
40 {
41 return lhs.i == rhs.i;
42 }
43};
44
45static_assert(!std::is_trivial_v<X>);
46
47template<template<typename, template<typename> typename> typename container,
48 template<typename> typename wrapper,
49 typename T = int>
50void
51test01()
52{
53 for (int a = 0; a <= 7; a++)
54 {
55 T x[] = {1, 2, 3, 4, 5, 6, 7};
56 T w[7];
57 container<T, wrapper> rx(x), rw(w);
58 auto i = ranges::begin(rx);
59 std::advance(i, a);
60 auto [in,out] = ranges::rotate_copy(rx, i, ranges::begin(rw));
61 VERIFY( in == ranges::end(rx) );
62 VERIFY( out == ranges::end(rw) );
63 for (int k = 0; k < 7; k++)
64 VERIFY( w[k] == (k+a)%7 + 1 );
65 }
66}
67
68constexpr bool
69test02()
70{
71 const int x[] = {1, 2, 3, 4};
72 int w[3];
73 const int y[] = { 2, 3, 1};
74 auto [in,out] = ranges::rotate_copy(x, x+1, x+3, w);
75 return (in == x+3
76 && out == w+3
77 && ranges::equal(w, y));
78}
79
80int
81main()
82{
83 test01<test_container, forward_iterator_wrapper>();
84 test01<test_range, forward_iterator_wrapper>();
85
86 test01<test_container, random_access_iterator_wrapper>();
87 test01<test_range, random_access_iterator_wrapper>();
88
89 test01<test_container, random_access_iterator_wrapper, X>();
90 test01<test_range, random_access_iterator_wrapper, X>();
91
92 static_assert(test02());
93}