From: Eric Fiselier Date: Sun, 28 Aug 2016 21:55:00 +0000 (+0000) Subject: Mark LWG 2716 as complete - shuffle and sample disallows lvalue URNGs. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=040411762fde039dcd1a7f513d95d01266bfa94d;p=platform%2Fupstream%2Fllvm.git 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. llvm-svn: 279947 --- diff --git a/libcxx/include/experimental/algorithm b/libcxx/include/experimental/algorithm index 3902111..10eafbd 100644 --- a/libcxx/include/experimental/algorithm +++ b/libcxx/include/experimental/algorithm @@ -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( diff --git a/libcxx/test/libcxx/iterators/trivial_iterators.pass.cpp b/libcxx/test/libcxx/iterators/trivial_iterators.pass.cpp index 33c83025..c4b3aae 100644 --- a/libcxx/test/libcxx/iterators/trivial_iterators.pass.cpp +++ b/libcxx/test/libcxx/iterators/trivial_iterators.pass.cpp @@ -42,7 +42,7 @@ class my_input_iterator { It it_; - template friend class input_iterator; + template friend class my_input_iterator; public: typedef my_input_iterator_tag iterator_category; typedef typename std::iterator_traits::value_type value_type; @@ -55,7 +55,7 @@ public: my_input_iterator() : it_() {} explicit my_input_iterator(It it) : it_(it) {} template - my_input_iterator(const input_iterator& u) :it_(u.it_) {} + my_input_iterator(const my_input_iterator& u) :it_(u.it_) {} reference operator*() const {return *it_;} pointer operator->() const {return it_;} diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_urng.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_urng.pass.cpp index 0c35ed7..512acc3 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_urng.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_urng.pass.cpp @@ -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)); } diff --git a/libcxx/test/std/experimental/algorithms/alg.random.sample/sample.fail.cpp b/libcxx/test/std/experimental/algorithms/alg.random.sample/sample.fail.cpp index eeb4373..b27135a 100644 --- a/libcxx/test/std/experimental/algorithms/alg.random.sample/sample.fail.cpp +++ b/libcxx/test/std/experimental/algorithms/alg.random.sample/sample.fail.cpp @@ -32,5 +32,8 @@ template 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, output_iterator >(); } diff --git a/libcxx/test/std/experimental/algorithms/alg.random.sample/sample.pass.cpp b/libcxx/test/std/experimental/algorithms/alg.random.sample/sample.pass.cpp index 1a9f9b0..5317317 100644 --- a/libcxx/test/std/experimental/algorithms/alg.random.sample/sample.pass.cpp +++ b/libcxx/test/std/experimental/algorithms/alg.random.sample/sample.pass.cpp @@ -46,8 +46,8 @@ template <> struct TestExpectations : public ReservoirSampleExpectations {}; -template class PopulationIteratorType, class PopulationItem, - template class SampleIteratorType, class SampleItem> +template class PopulationIteratorType, class PopulationItem, + template class SampleIteratorType, class SampleItem> void test() { typedef PopulationIteratorType PopulationIterator; typedef SampleIteratorType 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 class PopulationIteratorType, class PopulationItem, - template class SampleIteratorType, class SampleItem> +template class PopulationIteratorType, class PopulationItem, + template class SampleIteratorType, class SampleItem> void test_empty_population() { typedef PopulationIteratorType PopulationIterator; typedef SampleIteratorType SampleIterator; @@ -88,8 +88,8 @@ void test_empty_population() { assert(end.base() == oa); } -template class PopulationIteratorType, class PopulationItem, - template class SampleIteratorType, class SampleItem> +template class PopulationIteratorType, class PopulationItem, + template class SampleIteratorType, class SampleItem> void test_empty_sample() { typedef PopulationIteratorType PopulationIterator; typedef SampleIteratorType SampleIterator; @@ -103,8 +103,8 @@ void test_empty_sample() { assert(end.base() == oa); } -template class PopulationIteratorType, class PopulationItem, - template class SampleIteratorType, class SampleItem> +template class PopulationIteratorType, class PopulationItem, + template class SampleIteratorType, class SampleItem> void test_small_population() { // The population size is less than the sample size. typedef PopulationIteratorType PopulationIterator; diff --git a/libcxx/www/cxx1z_status.html b/libcxx/www/cxx1z_status.html index 41af346..925d6a6 100644 --- a/libcxx/www/cxx1z_status.html +++ b/libcxx/www/cxx1z_status.html @@ -299,7 +299,7 @@ 2709offsetof is unnecessarily impreciseOulu 2710"Effects: Equivalent to ..." doesn't count "Synchronization:" as determined semanticsOuluComplete 2711path is convertible from approximately everything under the sunOuluComplete - 2716Specification of shuffle and sample disallows lvalue URNGsOulu + 2716Specification of shuffle and sample disallows lvalue URNGsOuluComplete 2718Parallelism bug in [algorithms.parallel.exec] p2Oulu 2719permissions function should not be noexcept due to narrow contractOuluComplete 2720permissions function incorrectly specified for symlinksOuluComplete