Home | History | Annotate | Download | only in alg.random.sample
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // UNSUPPORTED: c++98, c++03, c++11, c++14
     11 
     12 // <algorithm>
     13 
     14 // template <class PopulationIterator, class SampleIterator, class Distance,
     15 //           class UniformRandomNumberGenerator>
     16 // SampleIterator sample(PopulationIterator first, PopulationIterator last,
     17 //                       SampleIterator out, Distance n,
     18 //                       UniformRandomNumberGenerator &&g);
     19 
     20 #include <algorithm>
     21 #include <random>
     22 #include <cassert>
     23 
     24 #include "test_iterators.h"
     25 
     26 template <class PopulationIterator, class SampleIterator> void test() {
     27   int ia[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
     28   const unsigned is = sizeof(ia) / sizeof(ia[0]);
     29   const unsigned os = 4;
     30   int oa[os];
     31   std::minstd_rand g;
     32   std::sample(PopulationIterator(ia), PopulationIterator(ia + is),
     33                             SampleIterator(oa), os, g);
     34 }
     35 
     36 int main() {
     37   // expected-error@algorithm:* {{static_assert failed "SampleIterator must meet the requirements of RandomAccessIterator"}}
     38   // expected-error@algorithm:* 2 {{does not provide a subscript operator}}
     39   // expected-error@algorithm:* {{invalid operands}}
     40   test<input_iterator<int *>, output_iterator<int *> >();
     41 }
     42