stl_algobase.h

Go to the documentation of this file.
00001 // Core algorithmic facilities -*- C++ -*-
00002 
00003 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
00004 // Free Software Foundation, Inc.
00005 //
00006 // This file is part of the GNU ISO C++ Library.  This library is free
00007 // software; you can redistribute it and/or modify it under the
00008 // terms of the GNU General Public License as published by the
00009 // Free Software Foundation; either version 3, or (at your option)
00010 // any later version.
00011 
00012 // This library is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 
00017 // Under Section 7 of GPL version 3, you are granted additional
00018 // permissions described in the GCC Runtime Library Exception, version
00019 // 3.1, as published by the Free Software Foundation.
00020 
00021 // You should have received a copy of the GNU General Public License and
00022 // a copy of the GCC Runtime Library Exception along with this program;
00023 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00024 // <http://www.gnu.org/licenses/>.
00025 
00026 /*
00027  *
00028  * Copyright (c) 1994
00029  * Hewlett-Packard Company
00030  *
00031  * Permission to use, copy, modify, distribute and sell this software
00032  * and its documentation for any purpose is hereby granted without fee,
00033  * provided that the above copyright notice appear in all copies and
00034  * that both that copyright notice and this permission notice appear
00035  * in supporting documentation.  Hewlett-Packard Company makes no
00036  * representations about the suitability of this software for any
00037  * purpose.  It is provided "as is" without express or implied warranty.
00038  *
00039  *
00040  * Copyright (c) 1996-1998
00041  * Silicon Graphics Computer Systems, Inc.
00042  *
00043  * Permission to use, copy, modify, distribute and sell this software
00044  * and its documentation for any purpose is hereby granted without fee,
00045  * provided that the above copyright notice appear in all copies and
00046  * that both that copyright notice and this permission notice appear
00047  * in supporting documentation.  Silicon Graphics makes no
00048  * representations about the suitability of this software for any
00049  * purpose.  It is provided "as is" without express or implied warranty.
00050  */
00051 
00052 /** @file stl_algobase.h
00053  *  This is an internal header file, included by other library headers.
00054  *  You should not attempt to use it directly.
00055  */
00056 
00057 #ifndef _STL_ALGOBASE_H
00058 #define _STL_ALGOBASE_H 1
00059 
00060 #include <bits/c++config.h>
00061 #include <bits/functexcept.h>
00062 #include <bits/cpp_type_traits.h>
00063 #include <ext/type_traits.h>
00064 #include <ext/numeric_traits.h>
00065 #include <bits/stl_pair.h>
00066 #include <bits/stl_iterator_base_types.h>
00067 #include <bits/stl_iterator_base_funcs.h>
00068 #include <bits/stl_iterator.h>
00069 #include <bits/concept_check.h>
00070 #include <debug/debug.h>
00071 #include <bits/move.h> // For std::swap and _GLIBCXX_MOVE
00072 
00073 _GLIBCXX_BEGIN_NAMESPACE(std)
00074 
00075   // See http://gcc.gnu.org/ml/libstdc++/2004-08/msg00167.html: in a
00076   // nutshell, we are partially implementing the resolution of DR 187,
00077   // when it's safe, i.e., the value_types are equal.
00078   template<bool _BoolType>
00079     struct __iter_swap
00080     {
00081       template<typename _ForwardIterator1, typename _ForwardIterator2>
00082         static void
00083         iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
00084         {
00085           typedef typename iterator_traits<_ForwardIterator1>::value_type
00086             _ValueType1;
00087           _ValueType1 __tmp = _GLIBCXX_MOVE(*__a);
00088           *__a = _GLIBCXX_MOVE(*__b);
00089           *__b = _GLIBCXX_MOVE(__tmp);
00090     }
00091     };
00092 
00093   template<>
00094     struct __iter_swap<true>
00095     {
00096       template<typename _ForwardIterator1, typename _ForwardIterator2>
00097         static void 
00098         iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
00099         {
00100           swap(*__a, *__b);
00101         }
00102     };
00103 
00104   /**
00105    *  @brief Swaps the contents of two iterators.
00106    *  @ingroup mutating_algorithms
00107    *  @param  a  An iterator.
00108    *  @param  b  Another iterator.
00109    *  @return   Nothing.
00110    *
00111    *  This function swaps the values pointed to by two iterators, not the
00112    *  iterators themselves.
00113   */
00114   template<typename _ForwardIterator1, typename _ForwardIterator2>
00115     inline void
00116     iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
00117     {
00118       typedef typename iterator_traits<_ForwardIterator1>::value_type
00119     _ValueType1;
00120       typedef typename iterator_traits<_ForwardIterator2>::value_type
00121     _ValueType2;
00122 
00123       // concept requirements
00124       __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
00125                   _ForwardIterator1>)
00126       __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
00127                   _ForwardIterator2>)
00128       __glibcxx_function_requires(_ConvertibleConcept<_ValueType1,
00129                   _ValueType2>)
00130       __glibcxx_function_requires(_ConvertibleConcept<_ValueType2,
00131                   _ValueType1>)
00132 
00133       typedef typename iterator_traits<_ForwardIterator1>::reference
00134     _ReferenceType1;
00135       typedef typename iterator_traits<_ForwardIterator2>::reference
00136     _ReferenceType2;
00137       std::__iter_swap<__are_same<_ValueType1, _ValueType2>::__value
00138     && __are_same<_ValueType1&, _ReferenceType1>::__value
00139     && __are_same<_ValueType2&, _ReferenceType2>::__value>::
00140     iter_swap(__a, __b);
00141     }
00142 
00143   /**
00144    *  @brief Swap the elements of two sequences.
00145    *  @ingroup mutating_algorithms
00146    *  @param  first1  A forward iterator.
00147    *  @param  last1   A forward iterator.
00148    *  @param  first2  A forward iterator.
00149    *  @return   An iterator equal to @p first2+(last1-first1).
00150    *
00151    *  Swaps each element in the range @p [first1,last1) with the
00152    *  corresponding element in the range @p [first2,(last1-first1)).
00153    *  The ranges must not overlap.
00154   */
00155   template<typename _ForwardIterator1, typename _ForwardIterator2>
00156     _ForwardIterator2
00157     swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
00158         _ForwardIterator2 __first2)
00159     {
00160       // concept requirements
00161       __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
00162                   _ForwardIterator1>)
00163       __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
00164                   _ForwardIterator2>)
00165       __glibcxx_requires_valid_range(__first1, __last1);
00166 
00167       for (; __first1 != __last1; ++__first1, ++__first2)
00168     std::iter_swap(__first1, __first2);
00169       return __first2;
00170     }
00171 
00172   /**
00173    *  @brief This does what you think it does.
00174    *  @ingroup sorting_algorithms
00175    *  @param  a  A thing of arbitrary type.
00176    *  @param  b  Another thing of arbitrary type.
00177    *  @return   The lesser of the parameters.
00178    *
00179    *  This is the simple classic generic implementation.  It will work on
00180    *  temporary expressions, since they are only evaluated once, unlike a
00181    *  preprocessor macro.
00182   */
00183   template<typename _Tp>
00184     inline const _Tp&
00185     min(const _Tp& __a, const _Tp& __b)
00186     {
00187       // concept requirements
00188       __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
00189       //return __b < __a ? __b : __a;
00190       if (__b < __a)
00191     return __b;
00192       return __a;
00193     }
00194 
00195   /**
00196    *  @brief This does what you think it does.
00197    *  @ingroup sorting_algorithms
00198    *  @param  a  A thing of arbitrary type.
00199    *  @param  b  Another thing of arbitrary type.
00200    *  @return   The greater of the parameters.
00201    *
00202    *  This is the simple classic generic implementation.  It will work on
00203    *  temporary expressions, since they are only evaluated once, unlike a
00204    *  preprocessor macro.
00205   */
00206   template<typename _Tp>
00207     inline const _Tp&
00208     max(const _Tp& __a, const _Tp& __b)
00209     {
00210       // concept requirements
00211       __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
00212       //return  __a < __b ? __b : __a;
00213       if (__a < __b)
00214     return __b;
00215       return __a;
00216     }
00217 
00218   /**
00219    *  @brief This does what you think it does.
00220    *  @ingroup sorting_algorithms
00221    *  @param  a  A thing of arbitrary type.
00222    *  @param  b  Another thing of arbitrary type.
00223    *  @param  comp  A @link comparison_functors comparison functor@endlink.
00224    *  @return   The lesser of the parameters.
00225    *
00226    *  This will work on temporary expressions, since they are only evaluated
00227    *  once, unlike a preprocessor macro.
00228   */
00229   template<typename _Tp, typename _Compare>
00230     inline const _Tp&
00231     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
00232     {
00233       //return __comp(__b, __a) ? __b : __a;
00234       if (__comp(__b, __a))
00235     return __b;
00236       return __a;
00237     }
00238 
00239   /**
00240    *  @brief This does what you think it does.
00241    *  @ingroup sorting_algorithms
00242    *  @param  a  A thing of arbitrary type.
00243    *  @param  b  Another thing of arbitrary type.
00244    *  @param  comp  A @link comparison_functors comparison functor@endlink.
00245    *  @return   The greater of the parameters.
00246    *
00247    *  This will work on temporary expressions, since they are only evaluated
00248    *  once, unlike a preprocessor macro.
00249   */
00250   template<typename _Tp, typename _Compare>
00251     inline const _Tp&
00252     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
00253     {
00254       //return __comp(__a, __b) ? __b : __a;
00255       if (__comp(__a, __b))
00256     return __b;
00257       return __a;
00258     }
00259 
00260 
00261   // If _Iterator has a base returns it otherwise _Iterator is returned
00262   // untouched
00263   template<typename _Iterator, bool _HasBase>
00264     struct _Iter_base
00265     {
00266       typedef _Iterator iterator_type;
00267       static iterator_type
00268       _S_base(_Iterator __it)
00269       { return __it; }
00270     };
00271 
00272   template<typename _Iterator>
00273     struct _Iter_base<_Iterator, true>
00274     {
00275       typedef typename _Iterator::iterator_type iterator_type;
00276       static iterator_type
00277       _S_base(_Iterator __it)
00278       { return __it.base(); }
00279     };
00280 
00281   // If _Iterator is a __normal_iterator return its base (a plain pointer,
00282   // normally) otherwise return it untouched.  See copy, fill, ... 
00283   template<typename _Iterator>
00284     struct _Niter_base
00285     : _Iter_base<_Iterator, __is_normal_iterator<_Iterator>::__value>
00286     { };
00287 
00288   template<typename _Iterator>
00289     inline typename _Niter_base<_Iterator>::iterator_type
00290     __niter_base(_Iterator __it)
00291     { return std::_Niter_base<_Iterator>::_S_base(__it); }
00292 
00293   // Likewise, for move_iterator.
00294   template<typename _Iterator>
00295     struct _Miter_base
00296     : _Iter_base<_Iterator, __is_move_iterator<_Iterator>::__value>
00297     { };
00298 
00299   template<typename _Iterator>
00300     inline typename _Miter_base<_Iterator>::iterator_type
00301     __miter_base(_Iterator __it)
00302     { return std::_Miter_base<_Iterator>::_S_base(__it); }
00303 
00304   // All of these auxiliary structs serve two purposes.  (1) Replace
00305   // calls to copy with memmove whenever possible.  (Memmove, not memcpy,
00306   // because the input and output ranges are permitted to overlap.)
00307   // (2) If we're using random access iterators, then write the loop as
00308   // a for loop with an explicit count.
00309 
00310   template<bool, bool, typename>
00311     struct __copy_move
00312     {
00313       template<typename _II, typename _OI>
00314         static _OI
00315         __copy_m(_II __first, _II __last, _OI __result)
00316         {
00317       for (; __first != __last; ++__result, ++__first)
00318         *__result = *__first;
00319       return __result;
00320     }
00321     };
00322 
00323 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00324   template<typename _Category>
00325     struct __copy_move<true, false, _Category>
00326     {
00327       template<typename _II, typename _OI>
00328         static _OI
00329         __copy_m(_II __first, _II __last, _OI __result)
00330         {
00331       for (; __first != __last; ++__result, ++__first)
00332         *__result = std::move(*__first);
00333       return __result;
00334     }
00335     };
00336 #endif
00337 
00338   template<>
00339     struct __copy_move<false, false, random_access_iterator_tag>
00340     {
00341       template<typename _II, typename _OI>
00342         static _OI
00343         __copy_m(_II __first, _II __last, _OI __result)
00344         { 
00345       typedef typename iterator_traits<_II>::difference_type _Distance;
00346       for(_Distance __n = __last - __first; __n > 0; --__n)
00347         {
00348           *__result = *__first;
00349           ++__first;
00350           ++__result;
00351         }
00352       return __result;
00353     }
00354     };
00355 
00356 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00357   template<>
00358     struct __copy_move<true, false, random_access_iterator_tag>
00359     {
00360       template<typename _II, typename _OI>
00361         static _OI
00362         __copy_m(_II __first, _II __last, _OI __result)
00363         { 
00364       typedef typename iterator_traits<_II>::difference_type _Distance;
00365       for(_Distance __n = __last - __first; __n > 0; --__n)
00366         {
00367           *__result = std::move(*__first);
00368           ++__first;
00369           ++__result;
00370         }
00371       return __result;
00372     }
00373     };
00374 #endif
00375 
00376   template<bool _IsMove>
00377     struct __copy_move<_IsMove, true, random_access_iterator_tag>
00378     {
00379       template<typename _Tp>
00380         static _Tp*
00381         __copy_m(const _Tp* __first, const _Tp* __last, _Tp* __result)
00382         {
00383       const ptrdiff_t _Num = __last - __first;
00384       if (_Num)
00385         __builtin_memmove(__result, __first, sizeof(_Tp) * _Num);
00386       return __result + _Num;
00387     }
00388     };
00389 
00390   template<bool _IsMove, typename _II, typename _OI>
00391     inline _OI
00392     __copy_move_a(_II __first, _II __last, _OI __result)
00393     {
00394       typedef typename iterator_traits<_II>::value_type _ValueTypeI;
00395       typedef typename iterator_traits<_OI>::value_type _ValueTypeO;
00396       typedef typename iterator_traits<_II>::iterator_category _Category;
00397       const bool __simple = (__is_trivial(_ValueTypeI)
00398                          && __is_pointer<_II>::__value
00399                          && __is_pointer<_OI>::__value
00400                  && __are_same<_ValueTypeI, _ValueTypeO>::__value);
00401 
00402       return std::__copy_move<_IsMove, __simple,
00403                           _Category>::__copy_m(__first, __last, __result);
00404     }
00405 
00406   // Helpers for streambuf iterators (either istream or ostream).
00407   // NB: avoid including <iosfwd>, relatively large.
00408   template<typename _CharT>
00409     struct char_traits;
00410 
00411   template<typename _CharT, typename _Traits>
00412     class istreambuf_iterator;
00413 
00414   template<typename _CharT, typename _Traits>
00415     class ostreambuf_iterator;
00416 
00417   template<bool _IsMove, typename _CharT>
00418     typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, 
00419          ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
00420     __copy_move_a2(_CharT*, _CharT*,
00421            ostreambuf_iterator<_CharT, char_traits<_CharT> >);
00422 
00423   template<bool _IsMove, typename _CharT>
00424     typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, 
00425          ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
00426     __copy_move_a2(const _CharT*, const _CharT*,
00427            ostreambuf_iterator<_CharT, char_traits<_CharT> >);
00428 
00429   template<bool _IsMove, typename _CharT>
00430     typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
00431                     _CharT*>::__type
00432     __copy_move_a2(istreambuf_iterator<_CharT, char_traits<_CharT> >,
00433            istreambuf_iterator<_CharT, char_traits<_CharT> >, _CharT*);
00434 
00435   template<bool _IsMove, typename _II, typename _OI>
00436     inline _OI
00437     __copy_move_a2(_II __first, _II __last, _OI __result)
00438     {
00439       return _OI(std::__copy_move_a<_IsMove>(std::__niter_base(__first),
00440                          std::__niter_base(__last),
00441                          std::__niter_base(__result)));
00442     }
00443 
00444   /**
00445    *  @brief Copies the range [first,last) into result.
00446    *  @ingroup mutating_algorithms
00447    *  @param  first  An input iterator.
00448    *  @param  last   An input iterator.
00449    *  @param  result An output iterator.
00450    *  @return   result + (first - last)
00451    *
00452    *  This inline function will boil down to a call to @c memmove whenever
00453    *  possible.  Failing that, if random access iterators are passed, then the
00454    *  loop count will be known (and therefore a candidate for compiler
00455    *  optimizations such as unrolling).  Result may not be contained within
00456    *  [first,last); the copy_backward function should be used instead.
00457    *
00458    *  Note that the end of the output range is permitted to be contained
00459    *  within [first,last).
00460   */
00461   template<typename _II, typename _OI>
00462     inline _OI
00463     copy(_II __first, _II __last, _OI __result)
00464     {
00465       // concept requirements
00466       __glibcxx_function_requires(_InputIteratorConcept<_II>)
00467       __glibcxx_function_requires(_OutputIteratorConcept<_OI,
00468         typename iterator_traits<_II>::value_type>)
00469       __glibcxx_requires_valid_range(__first, __last);
00470 
00471       return (std::__copy_move_a2<__is_move_iterator<_II>::__value>
00472           (std::__miter_base(__first), std::__miter_base(__last),
00473            __result));
00474     }
00475 
00476 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00477   /**
00478    *  @brief Moves the range [first,last) into result.
00479    *  @ingroup mutating_algorithms
00480    *  @param  first  An input iterator.
00481    *  @param  last   An input iterator.
00482    *  @param  result An output iterator.
00483    *  @return   result + (first - last)
00484    *
00485    *  This inline function will boil down to a call to @c memmove whenever
00486    *  possible.  Failing that, if random access iterators are passed, then the
00487    *  loop count will be known (and therefore a candidate for compiler
00488    *  optimizations such as unrolling).  Result may not be contained within
00489    *  [first,last); the move_backward function should be used instead.
00490    *
00491    *  Note that the end of the output range is permitted to be contained
00492    *  within [first,last).
00493   */
00494   template<typename _II, typename _OI>
00495     inline _OI
00496     move(_II __first, _II __last, _OI __result)
00497     {
00498       // concept requirements
00499       __glibcxx_function_requires(_InputIteratorConcept<_II>)
00500       __glibcxx_function_requires(_OutputIteratorConcept<_OI,
00501         typename iterator_traits<_II>::value_type>)
00502       __glibcxx_requires_valid_range(__first, __last);
00503 
00504       return std::__copy_move_a2<true>(std::__miter_base(__first),
00505                        std::__miter_base(__last), __result);
00506     }
00507 
00508 #define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp)
00509 #else
00510 #define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp)
00511 #endif
00512 
00513   template<bool, bool, typename>
00514     struct __copy_move_backward
00515     {
00516       template<typename _BI1, typename _BI2>
00517         static _BI2
00518         __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
00519         {
00520       while (__first != __last)
00521         *--__result = *--__last;
00522       return __result;
00523     }
00524     };
00525 
00526 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00527   template<typename _Category>
00528     struct __copy_move_backward<true, false, _Category>
00529     {
00530       template<typename _BI1, typename _BI2>
00531         static _BI2
00532         __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
00533         {
00534       while (__first != __last)
00535         *--__result = std::move(*--__last);
00536       return __result;
00537     }
00538     };
00539 #endif
00540 
00541   template<>
00542     struct __copy_move_backward<false, false, random_access_iterator_tag>
00543     {
00544       template<typename _BI1, typename _BI2>
00545         static _BI2
00546         __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
00547         {
00548       typename iterator_traits<_BI1>::difference_type __n;
00549       for (__n = __last - __first; __n > 0; --__n)
00550         *--__result = *--__last;
00551       return __result;
00552     }
00553     };
00554 
00555 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00556   template<>
00557     struct __copy_move_backward<true, false, random_access_iterator_tag>
00558     {
00559       template<typename _BI1, typename _BI2>
00560         static _BI2
00561         __copy_move_b(_BI1 __first, _BI1 __last, _BI2 __result)
00562         {
00563       typename iterator_traits<_BI1>::difference_type __n;
00564       for (__n = __last - __first; __n > 0; --__n)
00565         *--__result = std::move(*--__last);
00566       return __result;
00567     }
00568     };
00569 #endif
00570 
00571   template<bool _IsMove>
00572     struct __copy_move_backward<_IsMove, true, random_access_iterator_tag>
00573     {
00574       template<typename _Tp>
00575         static _Tp*
00576         __copy_move_b(const _Tp* __first, const _Tp* __last, _Tp* __result)
00577         {
00578       const ptrdiff_t _Num = __last - __first;
00579       if (_Num)
00580         __builtin_memmove(__result - _Num, __first, sizeof(_Tp) * _Num);
00581       return __result - _Num;
00582     }
00583     };
00584 
00585   template<bool _IsMove, typename _BI1, typename _BI2>
00586     inline _BI2
00587     __copy_move_backward_a(_BI1 __first, _BI1 __last, _BI2 __result)
00588     {
00589       typedef typename iterator_traits<_BI1>::value_type _ValueType1;
00590       typedef typename iterator_traits<_BI2>::value_type _ValueType2;
00591       typedef typename iterator_traits<_BI1>::iterator_category _Category;
00592       const bool __simple = (__is_trivial(_ValueType1)
00593                          && __is_pointer<_BI1>::__value
00594                          && __is_pointer<_BI2>::__value
00595                  && __are_same<_ValueType1, _ValueType2>::__value);
00596 
00597       return std::__copy_move_backward<_IsMove, __simple,
00598                                    _Category>::__copy_move_b(__first,
00599                                  __last,
00600                                  __result);
00601     }
00602 
00603   template<bool _IsMove, typename _BI1, typename _BI2>
00604     inline _BI2
00605     __copy_move_backward_a2(_BI1 __first, _BI1 __last, _BI2 __result)
00606     {
00607       return _BI2(std::__copy_move_backward_a<_IsMove>
00608           (std::__niter_base(__first), std::__niter_base(__last),
00609            std::__niter_base(__result)));
00610     }
00611 
00612   /**
00613    *  @brief Copies the range [first,last) into result.
00614    *  @ingroup mutating_algorithms
00615    *  @param  first  A bidirectional iterator.
00616    *  @param  last   A bidirectional iterator.
00617    *  @param  result A bidirectional iterator.
00618    *  @return   result - (first - last)
00619    *
00620    *  The function has the same effect as copy, but starts at the end of the
00621    *  range and works its way to the start, returning the start of the result.
00622    *  This inline function will boil down to a call to @c memmove whenever
00623    *  possible.  Failing that, if random access iterators are passed, then the
00624    *  loop count will be known (and therefore a candidate for compiler
00625    *  optimizations such as unrolling).
00626    *
00627    *  Result may not be in the range [first,last).  Use copy instead.  Note
00628    *  that the start of the output range may overlap [first,last).
00629   */
00630   template<typename _BI1, typename _BI2>
00631     inline _BI2
00632     copy_backward(_BI1 __first, _BI1 __last, _BI2 __result)
00633     {
00634       // concept requirements
00635       __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
00636       __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
00637       __glibcxx_function_requires(_ConvertibleConcept<
00638         typename iterator_traits<_BI1>::value_type,
00639         typename iterator_traits<_BI2>::value_type>)
00640       __glibcxx_requires_valid_range(__first, __last);
00641 
00642       return (std::__copy_move_backward_a2<__is_move_iterator<_BI1>::__value>
00643           (std::__miter_base(__first), std::__miter_base(__last),
00644            __result));
00645     }
00646 
00647 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00648   /**
00649    *  @brief Moves the range [first,last) into result.
00650    *  @ingroup mutating_algorithms
00651    *  @param  first  A bidirectional iterator.
00652    *  @param  last   A bidirectional iterator.
00653    *  @param  result A bidirectional iterator.
00654    *  @return   result - (first - last)
00655    *
00656    *  The function has the same effect as move, but starts at the end of the
00657    *  range and works its way to the start, returning the start of the result.
00658    *  This inline function will boil down to a call to @c memmove whenever
00659    *  possible.  Failing that, if random access iterators are passed, then the
00660    *  loop count will be known (and therefore a candidate for compiler
00661    *  optimizations such as unrolling).
00662    *
00663    *  Result may not be in the range [first,last).  Use move instead.  Note
00664    *  that the start of the output range may overlap [first,last).
00665   */
00666   template<typename _BI1, typename _BI2>
00667     inline _BI2
00668     move_backward(_BI1 __first, _BI1 __last, _BI2 __result)
00669     {
00670       // concept requirements
00671       __glibcxx_function_requires(_BidirectionalIteratorConcept<_BI1>)
00672       __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<_BI2>)
00673       __glibcxx_function_requires(_ConvertibleConcept<
00674         typename iterator_traits<_BI1>::value_type,
00675         typename iterator_traits<_BI2>::value_type>)
00676       __glibcxx_requires_valid_range(__first, __last);
00677 
00678       return std::__copy_move_backward_a2<true>(std::__miter_base(__first),
00679                         std::__miter_base(__last),
00680                         __result);
00681     }
00682 
00683 #define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp)
00684 #else
00685 #define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp)
00686 #endif
00687 
00688   template<typename _ForwardIterator, typename _Tp>
00689     inline typename
00690     __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, void>::__type
00691     __fill_a(_ForwardIterator __first, _ForwardIterator __last,
00692          const _Tp& __value)
00693     {
00694       for (; __first != __last; ++__first)
00695     *__first = __value;
00696     }
00697     
00698   template<typename _ForwardIterator, typename _Tp>
00699     inline typename
00700     __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type
00701     __fill_a(_ForwardIterator __first, _ForwardIterator __last,
00702          const _Tp& __value)
00703     {
00704       const _Tp __tmp = __value;
00705       for (; __first != __last; ++__first)
00706     *__first = __tmp;
00707     }
00708 
00709   // Specialization: for char types we can use memset.
00710   template<typename _Tp>
00711     inline typename
00712     __gnu_cxx::__enable_if<__is_byte<_Tp>::__value, void>::__type
00713     __fill_a(_Tp* __first, _Tp* __last, const _Tp& __c)
00714     {
00715       const _Tp __tmp = __c;
00716       __builtin_memset(__first, static_cast<unsigned char>(__tmp),
00717                __last - __first);
00718     }
00719 
00720   /**
00721    *  @brief Fills the range [first,last) with copies of value.
00722    *  @ingroup mutating_algorithms
00723    *  @param  first  A forward iterator.
00724    *  @param  last   A forward iterator.
00725    *  @param  value  A reference-to-const of arbitrary type.
00726    *  @return   Nothing.
00727    *
00728    *  This function fills a range with copies of the same value.  For char
00729    *  types filling contiguous areas of memory, this becomes an inline call
00730    *  to @c memset or @c wmemset.
00731   */
00732   template<typename _ForwardIterator, typename _Tp>
00733     inline void
00734     fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
00735     {
00736       // concept requirements
00737       __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
00738                   _ForwardIterator>)
00739       __glibcxx_requires_valid_range(__first, __last);
00740 
00741       std::__fill_a(std::__niter_base(__first), std::__niter_base(__last),
00742             __value);
00743     }
00744 
00745   template<typename _OutputIterator, typename _Size, typename _Tp>
00746     inline typename
00747     __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
00748     __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)
00749     {
00750       for (__decltype(__n + 0) __niter = __n;
00751        __niter > 0; --__niter, ++__first)
00752     *__first = __value;
00753       return __first;
00754     }
00755 
00756   template<typename _OutputIterator, typename _Size, typename _Tp>
00757     inline typename
00758     __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
00759     __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)
00760     {
00761       const _Tp __tmp = __value;
00762       for (__decltype(__n + 0) __niter = __n;
00763        __niter > 0; --__niter, ++__first)
00764     *__first = __tmp;
00765       return __first;
00766     }
00767 
00768   template<typename _Size, typename _Tp>
00769     inline typename
00770     __gnu_cxx::__enable_if<__is_byte<_Tp>::__value, _Tp*>::__type
00771     __fill_n_a(_Tp* __first, _Size __n, const _Tp& __c)
00772     {
00773       std::__fill_a(__first, __first + __n, __c);
00774       return __first + __n;
00775     }
00776 
00777   /**
00778    *  @brief Fills the range [first,first+n) with copies of value.
00779    *  @ingroup mutating_algorithms
00780    *  @param  first  An output iterator.
00781    *  @param  n      The count of copies to perform.
00782    *  @param  value  A reference-to-const of arbitrary type.
00783    *  @return   The iterator at first+n.
00784    *
00785    *  This function fills a range with copies of the same value.  For char
00786    *  types filling contiguous areas of memory, this becomes an inline call
00787    *  to @c memset or @ wmemset.
00788    *
00789    *  _GLIBCXX_RESOLVE_LIB_DEFECTS
00790    *  DR 865. More algorithms that throw away information
00791   */
00792   template<typename _OI, typename _Size, typename _Tp>
00793     inline _OI
00794     fill_n(_OI __first, _Size __n, const _Tp& __value)
00795     {
00796       // concept requirements
00797       __glibcxx_function_requires(_OutputIteratorConcept<_OI, _Tp>)
00798 
00799       return _OI(std::__fill_n_a(std::__niter_base(__first), __n, __value));
00800     }
00801 
00802   template<bool _BoolType>
00803     struct __equal
00804     {
00805       template<typename _II1, typename _II2>
00806         static bool
00807         equal(_II1 __first1, _II1 __last1, _II2 __first2)
00808         {
00809       for (; __first1 != __last1; ++__first1, ++__first2)
00810         if (!(*__first1 == *__first2))
00811           return false;
00812       return true;
00813     }
00814     };
00815 
00816   template<>
00817     struct __equal<true>
00818     {
00819       template<typename _Tp>
00820         static bool
00821         equal(const _Tp* __first1, const _Tp* __last1, const _Tp* __first2)
00822         {
00823       return !__builtin_memcmp(__first1, __first2, sizeof(_Tp)
00824                    * (__last1 - __first1));
00825     }
00826     };
00827 
00828   template<typename _II1, typename _II2>
00829     inline bool
00830     __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2)
00831     {
00832       typedef typename iterator_traits<_II1>::value_type _ValueType1;
00833       typedef typename iterator_traits<_II2>::value_type _ValueType2;
00834       const bool __simple = (__is_integer<_ValueType1>::__value
00835                          && __is_pointer<_II1>::__value
00836                          && __is_pointer<_II2>::__value
00837                  && __are_same<_ValueType1, _ValueType2>::__value);
00838 
00839       return std::__equal<__simple>::equal(__first1, __last1, __first2);
00840     }
00841 
00842 
00843   template<typename, typename>
00844     struct __lc_rai
00845     {
00846       template<typename _II1, typename _II2>
00847         static _II1
00848         __newlast1(_II1, _II1 __last1, _II2, _II2)
00849         { return __last1; }
00850 
00851       template<typename _II>
00852         static bool
00853         __cnd2(_II __first, _II __last)
00854         { return __first != __last; }
00855     };
00856 
00857   template<>
00858     struct __lc_rai<random_access_iterator_tag, random_access_iterator_tag>
00859     {
00860       template<typename _RAI1, typename _RAI2>
00861         static _RAI1
00862         __newlast1(_RAI1 __first1, _RAI1 __last1,
00863            _RAI2 __first2, _RAI2 __last2)
00864         {
00865       const typename iterator_traits<_RAI1>::difference_type
00866         __diff1 = __last1 - __first1;
00867       const typename iterator_traits<_RAI2>::difference_type
00868         __diff2 = __last2 - __first2;
00869       return __diff2 < __diff1 ? __first1 + __diff2 : __last1;
00870     }
00871 
00872       template<typename _RAI>
00873         static bool
00874         __cnd2(_RAI, _RAI)
00875         { return true; }
00876     };
00877 
00878   template<bool _BoolType>
00879     struct __lexicographical_compare
00880     {
00881       template<typename _II1, typename _II2>
00882         static bool __lc(_II1, _II1, _II2, _II2);
00883     };
00884 
00885   template<bool _BoolType>
00886     template<typename _II1, typename _II2>
00887       bool
00888       __lexicographical_compare<_BoolType>::
00889       __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
00890       {
00891     typedef typename iterator_traits<_II1>::iterator_category _Category1;
00892     typedef typename iterator_traits<_II2>::iterator_category _Category2;
00893     typedef std::__lc_rai<_Category1, _Category2>   __rai_type;
00894     
00895     __last1 = __rai_type::__newlast1(__first1, __last1,
00896                      __first2, __last2);
00897     for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
00898          ++__first1, ++__first2)
00899       {
00900         if (*__first1 < *__first2)
00901           return true;
00902         if (*__first2 < *__first1)
00903           return false;
00904       }
00905     return __first1 == __last1 && __first2 != __last2;
00906       }
00907 
00908   template<>
00909     struct __lexicographical_compare<true>
00910     {
00911       template<typename _Tp, typename _Up>
00912         static bool
00913         __lc(const _Tp* __first1, const _Tp* __last1,
00914          const _Up* __first2, const _Up* __last2)
00915     {
00916       const size_t __len1 = __last1 - __first1;
00917       const size_t __len2 = __last2 - __first2;
00918       const int __result = __builtin_memcmp(__first1, __first2,
00919                         std::min(__len1, __len2));
00920       return __result != 0 ? __result < 0 : __len1 < __len2;
00921     }
00922     };
00923 
00924   template<typename _II1, typename _II2>
00925     inline bool
00926     __lexicographical_compare_aux(_II1 __first1, _II1 __last1,
00927                   _II2 __first2, _II2 __last2)
00928     {
00929       typedef typename iterator_traits<_II1>::value_type _ValueType1;
00930       typedef typename iterator_traits<_II2>::value_type _ValueType2;
00931       const bool __simple =
00932     (__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value
00933      && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed
00934      && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed
00935      && __is_pointer<_II1>::__value
00936      && __is_pointer<_II2>::__value);
00937 
00938       return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
00939                                 __first2, __last2);
00940     }
00941 
00942   /**
00943    *  @brief Finds the first position in which @a val could be inserted
00944    *         without changing the ordering.
00945    *  @param  first   An iterator.
00946    *  @param  last    Another iterator.
00947    *  @param  val     The search term.
00948    *  @return         An iterator pointing to the first element <em>not less
00949    *                  than</em> @a val, or end() if every element is less than 
00950    *                  @a val.
00951    *  @ingroup binary_search_algorithms
00952   */
00953   template<typename _ForwardIterator, typename _Tp>
00954     _ForwardIterator
00955     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
00956         const _Tp& __val)
00957     {
00958       typedef typename iterator_traits<_ForwardIterator>::value_type
00959     _ValueType;
00960       typedef typename iterator_traits<_ForwardIterator>::difference_type
00961     _DistanceType;
00962 
00963       // concept requirements
00964       __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
00965       __glibcxx_function_requires(_LessThanOpConcept<_ValueType, _Tp>)
00966       __glibcxx_requires_partitioned_lower(__first, __last, __val);
00967 
00968       _DistanceType __len = std::distance(__first, __last);
00969       _DistanceType __half;
00970       _ForwardIterator __middle;
00971 
00972       while (__len > 0)
00973     {
00974       __half = __len >> 1;
00975       __middle = __first;
00976       std::advance(__middle, __half);
00977       if (*__middle < __val)
00978         {
00979           __first = __middle;
00980           ++__first;
00981           __len = __len - __half - 1;
00982         }
00983       else
00984         __len = __half;
00985     }
00986       return __first;
00987     }
00988 
00989   /// This is a helper function for the sort routines and for random.tcc.
00990   //  Precondition: __n > 0.
00991   template<typename _Size>
00992     inline _Size
00993     __lg(_Size __n)
00994     {
00995       _Size __k;
00996       for (__k = 0; __n != 0; __n >>= 1)
00997     ++__k;
00998       return __k - 1;
00999     }
01000 
01001   inline int
01002   __lg(int __n)
01003   { return sizeof(int) * __CHAR_BIT__  - 1 - __builtin_clz(__n); }
01004 
01005   inline long
01006   __lg(long __n)
01007   { return sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }
01008 
01009   inline long long
01010   __lg(long long __n)
01011   { return sizeof(long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
01012 
01013 _GLIBCXX_END_NAMESPACE
01014 
01015 _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P)
01016 
01017   /**
01018    *  @brief Tests a range for element-wise equality.
01019    *  @ingroup non_mutating_algorithms
01020    *  @param  first1  An input iterator.
01021    *  @param  last1   An input iterator.
01022    *  @param  first2  An input iterator.
01023    *  @return   A boolean true or false.
01024    *
01025    *  This compares the elements of two ranges using @c == and returns true or
01026    *  false depending on whether all of the corresponding elements of the
01027    *  ranges are equal.
01028   */
01029   template<typename _II1, typename _II2>
01030     inline bool
01031     equal(_II1 __first1, _II1 __last1, _II2 __first2)
01032     {
01033       // concept requirements
01034       __glibcxx_function_requires(_InputIteratorConcept<_II1>)
01035       __glibcxx_function_requires(_InputIteratorConcept<_II2>)
01036       __glibcxx_function_requires(_EqualOpConcept<
01037         typename iterator_traits<_II1>::value_type,
01038         typename iterator_traits<_II2>::value_type>)
01039       __glibcxx_requires_valid_range(__first1, __last1);
01040 
01041       return std::__equal_aux(std::__niter_base(__first1),
01042                   std::__niter_base(__last1),
01043                   std::__niter_base(__first2));
01044     }
01045 
01046   /**
01047    *  @brief Tests a range for element-wise equality.
01048    *  @ingroup non_mutating_algorithms
01049    *  @param  first1  An input iterator.
01050    *  @param  last1   An input iterator.
01051    *  @param  first2  An input iterator.
01052    *  @param binary_pred A binary predicate @link functors
01053    *                  functor@endlink.
01054    *  @return         A boolean true or false.
01055    *
01056    *  This compares the elements of two ranges using the binary_pred
01057    *  parameter, and returns true or
01058    *  false depending on whether all of the corresponding elements of the
01059    *  ranges are equal.
01060   */
01061   template<typename _IIter1, typename _IIter2, typename _BinaryPredicate>
01062     inline bool
01063     equal(_IIter1 __first1, _IIter1 __last1,
01064       _IIter2 __first2, _BinaryPredicate __binary_pred)
01065     {
01066       // concept requirements
01067       __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
01068       __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
01069       __glibcxx_requires_valid_range(__first1, __last1);
01070 
01071       for (; __first1 != __last1; ++__first1, ++__first2)
01072     if (!bool(__binary_pred(*__first1, *__first2)))
01073       return false;
01074       return true;
01075     }
01076 
01077   /**
01078    *  @brief Performs @b dictionary comparison on ranges.
01079    *  @ingroup sorting_algorithms
01080    *  @param  first1  An input iterator.
01081    *  @param  last1   An input iterator.
01082    *  @param  first2  An input iterator.
01083    *  @param  last2   An input iterator.
01084    *  @return   A boolean true or false.
01085    *
01086    *  <em>Returns true if the sequence of elements defined by the range
01087    *  [first1,last1) is lexicographically less than the sequence of elements
01088    *  defined by the range [first2,last2).  Returns false otherwise.</em>
01089    *  (Quoted from [25.3.8]/1.)  If the iterators are all character pointers,
01090    *  then this is an inline call to @c memcmp.
01091   */
01092   template<typename _II1, typename _II2>
01093     inline bool
01094     lexicographical_compare(_II1 __first1, _II1 __last1,
01095                 _II2 __first2, _II2 __last2)
01096     {
01097       // concept requirements
01098       typedef typename iterator_traits<_II1>::value_type _ValueType1;
01099       typedef typename iterator_traits<_II2>::value_type _ValueType2;
01100       __glibcxx_function_requires(_InputIteratorConcept<_II1>)
01101       __glibcxx_function_requires(_InputIteratorConcept<_II2>)
01102       __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
01103       __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
01104       __glibcxx_requires_valid_range(__first1, __last1);
01105       __glibcxx_requires_valid_range(__first2, __last2);
01106 
01107       return std::__lexicographical_compare_aux(std::__niter_base(__first1),
01108                         std::__niter_base(__last1),
01109                         std::__niter_base(__first2),
01110                         std::__niter_base(__last2));
01111     }
01112 
01113   /**
01114    *  @brief Performs @b dictionary comparison on ranges.
01115    *  @ingroup sorting_algorithms
01116    *  @param  first1  An input iterator.
01117    *  @param  last1   An input iterator.
01118    *  @param  first2  An input iterator.
01119    *  @param  last2   An input iterator.
01120    *  @param  comp  A @link comparison_functors comparison functor@endlink.
01121    *  @return   A boolean true or false.
01122    *
01123    *  The same as the four-parameter @c lexicographical_compare, but uses the
01124    *  comp parameter instead of @c <.
01125   */
01126   template<typename _II1, typename _II2, typename _Compare>
01127     bool
01128     lexicographical_compare(_II1 __first1, _II1 __last1,
01129                 _II2 __first2, _II2 __last2, _Compare __comp)
01130     {
01131       typedef typename iterator_traits<_II1>::iterator_category _Category1;
01132       typedef typename iterator_traits<_II2>::iterator_category _Category2;
01133       typedef std::__lc_rai<_Category1, _Category2>     __rai_type;
01134 
01135       // concept requirements
01136       __glibcxx_function_requires(_InputIteratorConcept<_II1>)
01137       __glibcxx_function_requires(_InputIteratorConcept<_II2>)
01138       __glibcxx_requires_valid_range(__first1, __last1);
01139       __glibcxx_requires_valid_range(__first2, __last2);
01140 
01141       __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2);
01142       for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
01143        ++__first1, ++__first2)
01144     {
01145       if (__comp(*__first1, *__first2))
01146         return true;
01147       if (__comp(*__first2, *__first1))
01148         return false;
01149     }
01150       return __first1 == __last1 && __first2 != __last2;
01151     }
01152 
01153   /**
01154    *  @brief Finds the places in ranges which don't match.
01155    *  @ingroup non_mutating_algorithms
01156    *  @param  first1  An input iterator.
01157    *  @param  last1   An input iterator.
01158    *  @param  first2  An input iterator.
01159    *  @return   A pair of iterators pointing to the first mismatch.
01160    *
01161    *  This compares the elements of two ranges using @c == and returns a pair
01162    *  of iterators.  The first iterator points into the first range, the
01163    *  second iterator points into the second range, and the elements pointed
01164    *  to by the iterators are not equal.
01165   */
01166   template<typename _InputIterator1, typename _InputIterator2>
01167     pair<_InputIterator1, _InputIterator2>
01168     mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
01169          _InputIterator2 __first2)
01170     {
01171       // concept requirements
01172       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
01173       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
01174       __glibcxx_function_requires(_EqualOpConcept<
01175         typename iterator_traits<_InputIterator1>::value_type,
01176         typename iterator_traits<_InputIterator2>::value_type>)
01177       __glibcxx_requires_valid_range(__first1, __last1);
01178 
01179       while (__first1 != __last1 && *__first1 == *__first2)
01180         {
01181       ++__first1;
01182       ++__first2;
01183         }
01184       return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
01185     }
01186 
01187   /**
01188    *  @brief Finds the places in ranges which don't match.
01189    *  @ingroup non_mutating_algorithms
01190    *  @param  first1  An input iterator.
01191    *  @param  last1   An input iterator.
01192    *  @param  first2  An input iterator.
01193    *  @param binary_pred A binary predicate @link functors
01194    *         functor@endlink.
01195    *  @return   A pair of iterators pointing to the first mismatch.
01196    *
01197    *  This compares the elements of two ranges using the binary_pred
01198    *  parameter, and returns a pair
01199    *  of iterators.  The first iterator points into the first range, the
01200    *  second iterator points into the second range, and the elements pointed
01201    *  to by the iterators are not equal.
01202   */
01203   template<typename _InputIterator1, typename _InputIterator2,
01204        typename _BinaryPredicate>
01205     pair<_InputIterator1, _InputIterator2>
01206     mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
01207          _InputIterator2 __first2, _BinaryPredicate __binary_pred)
01208     {
01209       // concept requirements
01210       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
01211       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
01212       __glibcxx_requires_valid_range(__first1, __last1);
01213 
01214       while (__first1 != __last1 && bool(__binary_pred(*__first1, *__first2)))
01215         {
01216       ++__first1;
01217       ++__first2;
01218         }
01219       return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
01220     }
01221 
01222 _GLIBCXX_END_NESTED_NAMESPACE
01223 
01224 // NB: This file is included within many other C++ includes, as a way
01225 // of getting the base algorithms. So, make sure that parallel bits
01226 // come in too if requested. 
01227 #ifdef _GLIBCXX_PARALLEL
01228 # include <parallel/algobase.h>
01229 #endif
01230 
01231 #endif