This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] 13284


Removes the lrand48/drand48 confusion for good, possible now via DR 395.

tested x86/linux

2003-12-04  Benjamin Kosnik  <bkoz@redhat.com>

	PR libstdc++/13284
	* include/bits/stl_algo.h (__random_number): Remove.
	(random_shuffle): Use rand, as permitted by DR 395.
	* include/ext/algorithm: Same.
	* linkage.m4 (GLIBCXX_CHECK_STDLIB_SUPPORT): Remove lrand48.
	* acconfig.h: Same.
	* crossconfig.m4: Remove HAVE_DRAND48, HAVE_LRAND48.
	* config.h.in: Regenerated.
	* configure: Same.
	* aclocal.m4: Same.

Index: include/bits/stl_algo.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/stl_algo.h,v
retrieving revision 1.42
diff -c -p -r1.42 stl_algo.h
*** include/bits/stl_algo.h	11 Nov 2003 20:09:08 -0000	1.42
--- include/bits/stl_algo.h	4 Dec 2003 19:10:46 -0000
*************** namespace std
*** 1652,1679 ****
        return std::copy(__first, __middle, copy(__middle, __last, __result));
      }
  
- 
-   /**
-    *  @if maint
-    *  Return a random number in the range [0, __n).  This function encapsulates
-    *  whether we're using rand (part of the standard C library) or lrand48
-    *  (not standard, but a much better choice whenever it's available).
-    *
-    *  XXX There is no corresponding encapsulation fn to seed the generator.
-    *  @endif
-   */
-   template<typename _Distance>
-     inline _Distance
-     __random_number(_Distance __n)
-     {
-   #ifdef _GLIBCXX_HAVE_LRAND48
-       return lrand48() % __n;
-   #else
-       return rand() % __n;
-   #endif
-     }
- 
- 
    /**
     *  @brief Randomly shuffle the elements of a sequence.
     *  @param  first   A forward iterator.
--- 1652,1657 ----
*************** namespace std
*** 1693,1701 ****
  	    _RandomAccessIterator>)
        __glibcxx_requires_valid_range(__first, __last);
  
!       if (__first == __last) return;
!       for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
! 	std::iter_swap(__i, __first + std::__random_number((__i - __first) + 1));
      }
  
    /**
--- 1671,1679 ----
  	    _RandomAccessIterator>)
        __glibcxx_requires_valid_range(__first, __last);
  
!       if (__first != __last) 
! 	for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
! 	  std::iter_swap(__i, __first + (std::rand() % ((__i - __first) + 1)));
      }
  
    /**
Index: include/ext/algorithm
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/ext/algorithm,v
retrieving revision 1.9
diff -c -p -r1.9 algorithm
*** include/ext/algorithm	11 Nov 2003 20:09:09 -0000	1.9
--- include/ext/algorithm	4 Dec 2003 19:10:46 -0000
*************** namespace __gnu_cxx
*** 274,280 ****
        _Distance __m = min(__n, __remaining);
  
        while (__m > 0) {
! 	if (std::__random_number(__remaining) < __m) {
  	      *__out = *__first;
  	      ++__out;
  	      --__m;
--- 274,280 ----
        _Distance __m = min(__n, __remaining);
  
        while (__m > 0) {
! 	if ((std::rand() % __remaining) < __m) {
  	      *__out = *__first;
  	      ++__out;
  	      --__m;
*************** namespace __gnu_cxx
*** 335,341 ****
  
        while (__first != __last) {
  	++__t;
! 	_Distance __M = std::__random_number(__t);
  	if (__M < __n)
  	  __out[__M] = *__first;
  	++__first;
--- 335,341 ----
  
        while (__first != __last) {
  	++__t;
! 	_Distance __M = std::rand() % (__t);
  	if (__M < __n)
  	  __out[__M] = *__first;
  	++__first;
Index: linkage.m4
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/linkage.m4,v
retrieving revision 1.3
diff -c -p -r1.3 linkage.m4
*** linkage.m4	1 Oct 2003 20:45:45 -0000	1.3
--- linkage.m4	4 Dec 2003 19:10:47 -0000
*************** dnl This might seem like overkill but ex
*** 371,377 ****
  dnl
  dnl Define HAVE_STRTOLD if "strtold" is declared and links
  dnl Define HAVE_STRTOF if "strtof" is declared and links
- dnl Define HAVE_LRAND48 if "lrand48" is declared and links
  dnl
  dnl GLIBCXX_CHECK_STDLIB_SUPPORT
  AC_DEFUN(GLIBCXX_CHECK_STDLIB_SUPPORT, [
--- 371,376 ----
*************** AC_DEFUN(GLIBCXX_CHECK_STDLIB_SUPPORT, [
*** 381,387 ****
  
    GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_2(strtold)
    GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_2(strtof)
-   GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_0(lrand48)
  
    CXXFLAGS="$ac_save_CXXFLAGS"
  ])
--- 380,385 ----
Index: crossconfig.m4
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/crossconfig.m4,v
retrieving revision 1.9
diff -c -p -r1.9 crossconfig.m4
*** crossconfig.m4	7 Nov 2003 16:49:18 -0000	1.9
--- crossconfig.m4	4 Dec 2003 19:10:47 -0000
*************** case "${host}" in
*** 53,59 ****
      GLIBCXX_CHECK_COMPLEX_MATH_SUPPORT
      GLIBCXX_CHECK_WCHAR_T_SUPPORT
      AC_DEFINE(HAVE_LC_MESSAGES)
-     AC_DEFINE(HAVE_LRAND48)
      AC_DEFINE(HAVE_GETPAGESIZE)
      AC_DEFINE(HAVE_SETENV)
      AC_DEFINE(HAVE_SIGSETJMP)
--- 53,58 ----
*************** case "${host}" in
*** 217,223 ****
           AC_DEFINE(HAVE_S_ISREG)
           AC_DEFINE(HAVE_LC_MESSAGES)
           AC_DEFINE(HAVE_BTOWC)
-          AC_DEFINE(HAVE_DRAND48)
           AC_DEFINE(HAVE_FGETWC)
           AC_DEFINE(HAVE_FGETWS)
           AC_DEFINE(HAVE_FINITE)
--- 216,221 ----
Index: acconfig.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/acconfig.h,v
retrieving revision 1.36
diff -c -p -r1.36 acconfig.h
*** acconfig.h	22 Oct 2003 15:51:43 -0000	1.36
--- acconfig.h	4 Dec 2003 19:10:47 -0000
***************
*** 63,71 ****
  // Define if gthr-default.h exists (meaning that threading support is enabled).
  #undef HAVE_GTHR_DEFAULT
  
- // Define if lrand48 exists.
- #undef HAVE_DRAND48
- 
  // Define if getpagesize exists.
  #undef HAVE_GETPAGESIZE
  
--- 63,68 ----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]