1 // Copyright (C) 2016-2017 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 } }
21 #ifndef _GLIBCXX_ASSERTIONS
22 // Make std::uniform_int_distribution check its parameters
23 # define _GLIBCXX_ASSERTIONS
29 #include <testsuite_hooks.h>
30 #include <testsuite_iterators.h>
35 using __gnu_test::test_container
;
36 using __gnu_test::output_iterator_wrapper
;
41 int pop
[UCHAR_MAX
] = { };
42 for (int i
= SCHAR_MAX
; i
< UCHAR_MAX
; ++i
)
44 const signed char sample_size
= SCHAR_MAX
; // PR libstdc++/77994
45 int out
[sample_size
] = { };
47 // random access iterators for both population and result
48 // (uses reservoir sampling)
49 auto it
= sample(std::begin(pop
), std::end(pop
), out
, sample_size
, rng
);
50 auto sum
= std::accumulate(out
, it
, 0);
51 VERIFY( sum
!= 0 ); // exceedingly unlikely!
53 // random access iterator for population and output iterator for result
54 // (uses selection sampling)
55 test_container
<int, output_iterator_wrapper
> samp2(out
);
56 sample(std::begin(pop
), std::end(pop
), samp2
.begin(), sample_size
, rng
);
57 sum
= std::accumulate(std::begin(out
), std::end(out
), 0);