Mark LWG 2716 as complete - shuffle and sample disallows lvalue URNGs.

Libc++'s implementation of shuffle and sample already support lvalue and rvalue
RNG's. This patch adds tests for both categories and marks the issue as complete.

This patch also contains drive-by change for std::experimental::sample which
improves the diagnostics produced when the correct iterator categories are
not supplied.


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@279947 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier 2016-08-28 21:55:00 +00:00
parent 113315b9a4
commit 17c38db650
6 changed files with 19 additions and 13 deletions

View File

@ -107,6 +107,9 @@ _SampleIterator sample(_PopulationIterator __first,
_PopCategory;
typedef typename iterator_traits<_PopulationIterator>::difference_type
_Difference;
static_assert(__is_forward_iterator<_PopulationIterator>::value ||
__is_random_access_iterator<_SampleIterator>::value,
"SampleIterator must meet the requirements of RandomAccessIterator");
typedef typename common_type<_Distance, _Difference>::type _CommonType;
_LIBCPP_ASSERT(__n >= 0, "N must be a positive number.");
return _VSTD_LFTS::__sample(

View File

@ -42,7 +42,7 @@ class my_input_iterator
{
It it_;
template <class U> friend class input_iterator;
template <class U> friend class my_input_iterator;
public:
typedef my_input_iterator_tag iterator_category;
typedef typename std::iterator_traits<It>::value_type value_type;
@ -55,7 +55,7 @@ public:
my_input_iterator() : it_() {}
explicit my_input_iterator(It it) : it_(it) {}
template <class U>
my_input_iterator(const input_iterator<U>& u) :it_(u.it_) {}
my_input_iterator(const my_input_iterator<U>& u) :it_(u.it_) {}
reference operator*() const {return *it_;}
pointer operator->() const {return it_;}

View File

@ -29,7 +29,7 @@ int main()
std::shuffle(ia, ia+sa, g);
LIBCPP_ASSERT(std::equal(ia, ia+sa, ia1));
assert(std::is_permutation(ia, ia+sa, ia1));
std::shuffle(ia, ia+sa, g);
std::shuffle(ia, ia+sa, std::move(g));
LIBCPP_ASSERT(std::equal(ia, ia+sa, ia2));
assert(std::is_permutation(ia, ia+sa, ia2));
}

View File

@ -32,5 +32,8 @@ template <class PopulationIterator, class SampleIterator> void test() {
}
int main() {
// expected-error@experimental/algorithm:* {{static_assert failed "SampleIterator must meet the requirements of RandomAccessIterator"}}
// expected-error@experimental/algorithm:* 2 {{does not provide a subscript operator}}
// expected-error@experimental/algorithm:* {{invalid operands}}
test<input_iterator<int *>, output_iterator<int *> >();
}

View File

@ -46,8 +46,8 @@ template <>
struct TestExpectations<std::input_iterator_tag>
: public ReservoirSampleExpectations {};
template <template<class> class PopulationIteratorType, class PopulationItem,
template<class> class SampleIteratorType, class SampleItem>
template <template<class...> class PopulationIteratorType, class PopulationItem,
template<class...> class SampleIteratorType, class SampleItem>
void test() {
typedef PopulationIteratorType<PopulationItem *> PopulationIterator;
typedef SampleIteratorType<SampleItem *> SampleIterator;
@ -68,13 +68,13 @@ void test() {
assert(std::equal(oa, oa + os, oa1));
end = std::experimental::sample(PopulationIterator(ia),
PopulationIterator(ia + is),
SampleIterator(oa), os, g);
SampleIterator(oa), os, std::move(g));
assert(end.base() - oa == std::min(os, is));
assert(std::equal(oa, oa + os, oa2));
}
template <template<class> class PopulationIteratorType, class PopulationItem,
template<class> class SampleIteratorType, class SampleItem>
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;
@ -88,8 +88,8 @@ void test_empty_population() {
assert(end.base() == oa);
}
template <template<class> class PopulationIteratorType, class PopulationItem,
template<class> class SampleIteratorType, class SampleItem>
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;
@ -103,8 +103,8 @@ void test_empty_sample() {
assert(end.base() == oa);
}
template <template<class> class PopulationIteratorType, class PopulationItem,
template<class> class SampleIteratorType, class SampleItem>
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;

View File

@ -299,7 +299,7 @@
<tr><td><a href="http://wg21.link/LWG2709">2709</a></td><td>offsetof is unnecessarily imprecise</td><td>Oulu</td><td></td></tr>
<tr><td><a href="http://wg21.link/LWG2710">2710</a></td><td>"Effects: Equivalent to ..." doesn't count "Synchronization:" as determined semantics</td><td>Oulu</td><td>Complete</td></tr>
<tr><td><a href="http://wg21.link/LWG2711">2711</a></td><td>path is convertible from approximately everything under the sun</td><td>Oulu</td><td>Complete</td></tr>
<tr><td><a href="http://wg21.link/LWG2716">2716</a></td><td>Specification of shuffle and sample disallows lvalue URNGs</td><td>Oulu</td><td></td></tr>
<tr><td><a href="http://wg21.link/LWG2716">2716</a></td><td>Specification of shuffle and sample disallows lvalue URNGs</td><td>Oulu</td><td>Complete</td></tr>
<tr><td><a href="http://wg21.link/LWG2718">2718</a></td><td>Parallelism bug in [algorithms.parallel.exec] p2</td><td>Oulu</td><td></td></tr>
<tr><td><a href="http://wg21.link/LWG2719">2719</a></td><td>permissions function should not be noexcept due to narrow contract</td><td>Oulu</td><td>Complete</td></tr>
<tr><td><a href="http://wg21.link/LWG2720">2720</a></td><td>permissions function incorrectly specified for symlinks</td><td>Oulu</td><td>Complete</td></tr>