Improve atomic store implementation on hppa-linux.
[official-gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / unique_copy / constrained.cc
blob896a584a7ae974d2e481e212c53609b8bb802993
1 // Copyright (C) 2020-2021 Free Software Foundation, Inc.
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.
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.
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/>.
18 // { dg-options "-std=gnu++2a" }
19 // { dg-do run { target c++2a } }
21 #include <algorithm>
22 #include <testsuite_hooks.h>
23 #include <testsuite_iterators.h>
25 using __gnu_test::test_range;
26 using __gnu_test::input_iterator_wrapper;
27 using __gnu_test::output_iterator_wrapper;
28 using __gnu_test::forward_iterator_wrapper;
30 namespace ranges = std::ranges;
32 template<template<typename> typename source_wrapper,
33 template<typename> typename dest_wrapper>
34 void
35 test01()
37 int x[6] = {0, 0, 0, 1, 1, 1};
38 int y[2];
39 const int z[2] = {0, 1};
41 test_range<int, source_wrapper> rx(x);
42 test_range<int, dest_wrapper> ry(y);
43 auto [in,out] = ranges::unique_copy(rx, ry.begin());
44 VERIFY( in == ranges::end(rx) && out == ranges::end(ry) );
45 VERIFY( ranges::equal(y, z) );
48 template<template<typename> typename source_wrapper,
49 template<typename> typename dest_wrapper>
50 void
51 test02()
53 int x[6] = {0, 0, 0, 1, 1, 1};
54 int y[2] = {0, 0};
55 const int z[2] = {0, 0};
57 test_range<int, source_wrapper> rx(x, x);
58 test_range<int, dest_wrapper> ry(y, y);
59 auto [in, out] = ranges::unique_copy(rx.begin(), rx.end(), ry.begin());
60 VERIFY( in.ptr == x && out.ptr == y );
61 VERIFY( ranges::equal(y, z) );
64 template<template<typename> typename source_wrapper,
65 template<typename> typename dest_wrapper>
66 void
67 test03()
69 struct X { int i; };
70 X x[6] = { {1}, {2}, {2}, {4}, {4}, {6} };
71 X y[4] = { {1}, {2}, {4}, {6} };
72 const X z[4] = { {1}, {2}, {4}, {6} };
74 test_range<X, source_wrapper> rx(x);
75 test_range<X, dest_wrapper> ry(y);
76 auto [in, out]
77 = ranges::unique_copy(rx, ry.begin(), ranges::equal_to{}, &X::i);
78 VERIFY( in == ranges::end(rx) && out == ranges::end(ry) );
79 VERIFY( ranges::equal(y, z, {}, &X::i, &X::i) );
82 constexpr bool
83 test04()
85 struct X { int i; };
86 X x[7] = { {1}, {2}, {2}, {2}, {4}, {4}, {6} };
87 X y[4] = { {1}, {2}, {4}, {6} };
88 const X z[4] = { {1}, {2}, {4}, {6} };
90 auto [in, out]
91 = ranges::unique_copy(x, x+7, y, ranges::equal_to{}, &X::i);
92 return (in == ranges::end(x)
93 && out == ranges::end(y)
94 && ranges::equal(y, z, {}, &X::i, &X::i));
97 int
98 main()
100 test01<input_iterator_wrapper, output_iterator_wrapper>();
101 test01<input_iterator_wrapper, forward_iterator_wrapper>();
102 test01<forward_iterator_wrapper, output_iterator_wrapper>();
104 test02<input_iterator_wrapper, output_iterator_wrapper>();
105 test02<input_iterator_wrapper, forward_iterator_wrapper>();
106 test02<forward_iterator_wrapper, output_iterator_wrapper>();
108 test03<input_iterator_wrapper, output_iterator_wrapper>();
109 test03<input_iterator_wrapper, forward_iterator_wrapper>();
110 test03<forward_iterator_wrapper, output_iterator_wrapper>();
112 static_assert(test04());