1 // Copyright (C) 2020-2024 Free Software Foundation, Inc.
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)
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-do run { target c++20 } }
19 // { dg-require-cstdint "" }
23 #include <testsuite_hooks.h>
24 #include <testsuite_iterators.h>
26 using __gnu_test::test_range
;
27 using __gnu_test::forward_iterator_wrapper
;
28 using __gnu_test::input_iterator_wrapper
;
29 using __gnu_test::output_iterator_wrapper
;
30 using __gnu_test::random_access_iterator_wrapper
;
32 namespace ranges
= std::ranges
;
36 template<template<typename
> typename in_wrapper
,
37 template<typename
> typename out_wrapper
>
41 const int x
[] = {1,2,3,4,5,6,7,8,9,10};
42 test_range
<const int, in_wrapper
> rx(x
);
44 test_range
<int, out_wrapper
> ry(y
);
45 auto out
= ranges::sample(rx
.begin(), rx
.end(), ry
.begin(), 20, rng
);
46 VERIFY( out
.ptr
== y
+10 );
47 VERIFY( ranges::equal(x
, y
) );
49 for (int i
= 0; i
< 100; i
++)
52 test_range
<int, out_wrapper
> rz(z
);
54 auto out
= ranges::sample(rx
, rz
.begin(), 5, rng
);
55 VERIFY( out
.ptr
== z
+5 );
57 VERIFY( ranges::adjacent_find(z
) == out
.ptr
);
58 VERIFY( ranges::includes(x
, z
) );
65 test01
<forward_iterator_wrapper
, output_iterator_wrapper
>();
66 test01
<input_iterator_wrapper
, random_access_iterator_wrapper
>();