[libcxx] r279947 - Mark LWG 2716 as complete - shuffle and sample disallows lvalue URNGs.

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 28 14:55:01 PDT 2016


Author: ericwf
Date: Sun Aug 28 16:55:00 2016
New Revision: 279947

URL: http://llvm.org/viewvc/llvm-project?rev=279947&view=rev
Log:
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.

Modified:
    libcxx/trunk/include/experimental/algorithm
    libcxx/trunk/test/libcxx/iterators/trivial_iterators.pass.cpp
    libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_urng.pass.cpp
    libcxx/trunk/test/std/experimental/algorithms/alg.random.sample/sample.fail.cpp
    libcxx/trunk/test/std/experimental/algorithms/alg.random.sample/sample.pass.cpp
    libcxx/trunk/www/cxx1z_status.html

Modified: libcxx/trunk/include/experimental/algorithm
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/algorithm?rev=279947&r1=279946&r2=279947&view=diff
==============================================================================
--- libcxx/trunk/include/experimental/algorithm (original)
+++ libcxx/trunk/include/experimental/algorithm Sun Aug 28 16:55:00 2016
@@ -107,6 +107,9 @@ _SampleIterator sample(_PopulationIterat
         _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(

Modified: libcxx/trunk/test/libcxx/iterators/trivial_iterators.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/iterators/trivial_iterators.pass.cpp?rev=279947&r1=279946&r2=279947&view=diff
==============================================================================
--- libcxx/trunk/test/libcxx/iterators/trivial_iterators.pass.cpp (original)
+++ libcxx/trunk/test/libcxx/iterators/trivial_iterators.pass.cpp Sun Aug 28 16:55:00 2016
@@ -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_;}

Modified: libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_urng.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_urng.pass.cpp?rev=279947&r1=279946&r2=279947&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_urng.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_urng.pass.cpp Sun Aug 28 16:55:00 2016
@@ -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));
 }

Modified: libcxx/trunk/test/std/experimental/algorithms/alg.random.sample/sample.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/algorithms/alg.random.sample/sample.fail.cpp?rev=279947&r1=279946&r2=279947&view=diff
==============================================================================
--- libcxx/trunk/test/std/experimental/algorithms/alg.random.sample/sample.fail.cpp (original)
+++ libcxx/trunk/test/std/experimental/algorithms/alg.random.sample/sample.fail.cpp Sun Aug 28 16:55:00 2016
@@ -32,5 +32,8 @@ template <class PopulationIterator, clas
 }
 
 int main() {
+  // expected-error at experimental/algorithm:* {{static_assert failed "SampleIterator must meet the requirements of RandomAccessIterator"}}
+  // expected-error at experimental/algorithm:* 2 {{does not provide a subscript operator}}
+  // expected-error at experimental/algorithm:* {{invalid operands}}
   test<input_iterator<int *>, output_iterator<int *> >();
 }

Modified: libcxx/trunk/test/std/experimental/algorithms/alg.random.sample/sample.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/algorithms/alg.random.sample/sample.pass.cpp?rev=279947&r1=279946&r2=279947&view=diff
==============================================================================
--- libcxx/trunk/test/std/experimental/algorithms/alg.random.sample/sample.pass.cpp (original)
+++ libcxx/trunk/test/std/experimental/algorithms/alg.random.sample/sample.pass.cpp Sun Aug 28 16:55:00 2016
@@ -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;

Modified: libcxx/trunk/www/cxx1z_status.html
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx1z_status.html?rev=279947&r1=279946&r2=279947&view=diff
==============================================================================
--- libcxx/trunk/www/cxx1z_status.html (original)
+++ libcxx/trunk/www/cxx1z_status.html Sun Aug 28 16:55:00 2016
@@ -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>




More information about the cfe-commits mailing list