[cfe-commits] [libcxx] r117098 - /libcxx/trunk/include/algorithm
Howard Hinnant
hhinnant at apple.com
Fri Oct 22 08:26:39 PDT 2010
Author: hhinnant
Date: Fri Oct 22 10:26:39 2010
New Revision: 117098
URL: http://llvm.org/viewvc/llvm-project?rev=117098&view=rev
Log:
Fixed bug in random_shuffle to avoid swapping with self
Modified:
libcxx/trunk/include/algorithm
Modified: libcxx/trunk/include/algorithm
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=117098&r1=117097&r2=117098&view=diff
==============================================================================
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Fri Oct 22 10:26:39 2010
@@ -2686,7 +2686,11 @@
_D __uid;
__rs_default __g = __rs_get();
for (--__last, --__d; __first < __last; ++__first, --__d)
- swap(*__first, *(__first + __uid(__g, _P(0, __d))));
+ {
+ difference_type __i = __uid(__g, _P(0, __d));
+ if (__i != difference_type(0))
+ swap(*__first, *(__first + __i));
+ }
}
}
@@ -2704,7 +2708,10 @@
if (__d > 1)
{
for (--__last; __first < __last; ++__first, --__d)
- swap(*__first, *(__first + __rand(__d)));
+ {
+ difference_type __i = __rand(__d);
+ swap(*__first, *(__first + __i));
+ }
}
}
@@ -2720,7 +2727,11 @@
{
_D __uid;
for (--__last, --__d; __first < __last; ++__first, --__d)
- swap(*__first, *(__first + __uid(__g, _P(0, __d))));
+ {
+ difference_type __i = __uid(__g, _P(0, __d));
+ if (__i != difference_type(0))
+ swap(*__first, *(__first + __i));
+ }
}
}
More information about the cfe-commits
mailing list