stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r372398 - /incubator/stdcxx/trunk/include/algorithm.cc
Date Thu, 26 Jan 2006 02:05:01 GMT
Author: sebor
Date: Wed Jan 25 18:04:58 2006
New Revision: 372398

URL: http://svn.apache.org/viewcvs?rev=372398&view=rev
Log:
2006-01-25  Martin Sebor  <sebor@roguewave.com>

	STDCXX-126
	* algorithm.cc (random_shuffle): Removed assumptions about the random
	number generator object's operator() taking an argument or returning
	a value convertible from or to anything other than the iterator's
	difference_type as required by 25.2.11, p3.

Modified:
    incubator/stdcxx/trunk/include/algorithm.cc

Modified: incubator/stdcxx/trunk/include/algorithm.cc
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/include/algorithm.cc?rev=372398&r1=372397&r2=372398&view=diff
==============================================================================
--- incubator/stdcxx/trunk/include/algorithm.cc (original)
+++ incubator/stdcxx/trunk/include/algorithm.cc Wed Jan 25 18:04:58 2006
@@ -588,10 +588,24 @@
 
     if (!(__first == __last)) {
 
-        _RWSTD_SIZE_T __limit = 1U;
+#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
+        typedef _TYPENAME
+            iterator_traits<_RandomAccessIter>::difference_type _DiffT;
+#else   // if defined (_RWSTD_NO_CLASS_PARTIAL_SPEC)
+        typedef _RWSTD_PTRDIFF_T _DiffT;
+#endif   // _RWSTD_NO_CLASS_PARTIAL_SPEC
 
-        for (_RandomAccessIter __i = __first; !(++__i == __last); )
-            _STD::iter_swap (__i, __first + __rand (++__limit));
+        _DiffT __limit = 2;
+
+        for (_RandomAccessIter __i = __first; !(++__i == __last); ++__limit) {
+
+            // the argument to and the return value of the random number
+            // generator's operator() is required to be convertinble from
+            // and to the iterator's difference_type but nothing else
+            const _DiffT __rndoff (__rand (__limit));
+
+            _STD::iter_swap (__i, __first + __rndoff);
+        }
     }
 }
 



Mime
View raw message