diff options
author | kan <kan@FreeBSD.org> | 2007-05-19 01:25:07 +0000 |
---|---|---|
committer | kan <kan@FreeBSD.org> | 2007-05-19 01:25:07 +0000 |
commit | 7865836f4b0f698454c31b4593effcb032c22c1e (patch) | |
tree | ea6c2718dc1e45ed535d194df808ef31f0ebac92 /contrib/libstdc++/include/ext/algorithm | |
parent | 1f9ea4d0a40cca64d60cf4dab152349da7b9dddf (diff) | |
download | FreeBSD-src-7865836f4b0f698454c31b4593effcb032c22c1e.zip FreeBSD-src-7865836f4b0f698454c31b4593effcb032c22c1e.tar.gz |
GCC 4.2.0 release C++ standard library and runtime support code.
Diffstat (limited to 'contrib/libstdc++/include/ext/algorithm')
-rw-r--r-- | contrib/libstdc++/include/ext/algorithm | 169 |
1 files changed, 89 insertions, 80 deletions
diff --git a/contrib/libstdc++/include/ext/algorithm b/contrib/libstdc++/include/ext/algorithm index 07ac4cb..712a4ed 100644 --- a/contrib/libstdc++/include/ext/algorithm +++ b/contrib/libstdc++/include/ext/algorithm @@ -1,6 +1,6 @@ // Algorithm extensions -*- C++ -*- -// Copyright (C) 2001, 2002 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2004, 2005 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, // USA. // As a special exception, you may use this file as part of a free software @@ -55,8 +55,7 @@ /** @file ext/algorithm * This file is a GNU extension to the Standard C++ Library (possibly - * containing extensions from the HP/SGI STL subset). You should only - * include this header if you are using GCC 3 or later. + * containing extensions from the HP/SGI STL subset). */ #ifndef _EXT_ALGORITHM @@ -66,8 +65,8 @@ #include <algorithm> -namespace __gnu_cxx -{ +_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) + using std::ptrdiff_t; using std::min; using std::pair; @@ -84,11 +83,12 @@ namespace __gnu_cxx _OutputIterator __result, input_iterator_tag) { - for ( ; __count > 0; --__count) { - *__result = *__first; - ++__first; - ++__result; - } + for ( ; __count > 0; --__count) + { + *__result = *__first; + ++__first; + ++__result; + } return pair<_InputIterator, _OutputIterator>(__first, __result); } @@ -99,8 +99,9 @@ namespace __gnu_cxx random_access_iterator_tag) { _RAIterator __last = __first + __count; - return pair<_RAIterator, _OutputIterator>(__last, - std::copy(__first, __last, __result)); + return pair<_RAIterator, _OutputIterator>(__last, std::copy(__first, + __last, + __result)); } /** @@ -132,23 +133,24 @@ namespace __gnu_cxx template<typename _InputIterator1, typename _InputIterator2> int - __lexicographical_compare_3way(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _InputIterator2 __last2) + __lexicographical_compare_3way(_InputIterator1 __first1, + _InputIterator1 __last1, + _InputIterator2 __first2, + _InputIterator2 __last2) { - while (__first1 != __last1 && __first2 != __last2) { - if (*__first1 < *__first2) - return -1; - if (*__first2 < *__first1) - return 1; - ++__first1; - ++__first2; - } - if (__first2 == __last2) { + while (__first1 != __last1 && __first2 != __last2) + { + if (*__first1 < *__first2) + return -1; + if (*__first2 < *__first1) + return 1; + ++__first1; + ++__first2; + } + if (__first2 == __last2) return !(__first1 == __last1); - } - else { + else return -1; - } } inline int @@ -169,11 +171,10 @@ namespace __gnu_cxx const char* __first2, const char* __last2) { #if CHAR_MAX == SCHAR_MAX - return __lexicographical_compare_3way( - (const signed char*) __first1, - (const signed char*) __last1, - (const signed char*) __first2, - (const signed char*) __last2); + return __lexicographical_compare_3way((const signed char*) __first1, + (const signed char*) __last1, + (const signed char*) __first2, + (const signed char*) __last2); #else return __lexicographical_compare_3way((const unsigned char*) __first1, (const unsigned char*) __last1, @@ -198,8 +199,10 @@ namespace __gnu_cxx */ template<typename _InputIterator1, typename _InputIterator2> int - lexicographical_compare_3way(_InputIterator1 __first1, _InputIterator1 __last1, - _InputIterator2 __first2, _InputIterator2 __last2) + lexicographical_compare_3way(_InputIterator1 __first1, + _InputIterator1 __last1, + _InputIterator2 __first2, + _InputIterator2 __last2) { // concept requirements __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) @@ -211,12 +214,12 @@ namespace __gnu_cxx __glibcxx_requires_valid_range(__first1, __last1); __glibcxx_requires_valid_range(__first2, __last2); - return __lexicographical_compare_3way(__first1, __last1, __first2, __last2); + return __lexicographical_compare_3way(__first1, __last1, __first2, + __last2); } // count and count_if: this version, whose return type is void, was present // in the HP STL, and is retained as an extension for backward compatibility. - template<typename _InputIterator, typename _Tp, typename _Size> void count(_InputIterator __first, _InputIterator __last, @@ -259,7 +262,8 @@ namespace __gnu_cxx * @ingroup SGIextensions * @doctodo */ - template<typename _ForwardIterator, typename _OutputIterator, typename _Distance> + template<typename _ForwardIterator, typename _OutputIterator, + typename _Distance> _OutputIterator random_sample_n(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __out, const _Distance __n) @@ -273,16 +277,17 @@ namespace __gnu_cxx _Distance __remaining = std::distance(__first, __last); _Distance __m = min(__n, __remaining); - while (__m > 0) { - if ((std::rand() % __remaining) < __m) { + while (__m > 0) + { + if ((std::rand() % __remaining) < __m) + { *__out = *__first; ++__out; --__m; + } + --__remaining; + ++__first; } - - --__remaining; - ++__first; - } return __out; } @@ -291,8 +296,8 @@ namespace __gnu_cxx * @ingroup SGIextensions * @doctodo */ - template<typename _ForwardIterator, typename _OutputIterator, typename _Distance, - typename _RandomNumberGenerator> + template<typename _ForwardIterator, typename _OutputIterator, + typename _Distance, typename _RandomNumberGenerator> _OutputIterator random_sample_n(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __out, const _Distance __n, @@ -309,20 +314,22 @@ namespace __gnu_cxx _Distance __remaining = std::distance(__first, __last); _Distance __m = min(__n, __remaining); - while (__m > 0) { - if (__rand(__remaining) < __m) { + while (__m > 0) + { + if (__rand(__remaining) < __m) + { *__out = *__first; ++__out; --__m; + } + --__remaining; + ++__first; } - - --__remaining; - ++__first; - } return __out; } - template<typename _InputIterator, typename _RandomAccessIterator, typename _Distance> + template<typename _InputIterator, typename _RandomAccessIterator, + typename _Distance> _RandomAccessIterator __random_sample(_InputIterator __first, _InputIterator __last, _RandomAccessIterator __out, @@ -333,14 +340,14 @@ namespace __gnu_cxx for ( ; __first != __last && __m < __n; ++__m, ++__first) __out[__m] = *__first; - while (__first != __last) { - ++__t; - _Distance __M = std::rand() % (__t); - if (__M < __n) - __out[__M] = *__first; - ++__first; - } - + while (__first != __last) + { + ++__t; + _Distance __M = std::rand() % (__t); + if (__M < __n) + __out[__M] = *__first; + ++__first; + } return __out + __m; } @@ -361,14 +368,14 @@ namespace __gnu_cxx for ( ; __first != __last && __m < __n; ++__m, ++__first) __out[__m] = *__first; - while (__first != __last) { - ++__t; - _Distance __M = __rand(__t); - if (__M < __n) - __out[__M] = *__first; - ++__first; - } - + while (__first != __last) + { + ++__t; + _Distance __M = __rand(__t); + if (__M < __n) + __out[__M] = *__first; + ++__first; + } return __out + __m; } @@ -380,7 +387,8 @@ namespace __gnu_cxx template<typename _InputIterator, typename _RandomAccessIterator> inline _RandomAccessIterator random_sample(_InputIterator __first, _InputIterator __last, - _RandomAccessIterator __out_first, _RandomAccessIterator __out_last) + _RandomAccessIterator __out_first, + _RandomAccessIterator __out_last) { // concept requirements __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) @@ -402,7 +410,8 @@ namespace __gnu_cxx typename _RandomNumberGenerator> inline _RandomAccessIterator random_sample(_InputIterator __first, _InputIterator __last, - _RandomAccessIterator __out_first, _RandomAccessIterator __out_last, + _RandomAccessIterator __out_first, + _RandomAccessIterator __out_last, _RandomNumberGenerator& __rand) { // concept requirements @@ -427,7 +436,8 @@ namespace __gnu_cxx is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { // concept requirements - __glibcxx_function_requires(_RandomAccessIteratorConcept<_RandomAccessIterator>) + __glibcxx_function_requires(_RandomAccessIteratorConcept< + _RandomAccessIterator>) __glibcxx_function_requires(_LessThanComparableConcept< typename iterator_traits<_RandomAccessIterator>::value_type>) __glibcxx_requires_valid_range(__first, __last); @@ -446,7 +456,8 @@ namespace __gnu_cxx _StrictWeakOrdering __comp) { // concept requirements - __glibcxx_function_requires(_RandomAccessIteratorConcept<_RandomAccessIterator>) + __glibcxx_function_requires(_RandomAccessIteratorConcept< + _RandomAccessIterator>) __glibcxx_function_requires(_BinaryPredicateConcept<_StrictWeakOrdering, typename iterator_traits<_RandomAccessIterator>::value_type, typename iterator_traits<_RandomAccessIterator>::value_type>) @@ -478,11 +489,9 @@ namespace __gnu_cxx return true; _ForwardIterator __next = __first; - for (++__next; __next != __last; __first = __next, ++__next) { + for (++__next; __next != __last; __first = __next, ++__next) if (*__next < *__first) return false; - } - return true; } @@ -493,7 +502,8 @@ namespace __gnu_cxx */ template<typename _ForwardIterator, typename _StrictWeakOrdering> bool - is_sorted(_ForwardIterator __first, _ForwardIterator __last, _StrictWeakOrdering __comp) + is_sorted(_ForwardIterator __first, _ForwardIterator __last, + _StrictWeakOrdering __comp) { // concept requirements __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) @@ -506,13 +516,12 @@ namespace __gnu_cxx return true; _ForwardIterator __next = __first; - for (++__next; __next != __last; __first = __next, ++__next) { + for (++__next; __next != __last; __first = __next, ++__next) if (__comp(*__next, *__first)) return false; - } - return true; } -} // namespace __gnu_cxx + +_GLIBCXX_END_NAMESPACE #endif /* _EXT_ALGORITHM */ |