Remove std::experimental::sample; use std::sample instead. See https://libcxx.llvm.org/TS_deprecation.html

llvm-svn: 323979
This commit is contained in:
Marshall Clow 2018-02-01 16:36:08 +00:00
parent 57e9f44a8c
commit 14082fcc42
4 changed files with 2 additions and 259 deletions

View File

@ -23,11 +23,8 @@ inline namespace fundamentals_v1 {
template <class ForwardIterator, class Searcher>
ForwardIterator search(ForwardIterator first, ForwardIterator last,
const Searcher &searcher);
template <class PopulationIterator, class SampleIterator, class Distance,
class UniformRandomNumberGenerator>
SampleIterator sample(PopulationIterator first, PopulationIterator last,
SampleIterator out, Distance n,
UniformRandomNumberGenerator &&g);
// sample removed because it's now part of C++17
} // namespace fundamentals_v1
} // namespace experimental
@ -56,16 +53,6 @@ _LIBCPP_INLINE_VISIBILITY
_ForwardIterator search(_ForwardIterator __f, _ForwardIterator __l, const _Searcher &__s)
{ return __s(__f, __l).first; }
template <class _PopulationIterator, class _SampleIterator, class _Distance,
class _UniformRandomNumberGenerator>
inline _LIBCPP_INLINE_VISIBILITY
_SampleIterator sample(_PopulationIterator __first, _PopulationIterator __last,
_SampleIterator __output_iter, _Distance __n,
_UniformRandomNumberGenerator &&__g) {
return _VSTD::__sample(__first, __last, __output_iter, __n, __g);
}
_LIBCPP_END_NAMESPACE_LFTS
_LIBCPP_POP_MACROS

View File

@ -1,41 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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
// <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() {
// 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 *> >();
}

View File

@ -1,150 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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"
struct ReservoirSampleExpectations {
enum { os = 4 };
static int oa1[os];
static int oa2[os];
};
int ReservoirSampleExpectations::oa1[] = {10, 5, 9, 4};
int ReservoirSampleExpectations::oa2[] = {5, 2, 10, 4};
struct SelectionSampleExpectations {
enum { os = 4 };
static int oa1[os];
static int oa2[os];
};
int SelectionSampleExpectations::oa1[] = {1, 4, 6, 7};
int SelectionSampleExpectations::oa2[] = {1, 2, 6, 8};
template <class IteratorCategory> struct TestExpectations
: public SelectionSampleExpectations {};
template <>
struct TestExpectations<std::input_iterator_tag>
: public ReservoirSampleExpectations {};
template <template<class...> class PopulationIteratorType, class PopulationItem,
template<class...> class SampleIteratorType, class SampleItem>
void test() {
typedef PopulationIteratorType<PopulationItem *> PopulationIterator;
typedef SampleIteratorType<SampleItem *> SampleIterator;
PopulationItem ia[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
const unsigned is = sizeof(ia) / sizeof(ia[0]);
typedef TestExpectations<typename std::iterator_traits<
PopulationIterator>::iterator_category> Expectations;
const unsigned os = Expectations::os;
SampleItem oa[os];
const int *oa1 = Expectations::oa1;
((void)oa1); // Prevent unused warning
const int *oa2 = Expectations::oa2;
((void)oa2); // Prevent unused warning
std::minstd_rand g;
SampleIterator end;
end = std::experimental::sample(PopulationIterator(ia),
PopulationIterator(ia + is),
SampleIterator(oa), os, g);
assert(static_cast<std::size_t>(end.base() - oa) == std::min(os, is));
// sample() is deterministic but non-reproducible;
// its results can vary between implementations.
LIBCPP_ASSERT(std::equal(oa, oa + os, oa1));
end = std::experimental::sample(PopulationIterator(ia),
PopulationIterator(ia + is),
SampleIterator(oa), os, std::move(g));
assert(static_cast<std::size_t>(end.base() - oa) == std::min(os, is));
LIBCPP_ASSERT(std::equal(oa, oa + os, oa2));
}
template <template<class...> class PopulationIteratorType, class PopulationItem,
template<class...> class SampleIteratorType, class SampleItem>
void test_empty_population() {
typedef PopulationIteratorType<PopulationItem *> PopulationIterator;
typedef SampleIteratorType<SampleItem *> SampleIterator;
PopulationItem ia[] = {42};
const unsigned os = 4;
SampleItem oa[os];
std::minstd_rand g;
SampleIterator end =
std::experimental::sample(PopulationIterator(ia), PopulationIterator(ia),
SampleIterator(oa), os, g);
assert(end.base() == oa);
}
template <template<class...> class PopulationIteratorType, class PopulationItem,
template<class...> class SampleIteratorType, class SampleItem>
void test_empty_sample() {
typedef PopulationIteratorType<PopulationItem *> PopulationIterator;
typedef SampleIteratorType<SampleItem *> SampleIterator;
PopulationItem ia[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
const unsigned is = sizeof(ia) / sizeof(ia[0]);
SampleItem oa[1];
std::minstd_rand g;
SampleIterator end =
std::experimental::sample(PopulationIterator(ia), PopulationIterator(ia + is),
SampleIterator(oa), 0, g);
assert(end.base() == oa);
}
template <template<class...> class PopulationIteratorType, class PopulationItem,
template<class...> class SampleIteratorType, class SampleItem>
void test_small_population() {
// The population size is less than the sample size.
typedef PopulationIteratorType<PopulationItem *> PopulationIterator;
typedef SampleIteratorType<SampleItem *> SampleIterator;
PopulationItem ia[] = {1, 2, 3, 4, 5};
const unsigned is = sizeof(ia) / sizeof(ia[0]);
const unsigned os = 8;
SampleItem oa[os];
const SampleItem oa1[] = {1, 2, 3, 4, 5};
std::minstd_rand g;
SampleIterator end;
end = std::experimental::sample(PopulationIterator(ia),
PopulationIterator(ia + is),
SampleIterator(oa), os, g);
assert(static_cast<std::size_t>(end.base() - oa) == std::min(os, is));
assert(std::equal(oa, end.base(), oa1));
}
int main() {
test<input_iterator, int, random_access_iterator, int>();
test<forward_iterator, int, output_iterator, int>();
test<forward_iterator, int, random_access_iterator, int>();
test<input_iterator, int, random_access_iterator, double>();
test<forward_iterator, int, output_iterator, double>();
test<forward_iterator, int, random_access_iterator, double>();
test_empty_population<input_iterator, int, random_access_iterator, int>();
test_empty_population<forward_iterator, int, output_iterator, int>();
test_empty_population<forward_iterator, int, random_access_iterator, int>();
test_empty_sample<input_iterator, int, random_access_iterator, int>();
test_empty_sample<forward_iterator, int, output_iterator, int>();
test_empty_sample<forward_iterator, int, random_access_iterator, int>();
test_small_population<input_iterator, int, random_access_iterator, int>();
test_small_population<forward_iterator, int, output_iterator, int>();
test_small_population<forward_iterator, int, random_access_iterator, int>();
}

View File

@ -1,53 +0,0 @@
//===----------------------------------------------------------------------===//
//
// 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"
// Stable if and only if PopulationIterator meets the requirements of a
// ForwardIterator type.
template <class PopulationIterator, class SampleIterator>
void test_stability(bool expect_stable) {
const unsigned kPopulationSize = 100;
int ia[kPopulationSize];
for (unsigned i = 0; i < kPopulationSize; ++i)
ia[i] = i;
PopulationIterator first(ia);
PopulationIterator last(ia + kPopulationSize);
const unsigned kSampleSize = 20;
int oa[kPopulationSize];
SampleIterator out(oa);
std::minstd_rand g;
const int kIterations = 1000;
bool unstable = false;
for (int i = 0; i < kIterations; ++i) {
std::experimental::sample(first, last, out, kSampleSize, g);
unstable |= !std::is_sorted(oa, oa + kSampleSize);
}
assert(expect_stable == !unstable);
}
int main() {
test_stability<forward_iterator<int *>, output_iterator<int *> >(true);
test_stability<input_iterator<int *>, random_access_iterator<int *> >(false);
}