1 // Copyright (C) 2016-2018 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-options "-std=gnu++17" }
19 // { dg-do run { target c++17 } }
20 // { dg-require-cstdint "" }
22 #ifndef _GLIBCXX_ASSERTIONS
23 // Make std::uniform_int_distribution check its parameters
24 # define _GLIBCXX_ASSERTIONS
30 #include <testsuite_hooks.h>
31 #include <testsuite_iterators.h>
36 using __gnu_test::test_container
;
37 using __gnu_test::output_iterator_wrapper
;
42 int pop
[UCHAR_MAX
] = { };
43 for (int i
= SCHAR_MAX
; i
< UCHAR_MAX
; ++i
)
45 const signed char sample_size
= SCHAR_MAX
; // PR libstdc++/77994
46 int out
[sample_size
] = { };
48 // random access iterators for both population and result
49 // (uses reservoir sampling)
50 auto it
= sample(std::begin(pop
), std::end(pop
), out
, sample_size
, rng
);
51 auto sum
= std::accumulate(out
, it
, 0);
52 VERIFY( sum
!= 0 ); // exceedingly unlikely!
54 // random access iterator for population and output iterator for result
55 // (uses selection sampling)
56 test_container
<int, output_iterator_wrapper
> samp2(out
);
57 sample(std::begin(pop
), std::end(pop
), samp2
.begin(), sample_size
, rng
);
58 sum
= std::accumulate(std::begin(out
), std::end(out
), 0);