diff options
author | Eric Fiselier <eric@efcs.ca> | 2016-08-28 22:14:37 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2016-08-28 22:14:37 +0000 |
commit | e7154709e02a388db2d8dce91860f2452f4145e0 (patch) | |
tree | d7cd66939217540b5b74d9a8484da38ed3179f42 /libcxx/test/std/algorithms/alg.modifying.operations/alg.random.sample/sample.fail.cpp | |
parent | 040411762fde039dcd1a7f513d95d01266bfa94d (diff) | |
download | bcm5719-llvm-e7154709e02a388db2d8dce91860f2452f4145e0.tar.gz bcm5719-llvm-e7154709e02a388db2d8dce91860f2452f4145e0.zip |
Implement C++17 std::sample.
This patch implements the std::sample function added to C++17 from LFTS. It
also removes the std::experimental::sample implementation which now forwards
to std::sample.
llvm-svn: 279948
Diffstat (limited to 'libcxx/test/std/algorithms/alg.modifying.operations/alg.random.sample/sample.fail.cpp')
-rw-r--r-- | libcxx/test/std/algorithms/alg.modifying.operations/alg.random.sample/sample.fail.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.sample/sample.fail.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.sample/sample.fail.cpp new file mode 100644 index 00000000000..d769ad850c3 --- /dev/null +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.sample/sample.fail.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <algorithm> + +// template <class PopulationIterator, class SampleIterator, class Distance, +// class UniformRandomNumberGenerator> +// SampleIterator sample(PopulationIterator first, PopulationIterator last, +// SampleIterator out, Distance n, +// UniformRandomNumberGenerator &&g); + +#include <algorithm> +#include <random> +#include <cassert> + +#include "test_iterators.h" + +template <class PopulationIterator, class SampleIterator> void test() { + int ia[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + const unsigned is = sizeof(ia) / sizeof(ia[0]); + const unsigned os = 4; + int oa[os]; + std::minstd_rand g; + std::sample(PopulationIterator(ia), PopulationIterator(ia + is), + SampleIterator(oa), os, g); +} + +int main() { + // expected-error@algorithm:* {{static_assert failed "SampleIterator must meet the requirements of RandomAccessIterator"}} + // expected-error@algorithm:* 2 {{does not provide a subscript operator}} + // expected-error@algorithm:* {{invalid operands}} + test<input_iterator<int *>, output_iterator<int *> >(); +} |