]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/testsuite/experimental/algorithm/sample.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / algorithm / sample.cc
index 543a6efc461b0dc3805e6e84c0f202290b0e6737..6eff581afead185e8a259dc19d5499b0e281cfcd 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2018 Free Software Foundation, Inc.
+// Copyright (C) 2014-2024 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
 // <http://www.gnu.org/licenses/>.
 
 // { dg-do run { target c++14 } }
+// { dg-require-cstdint "" }
 
 #include <experimental/algorithm>
-#include <iterator>
-#include <sstream>
-#include <forward_list>
-#include <vector>
 #include <random>
-#include <algorithm>
 #include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
 
-std::mt19937 rng;
+using __gnu_test::test_container;
+using __gnu_test::input_iterator_wrapper;
+using __gnu_test::output_iterator_wrapper;
+using __gnu_test::forward_iterator_wrapper;
 
-using std::istream_iterator;
-using std::ostream_iterator;
+std::mt19937 rng;
 
 void
 test01()
@@ -60,11 +59,12 @@ test02()
 void
 test03()
 {
-  std::istringstream pop("0 1 2 3 4 5 6 7 8 9");
+  const int pop[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, };
   int samp[5] = { };
 
   // input iterator for population
-  auto it = std::experimental::sample(istream_iterator<int>{pop}, {},
+  test_container<const int, input_iterator_wrapper> pop_in{pop};
+  auto it = std::experimental::sample(pop_in.begin(), pop_in.end(),
                                       samp,
                                       5, rng);
   VERIFY( it == samp + 5 );
@@ -77,21 +77,20 @@ test03()
 void
 test04()
 {
-  std::forward_list<int> pop{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-  std::stringstream samp;
+  const int pop[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+  int samp[5] = { };
 
   // forward iterator for population and output iterator for result
-  std::experimental::sample(pop.begin(), pop.end(),
-                            ostream_iterator<int>{samp, " "},
-                            5, rng);
+  test_container<const int, forward_iterator_wrapper> pop_fwd{pop};
+  test_container<int, output_iterator_wrapper> samp_out{samp};
+  auto it = std::experimental::sample(pop_fwd.begin(), pop_fwd.end(),
+                                     samp_out.begin(), 5, rng);
 
-  // samp.rdbuf()->pubseekoff(0, std::ios::beg);
-  std::vector<int> v(istream_iterator<int>{samp}, {});
-  VERIFY( v.size() == 5 );
+  VERIFY( std::distance(samp, it.ptr) == 5 );
 
-  std::sort(v.begin(), v.end());
-  auto it = std::unique(v.begin(), v.end());
-  VERIFY( it == v.end() );
+  std::sort(samp, it.ptr);
+  auto it2 = std::unique(samp, it.ptr);
+  VERIFY( it2 == it.ptr );
 }
 
 int