[libcxx] r298597 - Remove random_shuffle in C++17. Please use shuffle instead. If you have to, you cant get it back by defining _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE before including any libc++ headers.

Marshall Clow via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 23 06:43:37 PDT 2017


Author: marshall
Date: Thu Mar 23 08:43:37 2017
New Revision: 298597

URL: http://llvm.org/viewvc/llvm-project?rev=298597&view=rev
Log:
Remove random_shuffle in C++17.  Please use shuffle instead. If you have to, you cant get it back by defining _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE before including any libc++ headers.

Added:
    libcxx/trunk/test/libcxx/algorithms/alg.modifying.operations/
    libcxx/trunk/test/libcxx/algorithms/alg.modifying.operations/alg.random.shuffle/
    libcxx/trunk/test/libcxx/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.cxx1z.pass.cpp
Modified:
    libcxx/trunk/include/algorithm
    libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.pass.cpp
    libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_rand.pass.cpp

Modified: libcxx/trunk/include/algorithm
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=298597&r1=298596&r2=298597&view=diff
==============================================================================
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Thu Mar 23 08:43:37 2017
@@ -281,12 +281,12 @@ template <class ForwardIterator, class O
 
 template <class RandomAccessIterator>
     void
-    random_shuffle(RandomAccessIterator first, RandomAccessIterator last); // deprecated in C++14
+    random_shuffle(RandomAccessIterator first, RandomAccessIterator last); // deprecated in C++14, removed in C++17
 
 template <class RandomAccessIterator, class RandomNumberGenerator>
     void
     random_shuffle(RandomAccessIterator first, RandomAccessIterator last,
-                   RandomNumberGenerator& rand);  // deprecated in C++14
+                   RandomNumberGenerator& rand);  // deprecated in C++14, removed in C++17
 
 template<class PopulationIterator, class SampleIterator,
          class Distance, class UniformRandomBitGenerator>
@@ -3026,6 +3026,7 @@ uniform_int_distribution<_IntType>::oper
     return static_cast<result_type>(__u + __p.a());
 }
 
+#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE)
 class _LIBCPP_TYPE_VIS __rs_default;
 
 _LIBCPP_FUNC_VIS __rs_default __rs_get();
@@ -3095,6 +3096,7 @@ random_shuffle(_RandomAccessIterator __f
         }
     }
 }
+#endif
 
 template <class _PopulationIterator, class _SampleIterator, class _Distance,
           class _UniformRandomNumberGenerator>

Added: libcxx/trunk/test/libcxx/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.cxx1z.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.cxx1z.pass.cpp?rev=298597&view=auto
==============================================================================
--- libcxx/trunk/test/libcxx/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.cxx1z.pass.cpp (added)
+++ libcxx/trunk/test/libcxx/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.cxx1z.pass.cpp Thu Mar 23 08:43:37 2017
@@ -0,0 +1,46 @@
+//===----------------------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// template <class RandomAccessIterator>
+//     void
+//     random_shuffle(RandomAccessIterator first, RandomAccessIterator last);
+// 
+// template <class RandomAccessIterator, class RandomNumberGenerator>
+//     void
+//     random_shuffle(RandomAccessIterator first, RandomAccessIterator last,
+//                    RandomNumberGenerator& rand);
+
+//
+//  In C++17, random_shuffle has been removed.
+//  However, for backwards compatibility, if _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
+//  is defined before including <algorithm>, then random_shuffle will be restored.
+
+#define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
+
+#include <algorithm>
+#include <vector>
+
+struct gen
+{
+    std::ptrdiff_t operator()(std::ptrdiff_t n)
+    {
+        return n-1;
+    }
+};
+
+
+int main()
+{
+    std::vector<int> v;
+    std::random_shuffle(v.begin(), v.end());
+    gen r;
+    std::random_shuffle(v.begin(), v.end(), r);
+}

Modified: libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.pass.cpp?rev=298597&r1=298596&r2=298597&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle.pass.cpp Thu Mar 23 08:43:37 2017
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 // <algorithm>
+// REQUIRES-ANY: c++98, c++03, c++11, c++14
 
 // template<RandomAccessIterator Iter>
 //   requires ShuffleIterator<Iter>

Modified: libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_rand.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_rand.pass.cpp?rev=298597&r1=298596&r2=298597&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_rand.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.random.shuffle/random_shuffle_rand.pass.cpp Thu Mar 23 08:43:37 2017
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 // <algorithm>
+// REQUIRES-ANY: c++98, c++03, c++11, c++14
 
 // template<RandomAccessIterator Iter, Callable<auto, Iter::difference_type> Rand>
 //   requires ShuffleIterator<Iter>




More information about the cfe-commits mailing list