sample.fail.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // UNSUPPORTED: c++98, c++03, c++11, c++14
  9. // <algorithm>
  10. // template <class PopulationIterator, class SampleIterator, class Distance,
  11. // class UniformRandomNumberGenerator>
  12. // SampleIterator sample(PopulationIterator first, PopulationIterator last,
  13. // SampleIterator out, Distance n,
  14. // UniformRandomNumberGenerator &&g);
  15. #include <algorithm>
  16. #include <random>
  17. #include <cassert>
  18. #include "test_iterators.h"
  19. template <class PopulationIterator, class SampleIterator> void test() {
  20. int ia[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  21. const unsigned is = sizeof(ia) / sizeof(ia[0]);
  22. const unsigned os = 4;
  23. int oa[os];
  24. std::minstd_rand g;
  25. std::sample(PopulationIterator(ia), PopulationIterator(ia + is),
  26. SampleIterator(oa), os, g);
  27. }
  28. int main(int, char**) {
  29. // expected-error-re@algorithm:* {{static_assert failed{{( due to requirement '.*')?}} "SampleIterator must meet the requirements of RandomAccessIterator"}}
  30. // expected-error@algorithm:* 2 {{does not provide a subscript operator}}
  31. // expected-error@algorithm:* {{invalid operands}}
  32. test<input_iterator<int *>, output_iterator<int *> >();
  33. return 0;
  34. }