Evgeniy Stepanov 56a8c6438a Implement std::experimental::sample.
Following specification in "C++ Extensions for Library Fundamentals":
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4480.html#alg.random.sample



git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@237264 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-13 16:55:41 +00:00

37 lines
1.2 KiB
C++

//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <algorithm>
// template <class PopulationIterator, class SampleIterator, class Distance,
// class UniformRandomNumberGenerator>
// SampleIterator sample(PopulationIterator first, PopulationIterator last,
// SampleIterator out, Distance n,
// UniformRandomNumberGenerator &&g);
#include <experimental/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::experimental::sample(PopulationIterator(ia), PopulationIterator(ia + is),
SampleIterator(oa), os, g);
}
int main() {
test<input_iterator<int *>, output_iterator<int *> >();
}