This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

debug algo patch


Hi

Here is an evolution in management of debug algos I would like to propose for a future version. The attached patch does 3 things:
- Move algos implementation details in std::__detail namespace so that whatever mode (none/debug/profile/parallel) is activated those details will always be found in the same namespace
- Introduce real debug algos in std::__debug namespace
- Generalize usage of __gnu_debug::__safe method that limit performance impact of debug mode


I hope this patch to:
- Clean code: debug stuff will be isolated in include/debug folder and won't pollute anymore normal implementations in include/bits. This is especially important with the introduction of calls to __gnu_debug::__base
- Optimize debug performances because for the moment some debug algos or containers might have been calling internally other debug algos without knowing it and performing useless checks.


For the moment this patch doesn't work in debug mode because of ambiguity when resolving algo calls as soon as debug containers are involved; std::__debug is considered thanks to namespace inlinement and std::__cxx1998 is considered because of ADL as debug containers are inheriting from normal ones that are in __cxx1998 namespace. I have plan to remove this inheritance relation if the patch suite you well.

I have also restore the possibility to use both parallel and debug mode at the same time, I don't think there were a real reason to have remove this possibility. Note that when both modes are active we could also offer debug version of parallel specific algos, maybe one day.

In debug code I use a _GLIBCXX_BASE_A to define the base namespace to target to find underlying algos implementation. In normal mode you will see usage of _GLIBCXX_PARALLEL_A. I am not happy with this name because in fact it might not be a parallel algo at all, when parallel mode is not active it will be the normal algo. I simply wanted to explicitly avoid usage of the debug algos, it will have to be enhance for the final patch.

Note also that we could also got a step further in seggregation of code by moving concept checks outside normal algos implementation. We could have all algos defined directly into std namespace and then have an internal namespace with __debug, __parallel, __profile in it and one inlined depending on activated mode. This would have the advantage of:
- always consider concept checks first, so consistent error reporting whatever mode is activated or not
- avoid concept checks on internal algos usage


I am considering to start the SVN binary incompatible branch with this patch as soon as it works.

Regards

Index: include/Makefile.in
===================================================================
--- include/Makefile.in	(revision 173802)
+++ include/Makefile.in	(working copy)
@@ -945,18 +945,24 @@
 debug_srcdir = ${glibcxx_srcdir}/include/debug
 debug_builddir = ./debug
 debug_headers = \
+	${debug_srcdir}/algorithm \
+	${debug_srcdir}/algo.h \
+	${debug_srcdir}/algobase.h \
 	${debug_srcdir}/bitset \
 	${debug_srcdir}/debug.h \
 	${debug_srcdir}/deque \
 	${debug_srcdir}/formatter.h \
 	${debug_srcdir}/forward_list \
 	${debug_srcdir}/functions.h \
+	${debug_srcdir}/heap.h \
 	${debug_srcdir}/list \
 	${debug_srcdir}/map \
 	${debug_srcdir}/macros.h \
 	${debug_srcdir}/map.h \
 	${debug_srcdir}/multimap.h \
 	${debug_srcdir}/multiset.h \
+	${debug_srcdir}/numeric \
+	${debug_srcdir}/numeric.h \
 	${debug_srcdir}/safe_base.h \
 	${debug_srcdir}/safe_iterator.h \
 	${debug_srcdir}/safe_iterator.tcc \
@@ -991,6 +997,7 @@
 @ENABLE_PARALLEL_TRUE@        ${parallel_srcdir}/find_selectors.h \
 @ENABLE_PARALLEL_TRUE@        ${parallel_srcdir}/for_each.h \
 @ENABLE_PARALLEL_TRUE@        ${parallel_srcdir}/for_each_selectors.h \
+@ENABLE_PARALLEL_TRUE@        ${parallel_srcdir}/heap.h \
 @ENABLE_PARALLEL_TRUE@        ${parallel_srcdir}/iterator.h \
 @ENABLE_PARALLEL_TRUE@        ${parallel_srcdir}/list_partition.h \
 @ENABLE_PARALLEL_TRUE@        ${parallel_srcdir}/losertree.h \
Index: include/debug/algorithm
===================================================================
--- include/debug/algorithm	(revision 0)
+++ include/debug/algorithm	(revision 0)
@@ -0,0 +1,40 @@
+// Algorithm extensions -*- C++ -*-
+
+// Copyright (C) 2007, 2009
+// 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file debug/algorithm
+ *  This file is a GNU extension to the Standard C++ Library.
+ */
+
+#ifndef _GLIBCXX_DEBUG_ALGORITHM
+#define _GLIBCXX_DEBUG_ALGORITHM 1
+
+#pragma GCC system_header
+
+#include <algorithm>
+#include <debug/algobase.h>
+#include <debug/algo.h>
+#include <debug/heap.h>
+
+#endif
Index: include/debug/numeric.h
===================================================================
--- include/debug/numeric.h	(revision 0)
+++ include/debug/numeric.h	(revision 0)
@@ -0,0 +1,144 @@
+// -*- C++ -*-
+
+// Copyright (C) 2011 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 terms
+// of the GNU General Public License as published by the Free Software
+// Foundation; either version 3, or (at your option) any later
+// version.
+
+// This library is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
+
+/**
+ * @file debug/numeric
+*
+ *  This file is a GNU debug extension to the Standard C++ Library.
+ */
+
+#ifndef _GLIBCXX_DEBUG_NUMERIC_H
+#define _GLIBCXX_DEBUG_NUMERIC_H 1
+
+#include <debug/safe_iterator.h>
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+namespace __debug
+{
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  template<typename _ForwardIterator, typename _Tp>
+    void
+    iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      _GLIBCXX_BASE_A::iota(__gnu_debug::__base(__first),
+			    __gnu_debug::__base(__last), __value);
+    }
+#endif
+
+  template<typename _IIter, typename _Tp>
+    inline _Tp
+    accumulate(_IIter __begin, _IIter __end, _Tp __init)
+    {
+      __glibcxx_check_valid_range(__begin, __end);
+      return _GLIBCXX_BASE_A::accumulate(__gnu_debug::__base(__begin),
+					 __gnu_debug::__base(__end),
+					 __init);
+    }
+
+  template<typename _IIter, typename _Tp, typename _BinaryOperation>
+    inline _Tp
+    accumulate(_IIter __begin, _IIter __end, _Tp __init, 
+               _BinaryOperation __binary_op) 
+    {
+      __glibcxx_check_valid_range(__begin, __end);
+      return _GLIBCXX_BASE_A::accumulate(__gnu_debug::__base(__begin),
+					 __gnu_debug::__base(__end),
+					 __init, __binary_op);
+    }
+
+  template<typename _IIter1, typename _IIter2, typename _Tp>
+    inline _Tp
+    inner_product(_IIter1 __first1, _IIter1 __last1, 
+                  _IIter2 __first2, _Tp __init)
+    {
+      __glibcxx_check_valid_range(__first1, __last1);
+      return _GLIBCXX_BASE_A::inner_product(__gnu_debug::__base(__first1),
+					    __gnu_debug::__base(__first2),
+					    __first2, __init);
+    }
+
+  template<typename _IIter1, typename _IIter2, typename _Tp,
+           typename _BinaryFunction1, typename _BinaryFunction2>
+    inline _Tp
+    inner_product(_IIter1 __first1, _IIter1 __last1, 
+                  _IIter2 __first2, _Tp __init, _BinaryFunction1 __binary_op1, 
+                  _BinaryFunction2 __binary_op2)
+    {
+      __glibcxx_check_valid_range(__first1, __last1);
+      return _GLIBCXX_BASE_A::inner_product(__gnu_debug::__base(__first1),
+					    __gnu_debug::__base(__first2),
+					    __first2, __init,
+					    __binary_op1, __binary_op2);
+    }
+
+  template<typename _IIter, typename _OutputIterator>
+    inline _OutputIterator
+    partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result)
+    {
+      __glibcxx_check_valid_range(__begin, __end);
+      return _GLIBCXX_BASE_A::partial_sum(__gnu_debug::__base(__begin),
+					  __gnu_debug::__base(__end),
+					  __result);
+    }
+
+  template<typename _IIter, typename _OutputIterator,
+           typename _BinaryOperation>
+    inline _OutputIterator
+    partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result,
+                _BinaryOperation __binary_op)
+    {
+      __glibcxx_check_valid_range(__begin, __end);
+      return _GLIBCXX_BASE_A::partial_sum(__gnu_debug::__base(__begin),
+					  __gnu_debug::__base(__end),
+					  __result, __binary_op);
+    }
+
+  template<typename _IIter, typename _OutputIterator>
+    inline _OutputIterator
+    adjacent_difference(_IIter __begin, _IIter __end,
+                        _OutputIterator __result)
+    {
+      __glibcxx_check_valid_range(__begin, __end);
+      return _GLIBCXX_BASE_A::adjacent_difference(__gnu_debug::__base(__begin),
+						  __gnu_debug::__base(__end),
+						  __result);
+    }
+
+  template<typename _IIter, typename _OutputIterator,
+	   typename _BinaryOperation>
+    inline _OutputIterator
+    adjacent_difference(_IIter __begin, _IIter __end,
+			_OutputIterator __result, _BinaryOperation __binary_op)
+    {
+      __glibcxx_check_valid_range(__begin, __end);
+      return _GLIBCXX_BASE_A::adjacent_difference(__gnu_debug::__base(__begin),
+						  __gnu_debug::__base(__end),
+						  __result, __binary_op);
+    }
+} // end namespace
+} // end namespace
+
+#endif

Property changes on: include/debug/numeric.h
___________________________________________________________________
Added: svn:eol-style
   + native

Index: include/debug/numeric
===================================================================
--- include/debug/numeric	(revision 0)
+++ include/debug/numeric	(revision 0)
@@ -0,0 +1,37 @@
+// <numeric> -*- C++ -*-
+
+// Copyright (C) 2011 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file debug/numeric
+ *  This file is a GNU extension to the Standard C++ Library.
+ */
+
+#ifndef _GLIBCXX_DEBUG_NUMERIC
+#define _GLIBCXX_DEBUG_NUMERIC 1
+
+#pragma GCC system_header
+
+#include <numeric>
+#include <debug/numeric.h>
+
+#endif
Index: include/debug/heap.h
===================================================================
--- include/debug/heap.h	(revision 0)
+++ include/debug/heap.h	(revision 0)
@@ -0,0 +1,164 @@
+// Heap implementation -*- C++ -*-
+
+// Copyright (C) 2011 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file debug/heap.h
+ *  This is an internal header file, included by other library headers.
+ *  Do not attempt to use it directly. @headername{queue}
+ */
+
+#ifndef _GLIBCXX_DEBUG_HEAP_H
+#define _GLIBCXX_DEBUG_HEAP_H 1
+
+#include <debug/debug.h>
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+namespace __debug
+{
+  template<typename _RandomAccessIterator>
+    inline void
+    push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      __glibcxx_check_heap(__first, __last - 1);      
+      _GLIBCXX_BASE_A::push_heap(__gnu_debug::__base(__first),
+				 __gnu_debug::__base(__last));
+    }
+
+  template<typename _RandomAccessIterator, typename _Compare>
+    inline void
+    push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
+	      _Compare __comp)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      __glibcxx_check_heap_pred(__first, __last - 1, __comp);      
+      _GLIBCXX_BASE_A::push_heap(__gnu_debug::__base(__first),
+				 __gnu_debug::__base(__last), __comp);
+    }
+
+  template<typename _RandomAccessIterator>
+    inline void
+    pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      __glibcxx_check_heap(__first, __last);      
+      _GLIBCXX_BASE_A::pop_heap(__gnu_debug::__base(__first),
+				__gnu_debug::__base(__last));
+    }
+
+  template<typename _RandomAccessIterator, typename _Compare>
+    inline void
+    pop_heap(_RandomAccessIterator __first,
+	     _RandomAccessIterator __last, _Compare __comp)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      __glibcxx_check_heap_pred(__first, __last, __comp);
+      _GLIBCXX_BASE_A::pop_heap(__gnu_debug::__base(__first),
+				__gnu_debug::__base(__last), __comp);
+    }
+
+  template<typename _RandomAccessIterator>
+    void
+    make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      _GLIBCXX_BASE_A::make_heap(__gnu_debug::__base(__first),
+				 __gnu_debug::__base(__last));
+    }
+
+  template<typename _RandomAccessIterator, typename _Compare>
+    void
+    make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
+	      _Compare __comp)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      _GLIBCXX_BASE_A::make_heap(__gnu_debug::__base(__first),
+				 __gnu_debug::__base(__last), __comp);
+    }
+
+  template<typename _RandomAccessIterator>
+    void
+    sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      _GLIBCXX_BASE_A::sort_heap(__gnu_debug::__base(__first),
+				 __gnu_debug::__base(__last));
+    }
+
+  template<typename _RandomAccessIterator, typename _Compare>
+    void
+    sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
+	      _Compare __comp)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      _GLIBCXX_BASE_A::sort_heap(__gnu_debug::__base(__first),
+				 __gnu_debug::__base(__last), __comp);
+    }
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  template<typename _RandomAccessIterator>
+    inline _RandomAccessIterator
+    is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::is_heap_until(__gnu_debug::__base(__first),
+					      __gnu_debug::__base(__last)));
+    }
+
+  template<typename _RandomAccessIterator, typename _Compare>
+    inline _RandomAccessIterator
+    is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last,
+		  _Compare __comp)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::is_heap_until(__gnu_debug::__base(__first),
+					      __gnu_debug::__base(__last),
+					      __comp));
+    }
+
+  template<typename _RandomAccessIterator>
+    inline bool
+    is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::is_heap(__gnu_debug::__base(__first),
+				      __gnu_debug::__base(__last));
+    }
+
+  template<typename _RandomAccessIterator, typename _Compare>
+    inline bool
+    is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
+	    _Compare __comp)
+    { 
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::is_heap(__gnu_debug::__base(__first),
+				      __gnu_debug::__base(__last), __comp);
+    }
+#endif
+} // namespace __parallel
+} // namespace
+
+#endif

Property changes on: include/debug/heap.h
___________________________________________________________________
Added: svn:eol-style
   + native

Index: include/debug/algobase.h
===================================================================
--- include/debug/algobase.h	(revision 0)
+++ include/debug/algobase.h	(revision 0)
@@ -0,0 +1,200 @@
+// Core algorithmic facilities -*- C++ -*-
+
+// Copyright (C) 2011 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file debug/algobase.h
+ *  This is an internal header file, included by other library headers.
+ *  Do not attempt to use it directly. @headername{algorithm}
+ */
+
+#ifndef _GLIBCXX_DEBUG_ALGOBASE_H
+#define _GLIBCXX_DEBUG_ALGOBASE_H 1
+
+#include <debug/safe_iterator.h>
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+namespace __debug
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+  template<typename _ForwardIterator1, typename _ForwardIterator2>
+    _ForwardIterator2
+    swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+		_ForwardIterator2 __first2)
+    {
+      __glibcxx_check_valid_range(__first1, __last1);
+      return _GLIBCXX_BASE_A::swap_ranges(__gnu_debug::__base(__first1),
+					  __gnu_debug::__base(__last1),
+					  __first2);
+    }
+
+  template<typename _II, typename _OI>
+    inline _OI
+    copy(_II __first, _II __last, _OI __result)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::copy(__gnu_debug::__base(__first),
+				   __gnu_debug::__base(__last),
+				   __result);
+    }
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  template<typename _II, typename _OI>
+    inline _OI
+    move(_II __first, _II __last, _OI __result)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::move(__gnu_debug::__base(__first),
+				   __gnu_debug::__base(__last),
+				   __result);
+    }
+#endif
+
+  template<typename _BI1, typename _BI2>
+    inline _BI2
+    copy_backward(_BI1 __first, _BI1 __last, _BI2 __result)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::copy_backward(__gnu_debug::__base(__first),
+					    __gnu_debug::__base(__last),
+					    __result);
+    }
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  template<typename _BI1, typename _BI2>
+    inline _BI2
+    move_backward(_BI1 __first, _BI1 __last, _BI2 __result)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::move_backward(__gnu_debug::__base(__first),
+					    __gnu_debug::__base(__last),
+					    __result);
+    }
+#endif
+
+  template<typename _ForwardIterator, typename _Tp>
+    inline void
+    fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      _GLIBCXX_BASE_A::fill(__gnu_debug::__base(__first),
+			    __gnu_debug::__base(__last), __value);
+    }
+
+  template<typename _ForwardIterator, typename _Tp>
+    _ForwardIterator
+    lower_bound(_ForwardIterator __first, _ForwardIterator __last,
+		const _Tp& __val)
+    {
+      __glibcxx_check_partitioned_lower(__first, __last, __val);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::lower_bound(__gnu_debug::__base(__first),
+					    __gnu_debug::__base(__last),
+					    __val));
+    }
+
+  template<typename _II1, typename _II2>
+    inline bool
+    equal(_II1 __first1, _II1 __last1, _II2 __first2)
+    {
+      __glibcxx_check_valid_range(__first1, __last1);
+      return _GLIBCXX_BASE_A::equal(__gnu_debug::__base(__first1),
+				    __gnu_debug::__base(__last1),
+				    __first2);
+    }
+
+  template<typename _IIter1, typename _IIter2, typename _BinaryPredicate>
+    inline bool
+    equal(_IIter1 __first1, _IIter1 __last1,
+	  _IIter2 __first2, _BinaryPredicate __binary_pred)
+    {
+      __glibcxx_check_valid_range(__first1, __last1);
+      return _GLIBCXX_BASE_A::equal(__gnu_debug::__base(__first1),
+				    __gnu_debug::__base(__last1),
+				    __first2, __binary_pred);
+    }
+
+  template<typename _II1, typename _II2>
+    inline bool
+    lexicographical_compare(_II1 __first1, _II1 __last1,
+			    _II2 __first2, _II2 __last2)
+    {
+      __glibcxx_check_valid_range(__first1, __last1);
+      __glibcxx_check_valid_range(__first2, __last2);
+      return _GLIBCXX_BASE_A::lexicographical_compare(
+		__gnu_debug::__base(__first1), __gnu_debug::__base(__last1),
+		__gnu_debug::__base(__first2), __gnu_debug::__base(__last2));
+    }
+
+  template<typename _II1, typename _II2, typename _Compare>
+    bool
+    lexicographical_compare(_II1 __first1, _II1 __last1,
+			    _II2 __first2, _II2 __last2, _Compare __comp)
+    {
+      __glibcxx_check_valid_range(__first1, __last1);
+      __glibcxx_check_valid_range(__first2, __last2);
+      return _GLIBCXX_BASE_A::lexicographical_compare(
+		__gnu_debug::__base(__first1), __gnu_debug::__base(__last1),
+		__gnu_debug::__base(__first2), __gnu_debug::__base(__last2),
+		__comp);
+    }
+
+  template<typename _InputIterator1, typename _InputIterator2>
+    pair<_InputIterator1, _InputIterator2>
+    mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
+	     _InputIterator2 __first2)
+    {
+      __glibcxx_check_valid_range(__first1, __last1);
+      typedef __gnu_debug::_Siter_base<_InputIterator1> _SiterBase;
+      typedef typename _SiterBase::iterator_type _UnsafeIt;
+      std::pair<_UnsafeIt, _InputIterator2> __ret =
+	_GLIBCXX_BASE_A::mismatch(__gnu_debug::__base(__first1),
+				  __gnu_debug::__base(__last1),
+				  __first2);
+      return std::make_pair(__gnu_debug::__safe(__first1, __ret.first),
+			    __ret.second);
+    }
+
+  template<typename _InputIterator1, typename _InputIterator2,
+	   typename _BinaryPredicate>
+    pair<_InputIterator1, _InputIterator2>
+    mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
+	     _InputIterator2 __first2, _BinaryPredicate __binary_pred)
+    {
+      __glibcxx_check_valid_range(__first1, __last1);
+      typedef __gnu_debug::_Siter_base<_InputIterator1> _SiterBase;
+      typedef typename _SiterBase::iterator_type _UnsafeIt;
+      std::pair<_UnsafeIt, _InputIterator2> __ret =
+	_GLIBCXX_BASE_A::mismatch(__gnu_debug::__base(__first1),
+				  __gnu_debug::__base(__last1),
+				  __first2, __binary_pred);
+      return std::make_pair(__gnu_debug::__safe(__first1, __ret.first),
+			    __ret.second);
+    }
+
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace __debug
+} // namespace std
+
+#endif

Property changes on: include/debug/algobase.h
___________________________________________________________________
Added: svn:eol-style
   + native

Index: include/debug/algo.h
===================================================================
--- include/debug/algo.h	(revision 0)
+++ include/debug/algo.h	(revision 0)
@@ -0,0 +1,1248 @@
+// Algorithm implementation -*- C++ -*-
+
+// Copyright (C) 2011 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file debug/algo.h
+ *  This is an internal header file, included by other library headers.
+ *  Do not attempt to use it directly. @headername{algorithm}
+ */
+
+#ifndef _GLIBCXX_DEBUG_ALGO_H
+#define _GLIBCXX_DEBUG_ALGO_H 1
+
+#include <debug/safe_iterator.h>
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+namespace __debug
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+  template<typename _ForwardIterator1, typename _ForwardIterator2>
+    inline _ForwardIterator1
+    find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+	     _ForwardIterator2 __first2, _ForwardIterator2 __last2)
+    {
+      __glibcxx_check_valid_range(__first1, __last1);
+      __glibcxx_check_valid_range(__first2, __last2);
+      return __gnu_debug::__safe(__first1,
+	       _GLIBCXX_BASE_A::find_end(__gnu_debug::__base(__first1),
+					 __gnu_debug::__base(__last1),
+					 __gnu_debug::__base(__first2),
+					 __gnu_debug::__base(__last2)));
+    }
+
+  template<typename _ForwardIterator1, typename _ForwardIterator2,
+	   typename _BinaryPredicate>
+    inline _ForwardIterator1
+    find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+	     _ForwardIterator2 __first2, _ForwardIterator2 __last2,
+	     _BinaryPredicate __comp)
+    {
+      __glibcxx_check_valid_range(__first1, __last1);
+      __glibcxx_check_valid_range(__first2, __last2);
+
+      return __gnu_debug::__safe(__first1,
+	       _GLIBCXX_BASE_A::find_end(__gnu_debug::__base(__first1),
+					 __gnu_debug::__base(__last1),
+					 __gnu_debug::__base(__first2),
+					 __gnu_debug::__base(__last2),
+					 __comp));
+    }
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  template<typename _InputIterator, typename _Predicate>
+    inline bool
+    all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::all_of(__gnu_debug::__base(__first),
+				     __gnu_debug::__base(__last), __pred);
+    }
+
+  template<typename _InputIterator, typename _Predicate>
+    inline bool
+    none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::none_of(__gnu_debug::__base(__first),
+				      __gnu_debug::__base(__last), __pred);
+    }
+
+  template<typename _InputIterator, typename _Predicate>
+    inline bool
+    any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::any_of(__gnu_debug::__base(__first),
+				     __gnu_debug::__base(__last), __pred);
+    }
+
+  template<typename _InputIterator, typename _Predicate>
+    inline _InputIterator
+    find_if_not(_InputIterator __first, _InputIterator __last,
+		_Predicate __pred)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::find_if_not(__gnu_debug::__base(__first),
+					    __gnu_debug::__base(__last),
+					    __pred));
+    }
+
+  template<typename _InputIterator, typename _Predicate>
+    inline bool
+    is_partitioned(_InputIterator __first, _InputIterator __last,
+		   _Predicate __pred)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::is_partitioned(__gnu_debug::__base(__first),
+					     __gnu_debug::__base(__last),
+					     __pred);
+    }
+
+  template<typename _ForwardIterator, typename _Predicate>
+    _ForwardIterator
+    partition_point(_ForwardIterator __first, _ForwardIterator __last,
+		    _Predicate __pred)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe_(__first,
+	       _GLIBCXX_BASE_A::partition_point(__gnu_debug::__base(__first),
+						__gnu_debug::__base(__last),
+						__pred));
+    }
+#endif
+
+  template<typename _InputIterator, typename _OutputIterator, typename _Tp>
+    _OutputIterator
+    remove_copy(_InputIterator __first, _InputIterator __last,
+		_OutputIterator __result, const _Tp& __value)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::remove_copy(__gnu_debug::__base(__first),
+					  __gnu_debug::__base(__last),
+					  __result, __value);
+    }
+
+  template<typename _InputIterator, typename _OutputIterator,
+	   typename _Predicate>
+    _OutputIterator
+    remove_copy_if(_InputIterator __first, _InputIterator __last,
+		   _OutputIterator __result, _Predicate __pred)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::remove_copy_if(__gnu_debug::__base(__first),
+					     __gnu_debug::__base(__last),
+					     __result, __pred);
+    }
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  template<typename _InputIterator, typename _OutputIterator,
+	   typename _Predicate>
+    _OutputIterator
+    copy_if(_InputIterator __first, _InputIterator __last,
+	    _OutputIterator __result, _Predicate __pred)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::copy_if(__gnu_debug::__base(__first),
+				      __gnu_debug::__base(__last),
+				      __result, __pred);
+    }
+
+  template<typename _InputIterator, typename _Size, typename _OutputIterator>
+    inline _OutputIterator
+    copy_n(_InputIterator __first, _Size __n, _OutputIterator __result)
+    {
+      return _GLIBCXX_BASE_A::copy_n(__first, __n, __result);
+    }
+
+  template<typename _InputIterator, typename _OutputIterator1,
+	   typename _OutputIterator2, typename _Predicate>
+    pair<_OutputIterator1, _OutputIterator2>
+    partition_copy(_InputIterator __first, _InputIterator __last,
+		   _OutputIterator1 __out_true, _OutputIterator2 __out_false,
+		   _Predicate __pred)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::partition_copy(__gnu_debug::__base(__first),
+					     __gnu_debug::__base(__last),
+					     __out_true, __out_false, __pred);
+    }
+#endif
+
+  template<typename _ForwardIterator, typename _Tp>
+    _ForwardIterator
+    remove(_ForwardIterator __first, _ForwardIterator __last,
+	   const _Tp& __value)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::remove(__gnu_debug::__base(__first),
+				       __gnu_debug::__base(__last),
+				       __value));
+    }
+
+  template<typename _ForwardIterator, typename _Predicate>
+    _ForwardIterator
+    remove_if(_ForwardIterator __first, _ForwardIterator __last,
+	      _Predicate __pred)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::remove_if(__gnu_debug::__base(__first),
+					  __gnu_debug::__base(__last),
+					  __pred));
+    }
+
+  template<typename _ForwardIterator>
+    _ForwardIterator
+    unique(_ForwardIterator __first, _ForwardIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::unique(__gnu_debug::__base(__first),
+				       __gnu_debug::__base(__last)));
+    }
+
+  template<typename _ForwardIterator, typename _BinaryPredicate>
+    _ForwardIterator
+    unique(_ForwardIterator __first, _ForwardIterator __last,
+           _BinaryPredicate __binary_pred)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::unique(__gnu_debug::__base(__first),
+				       __gnu_debug::__base(__last),
+				       __binary_pred));
+    }
+
+  template<typename _BidirectionalIterator>
+    inline void
+    reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      _GLIBCXX_BASE_A::reverse(__gnu_debug::__base(__first),
+			       __gnu_debug::__base(__last));
+    }
+
+  template<typename _BidirectionalIterator, typename _OutputIterator>
+    _OutputIterator
+    reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last,
+		 _OutputIterator __result)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::reverse_copy(__gnu_debug::__base(__first),
+					   __gnu_debug::__base(__last),
+					   __result);
+    }
+
+  template<typename _ForwardIterator>
+    inline void
+    rotate(_ForwardIterator __first, _ForwardIterator __middle,
+	   _ForwardIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __middle);
+      __glibcxx_check_valid_range(__middle, __last);
+      _GLIBCXX_BASE_A::rotate(__gnu_debug::__base(__first),
+			      __gnu_debug::__base(__middle),
+			      __gnu_debug::__base(__last));
+    }
+
+  template<typename _ForwardIterator, typename _OutputIterator>
+    _OutputIterator
+    rotate_copy(_ForwardIterator __first, _ForwardIterator __middle,
+                _ForwardIterator __last, _OutputIterator __result)
+    {
+      __glibcxx_check_valid_range(__first, __middle);
+      __glibcxx_check_valid_range(__middle, __last);
+      return _GLIBCXX_BASE_A::rotate(__gnu_debug::__base(__first),
+				     __gnu_debug::__base(__middle),
+				     __gnu_debug::__base(__last),
+				     __result);
+    }
+
+  template<typename _ForwardIterator, typename _Predicate>
+    _ForwardIterator
+    stable_partition(_ForwardIterator __first, _ForwardIterator __last,
+		     _Predicate __pred)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::stable_partition(__gnu_debug::__base(__first),
+						 __gnu_debug::__base(__last),
+						 __pred));
+    }
+
+  template<typename _InputIterator, typename _RandomAccessIterator>
+    _RandomAccessIterator
+    partial_sort_copy(_InputIterator __first, _InputIterator __last,
+		      _RandomAccessIterator __result_first,
+		      _RandomAccessIterator __result_last)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      __glibcxx_check_valid_range(__result_first, __result_last);
+      return __gnu_debug::__safe(__result_first,
+	       _GLIBCXX_BASE_A::partial_sort_copy(
+			__gnu_debug::__base(__first),
+			__gnu_debug::__base(__last),
+			__gnu_debug::__base(__result_first),
+			__gnu_debug::__base(__result_last)));
+    }
+
+  template<typename _InputIterator, typename _RandomAccessIterator, typename _Compare>
+    _RandomAccessIterator
+    partial_sort_copy(_InputIterator __first, _InputIterator __last,
+		      _RandomAccessIterator __result_first,
+		      _RandomAccessIterator __result_last,
+		      _Compare __comp)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      __glibcxx_check_valid_range(__result_first, __result_last);
+      return __gnu_debug::__safe(__result_first,
+	       _GLIBCXX_BASE_A::partial_sort_copy(
+			__gnu_debug::__base(__first),
+			__gnu_debug::__base(__last),
+			__gnu_debug::__base(__result_first),
+			__gnu_debug::__base(__result_last),
+			__comp));
+    }
+
+  template<typename _ForwardIterator, typename _Tp, typename _Compare>
+    _ForwardIterator
+    lower_bound(_ForwardIterator __first, _ForwardIterator __last,
+		const _Tp& __val, _Compare __comp)
+    {
+      __glibcxx_check_partitioned_lower_pred(__first, __last,
+						__val, __comp);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::lower_bound(__gnu_debug::__base(__first),
+					    __gnu_debug::__base(__last),
+					    __val, __comp));
+    }
+
+  template<typename _ForwardIterator, typename _Tp>
+    _ForwardIterator
+    upper_bound(_ForwardIterator __first, _ForwardIterator __last,
+		const _Tp& __val)
+    {
+      __glibcxx_check_partitioned_upper(__first, __last, __val);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::upper_bound(__gnu_debug::__base(__first),
+					    __gnu_debug::__base(__last),
+					    __val));
+    }
+
+  template<typename _ForwardIterator, typename _Tp, typename _Compare>
+    _ForwardIterator
+    upper_bound(_ForwardIterator __first, _ForwardIterator __last,
+		const _Tp& __val, _Compare __comp)
+    {
+      __glibcxx_check_partitioned_upper_pred(__first, __last,
+						__val, __comp);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::upper_bound(__gnu_debug::__base(__first),
+					    __gnu_debug::__base(__last),
+					    __val, __comp));
+    }
+
+  template<typename _ForwardIterator, typename _Tp>
+    pair<_ForwardIterator, _ForwardIterator>
+    equal_range(_ForwardIterator __first, _ForwardIterator __last,
+		const _Tp& __val)
+    {
+      __glibcxx_check_partitioned_lower(__first, __last, __val);
+      __glibcxx_check_partitioned_upper(__first, __last, __val);
+      return __gnu_debug::__safe_pair(__first,
+	      _GLIBCXX_BASE_A::equal_range(__gnu_debug::__base(__first),
+					   __gnu_debug::__base(__last),
+					   __val));
+    }
+
+  template<typename _ForwardIterator, typename _Tp, typename _Compare>
+    pair<_ForwardIterator, _ForwardIterator>
+    equal_range(_ForwardIterator __first, _ForwardIterator __last,
+		const _Tp& __val, _Compare __comp)
+    {
+      __glibcxx_check_partitioned_lower_pred(__first, __last,
+					     __val, __comp);
+      __glibcxx_check_partitioned_upper_pred(__first, __last,
+					     __val, __comp);
+      return __gnu_debug::__safe_pair(__first,
+	      _GLIBCXX_BASE_A::equal_range(__gnu_debug::__base(__first),
+					   __gnu_debug::__base(__last),
+					   __val, __comp));
+    }
+
+  template<typename _ForwardIterator, typename _Tp>
+    bool
+    binary_search(_ForwardIterator __first, _ForwardIterator __last,
+                  const _Tp& __val)
+    {
+      __glibcxx_check_partitioned_lower(__first, __last, __val);
+      __glibcxx_check_partitioned_upper(__first, __last, __val);
+      return _GLIBCXX_BASE_A::binary_search(__gnu_debug::__base(__first),
+					    __gnu_debug::__base(__last),
+					    __val);
+    }
+
+  template<typename _ForwardIterator, typename _Tp, typename _Compare>
+    bool
+    binary_search(_ForwardIterator __first, _ForwardIterator __last,
+                  const _Tp& __val, _Compare __comp)
+    {
+      __glibcxx_check_partitioned_lower_pred(__first, __last,
+					     __val, __comp);
+      __glibcxx_check_partitioned_upper_pred(__first, __last,
+					     __val, __comp);
+      return _GLIBCXX_BASE_A::binary_search(__gnu_debug::__base(__first),
+					    __gnu_debug::__base(__last),
+					    __val, __comp);
+    }
+
+  template<typename _BidirectionalIterator>
+    void
+    inplace_merge(_BidirectionalIterator __first,
+		  _BidirectionalIterator __middle,
+		  _BidirectionalIterator __last)
+    {
+      __glibcxx_check_sorted(__first, __middle);
+      __glibcxx_check_sorted(__middle, __last);
+      _GLIBCXX_BASE_A::inplace_merge(__gnu_debug::__base(__first),
+				     __gnu_debug::__base(__middle),
+				     __gnu_debug::__base(__last));
+    }
+
+  template<typename _BidirectionalIterator, typename _Compare>
+    void
+    inplace_merge(_BidirectionalIterator __first,
+		  _BidirectionalIterator __middle,
+		  _BidirectionalIterator __last,
+		  _Compare __comp)
+    {
+      __glibcxx_check_sorted_pred(__first, __middle, __comp);
+      __glibcxx_check_sorted_pred(__middle, __last, __comp);
+      _GLIBCXX_BASE_A::inplace_merge(__gnu_debug::__base(__first),
+				     __gnu_debug::__base(__middle),
+				     __gnu_debug::__base(__last),
+				     __comp);
+    }
+
+  template<typename _InputIterator1, typename _InputIterator2>
+    bool
+    includes(_InputIterator1 __first1, _InputIterator1 __last1,
+	     _InputIterator2 __first2, _InputIterator2 __last2)
+    {
+      __glibcxx_check_sorted_set(__first1, __last1, __first2);
+      __glibcxx_check_sorted_set(__first2, __last2, __first1);
+      return _GLIBCXX_BASE_A::includes(__gnu_debug::__base(__first1),
+				       __gnu_debug::__base(__last1),
+				       __gnu_debug::__base(__first2),
+				       __gnu_debug::__base(__last2));
+    }
+
+  template<typename _InputIterator1, typename _InputIterator2,
+	   typename _Compare>
+    bool
+    includes(_InputIterator1 __first1, _InputIterator1 __last1,
+	     _InputIterator2 __first2, _InputIterator2 __last2,
+	     _Compare __comp)
+    {
+      __glibcxx_check_sorted_set_pred(__first1, __last1, __first2, __comp);
+      __glibcxx_check_sorted_set_pred(__first2, __last2, __first1, __comp);
+      return _GLIBCXX_BASE_A::includes(__gnu_debug::__base(__first1),
+				       __gnu_debug::__base(__last1),
+				       __gnu_debug::__base(__first2),
+				       __gnu_debug::__base(__last2),
+				       __comp);
+    }
+
+  template<typename _BidirectionalIterator>
+    bool
+    next_permutation(_BidirectionalIterator __first,
+		     _BidirectionalIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::next_permutation(__gnu_debug::__base(__first),
+					       __gnu_debug::__base(__last));
+    }
+
+  template<typename _BidirectionalIterator, typename _Compare>
+    bool
+    next_permutation(_BidirectionalIterator __first,
+		     _BidirectionalIterator __last, _Compare __comp)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::next_permutation(__gnu_debug::__base(__first),
+					       __gnu_debug::__base(__last),
+					       __comp);
+    }
+
+  template<typename _BidirectionalIterator>
+    bool
+    prev_permutation(_BidirectionalIterator __first,
+		     _BidirectionalIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::prev_permutation(__gnu_debug::__base(__first),
+					       __gnu_debug::__base(__last));
+    }
+
+  template<typename _BidirectionalIterator, typename _Compare>
+    bool
+    prev_permutation(_BidirectionalIterator __first,
+		     _BidirectionalIterator __last, _Compare __comp)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::prev_permutation(__gnu_debug::__base(__first),
+					       __gnu_debug::__base(__last),
+					       __comp);
+    }
+
+  template<typename _InputIterator, typename _OutputIterator, typename _Tp>
+    _OutputIterator
+    replace_copy(_InputIterator __first, _InputIterator __last,
+		 _OutputIterator __result,
+		 const _Tp& __old_value, const _Tp& __new_value)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::replace_copy(__gnu_debug::__base(__first),
+					   __gnu_debug::__base(__last),
+					   __result, __old_value, __new_value);
+    }
+
+  template<typename _InputIterator, typename _OutputIterator,
+	   typename _Predicate, typename _Tp>
+    _OutputIterator
+    replace_copy_if(_InputIterator __first, _InputIterator __last,
+		    _OutputIterator __result,
+		    _Predicate __pred, const _Tp& __new_value)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::replace_copy_if(__gnu_debug::__base(__first),
+					      __gnu_debug::__base(__last),
+					      __result,
+					      __pred, __new_value);
+    }
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  template<typename _ForwardIterator>
+    inline bool
+    is_sorted(_ForwardIterator __first, _ForwardIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::is_sorted(__gnu_debug::__base(__first),
+					__gnu_debug::__base(__last));
+    }
+
+  template<typename _ForwardIterator, typename _Compare>
+    inline bool
+    is_sorted(_ForwardIterator __first, _ForwardIterator __last,
+	      _Compare __comp)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::is_sorted(__gnu_debug::__base(__first),
+					__gnu_debug::__base(__last),
+					__comp);
+    }
+
+  template<typename _ForwardIterator>
+    _ForwardIterator
+    is_sorted_until(_ForwardIterator __first, _ForwardIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::is_sorted_until(__gnu_debug::__base(__first),
+						__gnu_debug::__base(__last)));
+    }
+
+  template<typename _ForwardIterator, typename _Compare>
+    _ForwardIterator
+    is_sorted_until(_ForwardIterator __first, _ForwardIterator __last,
+		    _Compare __comp)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::is_sorted_until(__gnu_debug::__base(__first),
+						__gnu_debug::__base(__last),
+						__comp));
+    }
+
+  template<typename _ForwardIterator>
+    pair<_ForwardIterator, _ForwardIterator>
+    minmax_element(_ForwardIterator __first, _ForwardIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe_pair(__first,
+	       _GLIBCXX_BASE_A::minmax_element(__gnu_debug::__base(__first),
+					       __gnu_debug::__base(__last)));
+    }
+
+  template<typename _ForwardIterator, typename _Compare>
+    pair<_ForwardIterator, _ForwardIterator>
+    minmax_element(_ForwardIterator __first, _ForwardIterator __last,
+		   _Compare __comp)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe_pair(__first,
+	       _GLIBCXX_BASE_A::minmax_element(__gnu_debug::__base(__first),
+					       __gnu_debug::__base(__last),
+					       __comp));
+    }
+
+  template<typename _ForwardIterator1, typename _ForwardIterator2>
+    bool
+    is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+		   _ForwardIterator2 __first2)
+    {
+      __glibcxx_check_valid_range(__first1, __last1);
+      return _GLIBCXX_BASE_A::is_permutation(__gnu_debug::__base(__first1),
+					     __gnu_debug::__base(__last1),
+					     __first2);
+    }
+
+  template<typename _ForwardIterator1, typename _ForwardIterator2,
+	   typename _BinaryPredicate>
+    bool
+    is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+		   _ForwardIterator2 __first2, _BinaryPredicate __pred)
+    {
+      __glibcxx_check_valid_range(__first1, __last1);
+      return _GLIBCXX_BASE_A::is_permutation(__gnu_debug::__base(__first1),
+					     __gnu_debug::__base(__last1),
+					     __first2, __pred);
+    }
+
+#ifdef _GLIBCXX_USE_C99_STDINT_TR1
+  template<typename _RandomAccessIterator,
+	   typename _UniformRandomNumberGenerator>
+    void
+    shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
+	    _UniformRandomNumberGenerator&& __g)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      _GLIBCXX_BASE_A::shuffle(__gnu_debug::__base(__first),
+			       __gnu_debug!!__base(__last),
+			       std::move(__g));
+    }
+#endif
+
+#endif // __GXX_EXPERIMENTAL_CXX0X__
+
+  template<typename _InputIterator, typename _Function>
+    _Function
+    for_each(_InputIterator __first, _InputIterator __last, _Function __f)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::for_each(__gnu_debug::__base(__first),
+				       __gnu_debug::__base(__last),
+				       __f);
+    }
+
+  template<typename _InputIterator, typename _Tp>
+    inline _InputIterator
+    find(_InputIterator __first, _InputIterator __last,
+	 const _Tp& __val)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::find(__gnu_debug::__base(__first),
+				     __gnu_debug::__base(__last),
+				     __val));
+    }
+
+  template<typename _InputIterator, typename _Predicate>
+    inline _InputIterator
+    find_if(_InputIterator __first, _InputIterator __last,
+	    _Predicate __pred)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::find_if(__gnu_debug::__base(__first),
+					__gnu_debug::__base(__last),
+					__pred));
+    }
+
+  template<typename _InputIterator, typename _ForwardIterator>
+    _InputIterator
+    find_first_of(_InputIterator __first1, _InputIterator __last1,
+		  _ForwardIterator __first2, _ForwardIterator __last2)
+    {
+      __glibcxx_check_valid_range(__first1, __last1);
+      __glibcxx_check_valid_range(__first2, __last2);
+      return __gnu_debug::__safe(__first1,
+	       _GLIBCXX_BASE_A::find_first_of(__gnu_debug::__base(__first1),
+					      __gnu_debug::__base(__last1),
+					      __gnu_debug::__base(__first2),
+					      __gnu_debug::__base(__last2)));
+    }
+
+  template<typename _InputIterator, typename _ForwardIterator,
+	   typename _BinaryPredicate>
+    _InputIterator
+    find_first_of(_InputIterator __first1, _InputIterator __last1,
+		  _ForwardIterator __first2, _ForwardIterator __last2,
+		  _BinaryPredicate __comp)
+    {
+      __glibcxx_check_valid_range(__first1, __last1);
+      __glibcxx_check_valid_range(__first2, __last2);
+      return __gnu_debug::__safe(__first1,
+	       _GLIBCXX_BASE_A::find_first_of(__gnu_debug::__base(__first1),
+					      __gnu_debug::__base(__last1),
+					      __gnu_debug::__base(__first2),
+					      __gnu_debug::__base(__last2)));
+    }
+
+  template<typename _ForwardIterator>
+    _ForwardIterator
+    adjacent_find(_ForwardIterator __first, _ForwardIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::adjacent_find(__gnu_debug::__base(__first),
+					      __gnu_debug::__base(__last)));
+    }
+
+  template<typename _ForwardIterator, typename _BinaryPredicate>
+    _ForwardIterator
+    adjacent_find(_ForwardIterator __first, _ForwardIterator __last,
+		  _BinaryPredicate __binary_pred)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::adjacent_find(__gnu_debug::__base(__first),
+					      __gnu_debug::__base(__last),
+					      __binary_pred));
+    }
+
+  template<typename _InputIterator, typename _Tp>
+    typename iterator_traits<_InputIterator>::difference_type
+    count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::count(__gnu_debug::__base(__first),
+				    __gnu_debug::__base(__last),
+				    __value);
+    }
+
+  template<typename _InputIterator, typename _Predicate>
+    typename iterator_traits<_InputIterator>::difference_type
+    count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::count_if(__gnu_debug::__base(__first),
+				       __gnu_debug::__base(__last),
+				       __pred);
+    }
+
+  template<typename _ForwardIterator1, typename _ForwardIterator2>
+    _ForwardIterator1
+    search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+	   _ForwardIterator2 __first2, _ForwardIterator2 __last2)
+    {
+      __glibcxx_check_valid_range(__first1, __last1);
+      __glibcxx_check_valid_range(__first2, __last2);
+      return __gnu_debug::__safe(__first1,
+	       _GLIBCXX_BASE_A::search(__gnu_debug::__base(__first1),
+				       __gnu_debug::__base(__last1),
+				       __gnu_debug::__base(__first2),
+				       __gnu_debug::__base(__last2)));
+    }
+
+  template<typename _ForwardIterator1, typename _ForwardIterator2,
+	   typename _BinaryPredicate>
+    _ForwardIterator1
+    search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+	   _ForwardIterator2 __first2, _ForwardIterator2 __last2,
+	   _BinaryPredicate  __predicate)
+    {
+      __glibcxx_check_valid_range(__first1, __last1);
+      __glibcxx_check_valid_range(__first2, __last2);
+      return __gnu_debug::__safe(__first1,
+	       _GLIBCXX_BASE_A::search(__gnu_debug::__base(__first1),
+				       __gnu_debug::__base(__last1),
+				       __gnu_debug::__base(__first2),
+				       __gnu_debug::__base(__last2),
+				       __predicate));
+    }
+
+  template<typename _ForwardIterator, typename _Integer, typename _Tp>
+    _ForwardIterator
+    search_n(_ForwardIterator __first, _ForwardIterator __last,
+	     _Integer __count, const _Tp& __val)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::search_n(__gnu_debug::__base(__first),
+					 __gnu_debug::__base(__last),
+					 __count, __val));
+    }
+
+
+  template<typename _ForwardIterator, typename _Integer, typename _Tp,
+           typename _BinaryPredicate>
+    _ForwardIterator
+    search_n(_ForwardIterator __first, _ForwardIterator __last,
+	     _Integer __count, const _Tp& __val,
+	     _BinaryPredicate __binary_pred)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::search_n(__gnu_debug::__base(__first),
+					 __gnu_debug::__base(__last),
+					 __count, __val, __binary_pred));
+    }
+
+  template<typename _InputIterator, typename _OutputIterator,
+	   typename _UnaryOperation>
+    _OutputIterator
+    transform(_InputIterator __first, _InputIterator __last,
+	      _OutputIterator __result, _UnaryOperation __unary_op)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::transform(__gnu_debug::__base(__first),
+					__gnu_debug::__base(__last),
+					__result, __unary_op);
+    }
+
+  template<typename _InputIterator1, typename _InputIterator2,
+	   typename _OutputIterator, typename _BinaryOperation>
+    _OutputIterator
+    transform(_InputIterator1 __first1, _InputIterator1 __last1,
+	      _InputIterator2 __first2, _OutputIterator __result,
+	      _BinaryOperation __binary_op)
+    {
+      __glibcxx_check_valid_range(__first1, __last1);
+      return _GLIBCXX_BASE_A::transform(__gnu_debug::__base(__first1),
+					__gnu_debug::__base(__last1),
+					__first2, __result, __binary_op);
+    }
+
+  template<typename _ForwardIterator, typename _Tp>
+    void
+    replace(_ForwardIterator __first, _ForwardIterator __last,
+	    const _Tp& __old_value, const _Tp& __new_value)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      _GLIBCXX_BASE_A::replace(__gnu_debug::__base(__first),
+			       __gnu_debug::__base(__last),
+			       __old_value, __new_value);
+    }
+
+  template<typename _ForwardIterator, typename _Predicate, typename _Tp>
+    void
+    replace_if(_ForwardIterator __first, _ForwardIterator __last,
+	       _Predicate __pred, const _Tp& __new_value)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      _GLIBCXX_BASE_A::replace_if(__gnu_debug::__base(__first),
+				  __gnu_debug::__base(__last),
+				  __pred, __new_value);
+    }
+
+  template<typename _ForwardIterator, typename _Generator>
+    void
+    generate(_ForwardIterator __first, _ForwardIterator __last,
+	     _Generator __gen)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      _GLIBCXX_BASE_A::generate(__gnu_debug::__base(__first),
+				__gnu_debug::__base(__last),
+				__gen);
+    }
+
+  template<typename _OutputIterator, typename _Size, typename _Generator>
+    _OutputIterator
+    generate_n(_OutputIterator __first, _Size __n, _Generator __gen)
+    { return _GLIBCXX_BASE_A::generate_n(__first, __n, __gen); }
+
+
+  template<typename _InputIterator, typename _OutputIterator>
+    inline _OutputIterator
+    unique_copy(_InputIterator __first, _InputIterator __last,
+		_OutputIterator __result)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::unique_copy(__gnu_debug::__base(__first),
+					  __gnu_debug::__base(__last),
+					  __result);
+    }
+
+  template<typename _InputIterator, typename _OutputIterator,
+	   typename _BinaryPredicate>
+    inline _OutputIterator
+    unique_copy(_InputIterator __first, _InputIterator __last,
+		_OutputIterator __result,
+		_BinaryPredicate __binary_pred)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return _GLIBCXX_BASE_A::unique_copy(__gnu_debug::__base(__first),
+					  __gnu_debug::__base(__last),
+					  __result, __binary_pred);
+    }
+
+
+  template<typename _RandomAccessIterator>
+    inline void
+    random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      _GLIBCXX_BASE_A::random_shuffle(__gnu_debug::__base(__first),
+				      __gnu_debug::__base(__last));
+    }
+
+  template<typename _RandomAccessIterator, typename _RandomNumberGenerator>
+    void
+    random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+		   _RandomNumberGenerator&& __rand)
+#else
+		   _RandomNumberGenerator& __rand)
+#endif
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      _GLIBCXX_BASE_A::random_shuffle(__gnu_debug::__base(__first),
+				      __gnu_debug::__base(__last),
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+				      std::move(__rand));
+#else
+				      __rand);
+#endif
+    }
+
+  template<typename _ForwardIterator, typename _Predicate>
+    inline _ForwardIterator
+    partition(_ForwardIterator __first, _ForwardIterator __last,
+	      _Predicate   __pred)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::partition(__gnu_debug::__base(__first),
+					  __gnu_debug::__base(__last),
+					  __pred));
+    }
+
+  template<typename _RandomAccessIterator>
+    inline void
+    partial_sort(_RandomAccessIterator __first,
+		 _RandomAccessIterator __middle,
+		 _RandomAccessIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __middle);
+      __glibcxx_check_valid_range(__middle, __last);
+      _GLIBCXX_BASE_A::partial_sort(__gnu_debug::__base(__first),
+				    __gnu_debug::__base(__middle),
+				    __gnu_debug::__base(__last));
+    }
+
+  template<typename _RandomAccessIterator, typename _Compare>
+    inline void
+    partial_sort(_RandomAccessIterator __first,
+		 _RandomAccessIterator __middle,
+		 _RandomAccessIterator __last,
+		 _Compare __comp)
+    {
+      __glibcxx_check_valid_range(__first, __middle);
+      __glibcxx_check_valid_range(__middle, __last);
+      _GLIBCXX_BASE_A::partial_sort(__gnu_debug::__base(__first),
+				    __gnu_debug::__base(__middle),
+				    __gnu_debug::__base(__last),
+				    __comp);
+    }
+
+  template<typename _RandomAccessIterator>
+    inline void
+    nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth,
+		_RandomAccessIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __nth);
+      __glibcxx_check_valid_range(__nth, __last);
+      _GLIBCXX_BASE_A::nth_element(__gnu_debug::__base(__first),
+				   __gnu_debug::__base(__nth),
+				   __gnu_debug::__base(__last));
+    }
+
+  template<typename _RandomAccessIterator, typename _Compare>
+    inline void
+    nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth,
+		_RandomAccessIterator __last, _Compare __comp)
+    {
+      __glibcxx_check_valid_range(__first, __nth);
+      __glibcxx_check_valid_range(__nth, __last);
+      _GLIBCXX_BASE_A::nth_element(__gnu_debug::__base(__first),
+				   __gnu_debug::__base(__nth),
+				   __gnu_debug::__base(__last), __comp);
+    }
+
+  template<typename _RandomAccessIterator>
+    inline void
+    sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      _GLIBCXX_BASE_A::sort(__gnu_debug::__base(__first),
+			    __gnu_debug::__base(__last));
+    }
+
+  template<typename _RandomAccessIterator, typename _Compare>
+    inline void
+    sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
+	 _Compare __comp)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      _GLIBCXX_BASE_A::sort(__gnu_debug::__base(__first),
+			    __gnu_debug::__base(__last), __comp);
+    }
+
+  template<typename _InputIterator1, typename _InputIterator2,
+	   typename _OutputIterator>
+    _OutputIterator
+    merge(_InputIterator1 __first1, _InputIterator1 __last1,
+	  _InputIterator2 __first2, _InputIterator2 __last2,
+	  _OutputIterator __result)
+    {
+      __glibcxx_check_sorted_set(__first1, __last1, __first2);
+      __glibcxx_check_sorted_set(__first2, __last2, __first1);
+      return _GLIBCXX_BASE_A::merge(__gnu_debug::__base(__first1),
+				    __gnu_debug::__base(__last1),
+				    __gnu_debug::__base(__first2),
+				    __gnu_debug::__base(__last2),
+				    __result);
+    }
+
+  template<typename _InputIterator1, typename _InputIterator2,
+	   typename _OutputIterator, typename _Compare>
+    _OutputIterator
+    merge(_InputIterator1 __first1, _InputIterator1 __last1,
+	  _InputIterator2 __first2, _InputIterator2 __last2,
+	  _OutputIterator __result, _Compare __comp)
+    {
+      __glibcxx_check_sorted_set_pred(__first1, __last1, __first2, __comp);
+      __glibcxx_check_sorted_set_pred(__first2, __last2, __first1, __comp);
+      return _GLIBCXX_BASE_A::merge(__gnu_debug::__base(__first1),
+				    __gnu_debug::__base(__last1),
+				    __gnu_debug::__base(__first2),
+				    __gnu_debug::__base(__last2),
+				    __result, __comp);
+    }
+
+  template<typename _RandomAccessIterator>
+    inline void
+    stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      _GLIBCXX_BASE_A::stable_sort(__gnu_debug::__base(__first),
+				   __gnu_debug::__base(__last));
+    }
+
+  template<typename _RandomAccessIterator, typename _Compare>
+    inline void
+    stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
+		_Compare __comp)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      _GLIBCXX_BASE_A::stable_sort(__gnu_debug::__base(__first),
+				   __gnu_debug::__base(__last),
+				   __comp);
+    }
+
+
+  template<typename _InputIterator1, typename _InputIterator2,
+	   typename _OutputIterator>
+    _OutputIterator
+    set_union(_InputIterator1 __first1, _InputIterator1 __last1,
+	      _InputIterator2 __first2, _InputIterator2 __last2,
+	      _OutputIterator __result)
+    {
+      __glibcxx_check_sorted_set(__first1, __last1, __first2);
+      __glibcxx_check_sorted_set(__first2, __last2, __first1);
+      return _GLIBCXX_BASE_A::set_union(__gnu_debug::__base(__first1),
+					__gnu_debug::__base(__last1),
+					__gnu_debug::__base(__first2),
+					__gnu_debug::__base(__last2),
+					__result);
+    }
+
+  template<typename _InputIterator1, typename _InputIterator2,
+	   typename _OutputIterator, typename _Compare>
+    _OutputIterator
+    set_union(_InputIterator1 __first1, _InputIterator1 __last1,
+	      _InputIterator2 __first2, _InputIterator2 __last2,
+	      _OutputIterator __result, _Compare __comp)
+    {
+      __glibcxx_check_sorted_set_pred(__first1, __last1, __first2, __comp);
+      __glibcxx_check_sorted_set_pred(__first2, __last2, __first1, __comp);
+      return _GLIBCXX_BASE_A::set_union(__gnu_debug::__base(__first1),
+					__gnu_debug::__base(__last1),
+					__gnu_debug::__base(__first2),
+					__gnu_debug::__base(__last2),
+					__result, __comp);
+    }
+
+  template<typename _InputIterator1, typename _InputIterator2,
+	   typename _OutputIterator>
+    _OutputIterator
+    set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
+		     _InputIterator2 __first2, _InputIterator2 __last2,
+		     _OutputIterator __result)
+    {
+      __glibcxx_check_sorted_set(__first1, __last1, __first2);
+      __glibcxx_check_sorted_set(__first2, __last2, __first1);
+      return _GLIBCXX_BASE_A::set_intersection(__gnu_debug::__base(__first1),
+					       __gnu_debug::__base(__last1),
+					       __gnu_debug::__base(__first2),
+					       __gnu_debug::__base(__last2),
+					       __result);
+    }
+
+  template<typename _InputIterator1, typename _InputIterator2,
+	   typename _OutputIterator, typename _Compare>
+    _OutputIterator
+    set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
+		     _InputIterator2 __first2, _InputIterator2 __last2,
+		     _OutputIterator __result, _Compare __comp)
+    {
+      __glibcxx_check_sorted_set_pred(__first1, __last1, __first2, __comp);
+      __glibcxx_check_sorted_set_pred(__first2, __last2, __first1, __comp);
+      return _GLIBCXX_BASE_A::set_intersection(__gnu_debug::__base(__first1),
+					       __gnu_debug::__base(__last1),
+					       __gnu_debug::__base(__first2),
+					       __gnu_debug::__base(__last2),
+					       __result, __comp);
+    }
+
+  template<typename _InputIterator1, typename _InputIterator2,
+	   typename _OutputIterator>
+    _OutputIterator
+    set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
+		   _InputIterator2 __first2, _InputIterator2 __last2,
+		   _OutputIterator __result)
+    {
+      __glibcxx_check_sorted_set(__first1, __last1, __first2);
+      __glibcxx_check_sorted_set(__first2, __last2, __first1);
+      return _GLIBCXX_BASE_A::set_difference(__gnu_debug::__base(__first1),
+					     __gnu_debug::__base(__last1),
+					     __gnu_debug::__base(__first2),
+					     __gnu_debug::__base(__last2),
+					     __result);
+    }
+
+  template<typename _InputIterator1, typename _InputIterator2,
+	   typename _OutputIterator, typename _Compare>
+    _OutputIterator
+    set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
+		   _InputIterator2 __first2, _InputIterator2 __last2,
+		   _OutputIterator __result, _Compare __comp)
+    {
+      __glibcxx_check_sorted_set_pred(__first1, __last1, __first2, __comp);
+      __glibcxx_check_sorted_set_pred(__first2, __last2, __first1, __comp);
+      return _GLIBCXX_BASE_A::set_difference(__gnu_debug::__base(__first1),
+					     __gnu_debug::__base(__last1),
+					     __gnu_debug::__base(__first2),
+					     __gnu_debug::__base(__last2),
+					     __result, __comp);
+    }
+
+  template<typename _InputIterator1, typename _InputIterator2,
+	   typename _OutputIterator>
+    _OutputIterator
+    set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
+			     _InputIterator2 __first2, _InputIterator2 __last2,
+			     _OutputIterator __result)
+    {
+      __glibcxx_check_sorted_set(__first1, __last1, __first2);
+      __glibcxx_check_sorted_set(__first2, __last2, __first1);
+      return _GLIBCXX_BASE_A::set_symmetric_difference(
+		__gnu_debug::__base(__first1),
+		__gnu_debug::__base(__last1),
+		__gnu_debug::__base(__first2),
+		__gnu_debug::__base(__last2),
+		__result);
+    }
+
+  template<typename _InputIterator1, typename _InputIterator2,
+	   typename _OutputIterator, typename _Compare>
+    _OutputIterator
+    set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
+			     _InputIterator2 __first2, _InputIterator2 __last2,
+			     _OutputIterator __result,
+			     _Compare __comp)
+    {
+      __glibcxx_check_sorted_set_pred(__first1, __last1, __first2, __comp);
+      __glibcxx_check_sorted_set_pred(__first2, __last2, __first1, __comp);
+      return _GLIBCXX_BASE_A::set_symmetric_difference(
+		__gnu_debug::__base(__first1),
+		__gnu_debug::__base(__last1),
+		__gnu_debug::__base(__first2),
+		__gnu_debug::__base(__last2),
+		__result, __comp);
+    }
+
+  template<typename _ForwardIterator>
+    _ForwardIterator
+    min_element(_ForwardIterator __first, _ForwardIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::min_element(__gnu_debug::__base(__first),
+					    __gnu_debug::__base(__last)));
+    }
+
+  template<typename _ForwardIterator, typename _Compare>
+    _ForwardIterator
+    min_element(_ForwardIterator __first, _ForwardIterator __last,
+		_Compare __comp)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::min_element(__gnu_debug::__base(__first),
+					    __gnu_debug::__base(__last),
+					    __comp));
+    }
+
+  template<typename _ForwardIterator>
+    _ForwardIterator
+    max_element(_ForwardIterator __first, _ForwardIterator __last)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::max_element(__gnu_debug::__base(__first),
+					    __gnu_debug::__base(__last)));
+    }
+
+  template<typename _ForwardIterator, typename _Compare>
+    _ForwardIterator
+    max_element(_ForwardIterator __first, _ForwardIterator __last,
+		_Compare __comp)
+    {
+      __glibcxx_check_valid_range(__first, __last);
+      return __gnu_debug::__safe(__first,
+	       _GLIBCXX_BASE_A::max_element(__gnu_debug::__base(__first),
+					    __gnu_debug::__base(__last),
+					    __comp));
+    }
+
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace __debug
+} // namespace std
+
+#endif

Property changes on: include/debug/algo.h
___________________________________________________________________
Added: svn:eol-style
   + native

Index: include/debug/macros.h
===================================================================
--- include/debug/macros.h	(revision 173802)
+++ include/debug/macros.h	(working copy)
@@ -30,6 +30,12 @@
 #ifndef _GLIBCXX_DEBUG_MACROS_H
 #define _GLIBCXX_DEBUG_MACROS_H 1
 
+#ifdef _GLIBCXX_PARALLEL
+#  define _GLIBCXX_BASE_A _GLIBCXX_PARALLEL_A
+#else
+#  define _GLIBCXX_BASE_A _GLIBCXX_STD_A
+#endif
+
 /**
  * Macros used by the implementation to verify certain
  * properties. These macros may only be used directly by the debug
@@ -209,26 +215,33 @@
 // Verify that the iterator range [_First, _Last) is sorted
 #define __glibcxx_check_sorted(_First,_Last)				\
 __glibcxx_check_valid_range(_First,_Last);				\
-_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted(_First, _Last),	\
-		      _M_message(__gnu_debug::__msg_unsorted)	        \
-                      ._M_iterator(_First, #_First)			\
-		      ._M_iterator(_Last, #_Last))
+_GLIBCXX_DEBUG_VERIFY(							\
+  __gnu_debug::__check_sorted(__gnu_debug::__base(_First),		\
+			      __gnu_debug::__base(_Last)),		\
+  _M_message(__gnu_debug::__msg_unsorted)				\
+  ._M_iterator(_First, #_First)						\
+  ._M_iterator(_Last, #_Last))
 
 /** Verify that the iterator range [_First, _Last) is sorted by the
     predicate _Pred. */
 #define __glibcxx_check_sorted_pred(_First,_Last,_Pred)			\
 __glibcxx_check_valid_range(_First,_Last);				\
-_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_sorted(_First, _Last, _Pred), \
-		      _M_message(__gnu_debug::__msg_unsorted_pred)      \
-                      ._M_iterator(_First, #_First)			\
-		      ._M_iterator(_Last, #_Last)			\
-		      ._M_string(#_Pred))
+_GLIBCXX_DEBUG_VERIFY(							\
+  __gnu_debug::__check_sorted(__gnu_debug::__base(_First),		\
+			      __gnu_debug::__base(_Last),		\
+			      _Pred),					\
+  _M_message(__gnu_debug::__msg_unsorted_pred)				\
+  ._M_iterator(_First, #_First)						\
+  ._M_iterator(_Last, #_Last)						\
+  ._M_string(#_Pred))
 
 // Special variant for std::merge, std::includes, std::set_*
 #define __glibcxx_check_sorted_set(_First1,_Last1,_First2)		\
 __glibcxx_check_valid_range(_First1,_Last1);				\
 _GLIBCXX_DEBUG_VERIFY(                                                  \
-  __gnu_debug::__check_sorted_set(_First1, _Last1, _First2),		\
+  __gnu_debug::__check_sorted_set(__gnu_debug::__base(_First1),		\
+				  __gnu_debug::__base(_Last1),		\
+				  _First2),				\
   _M_message(__gnu_debug::__msg_unsorted)				\
   ._M_iterator(_First1, #_First1)					\
   ._M_iterator(_Last1, #_Last1))
@@ -237,7 +250,9 @@
 #define __glibcxx_check_sorted_set_pred(_First1,_Last1,_First2,_Pred)	\
 __glibcxx_check_valid_range(_First1,_Last1);        			\
 _GLIBCXX_DEBUG_VERIFY(							\
-  __gnu_debug::__check_sorted_set(_First1, _Last1, _First2, _Pred),	\
+  __gnu_debug::__check_sorted_set(__gnu_debug::__base(_First1),		\
+				  __gnu_debug::__base(_Last1),		\
+				  _First2, _Pred),			\
   _M_message(__gnu_debug::__msg_unsorted_pred)				\
   ._M_iterator(_First1, #_First1)					\
   ._M_iterator(_Last1, #_Last1)						\
@@ -247,61 +262,73 @@
     w.r.t. the value _Value. */
 #define __glibcxx_check_partitioned_lower(_First,_Last,_Value)		\
 __glibcxx_check_valid_range(_First,_Last);				\
-_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower(_First, _Last, \
-							    _Value),	\
-		      _M_message(__gnu_debug::__msg_unpartitioned)      \
-		      ._M_iterator(_First, #_First)			\
-		      ._M_iterator(_Last, #_Last)			\
-		      ._M_string(#_Value))
+_GLIBCXX_DEBUG_VERIFY(							\
+  __gnu_debug::__check_partitioned_lower(__gnu_debug::__base(_First),	\
+					 __gnu_debug::__base(_Last),	\
+					 _Value),			\
+  _M_message(__gnu_debug::__msg_unpartitioned)				\
+  ._M_iterator(_First, #_First)						\
+  ._M_iterator(_Last, #_Last)						\
+  ._M_string(#_Value))
 
 #define __glibcxx_check_partitioned_upper(_First,_Last,_Value)		\
 __glibcxx_check_valid_range(_First,_Last);				\
-_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper(_First, _Last, \
-							    _Value),	\
-		      _M_message(__gnu_debug::__msg_unpartitioned)      \
-		      ._M_iterator(_First, #_First)			\
-		      ._M_iterator(_Last, #_Last)			\
-		      ._M_string(#_Value))
+_GLIBCXX_DEBUG_VERIFY(							\
+  __gnu_debug::__check_partitioned_upper(__gnu_debug::__base(_First),	\
+					 __gnu_debug::__base(_Last),	\
+					 _Value),			\
+  _M_message(__gnu_debug::__msg_unpartitioned)				\
+  ._M_iterator(_First, #_First)						\
+  ._M_iterator(_Last, #_Last)						\
+  ._M_string(#_Value))
 
 /** Verify that the iterator range [_First, _Last) is partitioned
     w.r.t. the value _Value and predicate _Pred. */
 #define __glibcxx_check_partitioned_lower_pred(_First,_Last,_Value,_Pred) \
 __glibcxx_check_valid_range(_First,_Last);				\
-_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_lower(_First, _Last, \
-							 _Value, _Pred), \
-		      _M_message(__gnu_debug::__msg_unpartitioned_pred) \
-		      ._M_iterator(_First, #_First)			\
-		      ._M_iterator(_Last, #_Last)			\
-		      ._M_string(#_Pred)				\
-                      ._M_string(#_Value))
+_GLIBCXX_DEBUG_VERIFY(							\
+  __gnu_debug::__check_partitioned_lower(__gnu_debug::__base(_First),	\
+					 __gnu_debug::__base(_Last),	\
+					 _Value, _Pred),		\
+  _M_message(__gnu_debug::__msg_unpartitioned_pred)			\
+  ._M_iterator(_First, #_First)						\
+  ._M_iterator(_Last, #_Last)						\
+  ._M_string(#_Pred)							\
+  ._M_string(#_Value))
 
 /** Verify that the iterator range [_First, _Last) is partitioned
     w.r.t. the value _Value and predicate _Pred. */
 #define __glibcxx_check_partitioned_upper_pred(_First,_Last,_Value,_Pred) \
 __glibcxx_check_valid_range(_First,_Last);				\
-_GLIBCXX_DEBUG_VERIFY(__gnu_debug::__check_partitioned_upper(_First, _Last, \
-							 _Value, _Pred), \
-		      _M_message(__gnu_debug::__msg_unpartitioned_pred) \
-		      ._M_iterator(_First, #_First)			\
-		      ._M_iterator(_Last, #_Last)			\
-		      ._M_string(#_Pred)				\
-                      ._M_string(#_Value))
+_GLIBCXX_DEBUG_VERIFY(							\
+  __gnu_debug::__check_partitioned_upper(__gnu_debug::__base(_First),	\
+					 __gnu_debug::__base(_Last),	\
+					 _Value, _Pred),		\
+  _M_message(__gnu_debug::__msg_unpartitioned_pred)			\
+  ._M_iterator(_First, #_First)						\
+  ._M_iterator(_Last, #_Last)						\
+  ._M_string(#_Pred)							\
+  ._M_string(#_Value))
 
 // Verify that the iterator range [_First, _Last) is a heap
 #define __glibcxx_check_heap(_First,_Last)				\
-_GLIBCXX_DEBUG_VERIFY(std::__is_heap(_First, _Last),		        \
-		      _M_message(__gnu_debug::__msg_not_heap)	        \
-		      ._M_iterator(_First, #_First)			\
-		      ._M_iterator(_Last, #_Last))
+_GLIBCXX_DEBUG_VERIFY(							\
+  __detail::__is_heap(__gnu_debug::__base(_First),			\
+		      __gnu_debug::__base(_Last)),			\
+  _M_message(__gnu_debug::__msg_not_heap)				\
+  ._M_iterator(_First, #_First)						\
+  ._M_iterator(_Last, #_Last))
 
 /** Verify that the iterator range [_First, _Last) is a heap
     w.r.t. the predicate _Pred. */
 #define __glibcxx_check_heap_pred(_First,_Last,_Pred)			\
-_GLIBCXX_DEBUG_VERIFY(std::__is_heap(_First, _Last, _Pred),		\
-		      _M_message(__gnu_debug::__msg_not_heap_pred)      \
-                      ._M_iterator(_First, #_First)			\
-		      ._M_iterator(_Last, #_Last)			\
-		      ._M_string(#_Pred))
+_GLIBCXX_DEBUG_VERIFY(							\
+  __detail::__is_heap(__gnu_debug::__base(_First),			\
+		      __gnu_debug::__base(_Last), _Pred),		\
+  _M_message(__gnu_debug::__msg_not_heap_pred)				\
+  ._M_iterator(_First, #_First)						\
+  ._M_iterator(_Last, #_Last)						\
+  ._M_string(#_Pred))
 
 #ifdef _GLIBCXX_DEBUG_PEDANTIC
 #  define __glibcxx_check_string(_String) _GLIBCXX_DEBUG_ASSERT(_String != 0)
Index: include/debug/safe_iterator.h
===================================================================
--- include/debug/safe_iterator.h	(revision 173802)
+++ include/debug/safe_iterator.h	(working copy)
@@ -682,6 +682,42 @@
     inline typename _Siter_base<_Iterator>::iterator_type
     __base(_Iterator __it)
     { return _Siter_base<_Iterator>::_S_base(__it); }
+
+  template <bool _Cond>
+    struct _Safe {
+      template <typename _Iterator>
+	static _Iterator _To(_Iterator, _Iterator __it)
+	{ return __it; }
+    };
+
+  template <>
+    struct _Safe<true> {
+      template <typename _Iterator, typename _Sequence>
+	static _Safe_iterator<_Iterator, _Sequence>
+       	_To(_Safe_iterator<_Iterator, _Sequence> __safe_it,
+	    _Iterator __it) {
+	  typedef _Safe_iterator<_Iterator, _Sequence> _SafeIt;
+	  return _SafeIt(__it, __safe_it._M_get_sequence());
+	}
+  };
+
+  template<typename _SafeIt, typename _UnsafeIt>
+    inline _SafeIt
+    __safe(_SafeIt __safe_it, _UnsafeIt __unsafe_it)
+    {  return _Safe<__is_safe_random_iterator<_SafeIt>::__value>::
+		_To(__safe_it, __unsafe_it); }
+
+  template<typename _SafeIt, typename _UnsafeIt>
+    inline std::pair<_SafeIt, _SafeIt>
+    __safe_pair(_SafeIt __safe_it,
+		const std::pair<_UnsafeIt, _UnsafeIt>& __unsafe_pair) {
+      const bool __is_safe = __is_safe_random_iterator<_SafeIt>::__value;
+      return std::make_pair(_Safe<__is_safe>::_To(__safe_it,
+						  __unsafe_pair.first),
+			    _Safe<__is_safe>::_To(__safe_it,
+						  __unsafe_pair.second));
+
+    }
 } // namespace __gnu_debug
 
 #include <debug/safe_iterator.tcc>
Index: include/std/valarray
===================================================================
--- include/std/valarray	(revision 173802)
+++ include/std/valarray	(working copy)
@@ -1020,7 +1020,7 @@
     valarray<_Tp>::min() const
     {
       _GLIBCXX_DEBUG_ASSERT(_M_size > 0);
-      return *std::min_element(_M_data, _M_data + _M_size);
+      return *_GLIBCXX_PARALLEL_A::min_element(_M_data, _M_data + _M_size);
     }
 
   template<typename _Tp>
@@ -1028,7 +1028,7 @@
     valarray<_Tp>::max() const
     {
       _GLIBCXX_DEBUG_ASSERT(_M_size > 0);
-      return *std::max_element(_M_data, _M_data + _M_size);
+      return *_GLIBCXX_PARALLEL_A::max_element(_M_data, _M_data + _M_size);
     }
   
   template<class _Tp>
Index: include/std/algorithm
===================================================================
--- include/std/algorithm	(revision 173802)
+++ include/std/algorithm	(working copy)
@@ -66,4 +66,8 @@
 # include <parallel/algorithm>
 #endif
 
+#ifdef _GLIBCXX_DEBUG
+# include <debug/algorithm>
+#endif
+
 #endif /* _GLIBCXX_ALGORITHM */
Index: include/std/numeric
===================================================================
--- include/std/numeric	(revision 173802)
+++ include/std/numeric	(working copy)
@@ -65,6 +65,10 @@
 # include <parallel/numeric>
 #endif
 
+#ifdef _GLIBCXX_DEBUG
+# include <debug/numeric>
+#endif
+
 /**
  * @defgroup numerics Numerics
  *
Index: include/std/streambuf
===================================================================
--- include/std/streambuf	(revision 173802)
+++ include/std/streambuf	(working copy)
@@ -145,10 +145,10 @@
       __copy_streambufs_eof<>(__streambuf_type*, __streambuf_type*, bool&);
 
       template<bool _IsMove, typename _CharT2>
-        friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, 
+	friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
 					       _CharT2*>::__type
-        __copy_move_a2(istreambuf_iterator<_CharT2>,
-		       istreambuf_iterator<_CharT2>, _CharT2*);
+        __detail::__copy_move_a2(istreambuf_iterator<_CharT2>,
+				 istreambuf_iterator<_CharT2>, _CharT2*);
 
       template<typename _CharT2>
         friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
Index: include/parallel/multiway_merge.h
===================================================================
--- include/parallel/multiway_merge.h	(revision 173802)
+++ include/parallel/multiway_merge.h	(working copy)
@@ -922,6 +922,7 @@
 				__sentinel,
 				_DifferenceTp __length, _Compare __comp)
     {
+      using namespace std;
       _GLIBCXX_CALL(__length)
 
       typedef _DifferenceTp _DifferenceType;
@@ -958,7 +959,7 @@
 	case 0:
           break;
 	case 1:
-          __return_target = std::copy(__seqs_begin[0].first,
+          __return_target = _GLIBCXX_STD_A::copy(__seqs_begin[0].first,
 				      __seqs_begin[0].first + __length,
 				      __target);
           __seqs_begin[0].first += __length;
@@ -1036,6 +1037,7 @@
 				      _Compare __comp,
      std::vector<std::pair<_DifferenceType, _DifferenceType> > *__pieces)
     {
+      using namespace std;
       typedef typename std::iterator_traits<_RAIterIterator>
 	::difference_type _SeqNumber;
       typedef typename std::iterator_traits<_RAIterIterator>
@@ -1078,7 +1080,7 @@
 	  {
 	    // For each sequence.
 	    if (__slab > 0)
-	      __pieces[__slab][__seq].first = std::upper_bound
+	      __pieces[__slab][__seq].first = _GLIBCXX_STD_A::upper_bound
 		(__seqs_begin[__seq].first, __seqs_begin[__seq].second,
 		 __samples[__num_samples * __k * __slab / __num_threads],
 		 __comp)
@@ -1087,7 +1089,7 @@
 	      // Absolute beginning.
 	      __pieces[__slab][__seq].first = 0;
 	    if ((__slab + 1) < __num_threads)
-	      __pieces[__slab][__seq].second = std::upper_bound
+	      __pieces[__slab][__seq].second = _GLIBCXX_STD_A::upper_bound
 		(__seqs_begin[__seq].first, __seqs_begin[__seq].second,
 		 __samples[__num_samples * __k * (__slab + 1) / __num_threads],
 		 __comp)
Index: include/parallel/algorithm
===================================================================
--- include/parallel/algorithm	(revision 173802)
+++ include/parallel/algorithm	(working copy)
@@ -36,5 +36,6 @@
 #include <parallel/algorithmfwd.h>
 #include <parallel/algobase.h>
 #include <parallel/algo.h>
+#include <parallel/heap.h>
 
 #endif
Index: include/parallel/heap.h
===================================================================
--- include/parallel/heap.h	(revision 0)
+++ include/parallel/heap.h	(revision 0)
@@ -0,0 +1,107 @@
+// Heap implementation -*- C++ -*-
+
+// Copyright (C) 2011 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file parallel/heap.h
+ *  This is an internal header file, included by other library headers.
+ *  Do not attempt to use it directly. @headername{queue}
+ */
+
+#ifndef _GLIBCXX_PARALLEL_HEAP_H
+#define _GLIBCXX_PARALLEL_HEAP_H 1
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+namespace __parallel
+{
+  template<typename _RandomAccessIterator>
+    inline void
+    push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
+    { _GLIBCXX_STD_A::push_heap(__first, __last); }
+
+  template<typename _RandomAccessIterator, typename _Compare>
+    inline void
+    push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
+	      _Compare __comp)
+    { _GLIBCXX_STD_A::push_heap(__first, __last, __comp); }
+
+  template<typename _RandomAccessIterator>
+    inline void
+    pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
+    { _GLIBCXX_STD_A::pop_heap(__first, __last); }
+
+  template<typename _RandomAccessIterator, typename _Compare>
+    inline void
+    pop_heap(_RandomAccessIterator __first,
+	     _RandomAccessIterator __last, _Compare __comp)
+    { _GLIBCXX_STD_A::pop_heap(__first, __last, __comp); }
+
+  template<typename _RandomAccessIterator>
+    void
+    make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
+    { _GLIBCXX_STD_A::make_heap(__first, __last); }
+
+  template<typename _RandomAccessIterator, typename _Compare>
+    void
+    make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
+	      _Compare __comp)
+    { _GLIBCXX_STD_A::make_heap(__first, __last, __comp); }
+
+  template<typename _RandomAccessIterator>
+    void
+    sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
+    { _GLIBCXX_STD_A::sort_heap(__first, __last); }
+
+  template<typename _RandomAccessIterator, typename _Compare>
+    void
+    sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
+	      _Compare __comp)
+    { _GLIBCXX_STD_A::sort_heap(__first, __last, __comp); }
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  template<typename _RandomAccessIterator>
+    inline _RandomAccessIterator
+    is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last)
+    { return _GLIBCXX_STD_A::is_heap_until(__first, __last); }
+
+  template<typename _RandomAccessIterator, typename _Compare>
+    inline _RandomAccessIterator
+    is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last,
+		  _Compare __comp)
+    { return _GLIBCXX_STD_A::is_heap_until(__first, __last, __comp); }
+
+  template<typename _RandomAccessIterator>
+    inline bool
+    is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
+    { return _GLIBCXX_STD_A::is_heap(__first, __last); }
+
+  template<typename _RandomAccessIterator, typename _Compare>
+    inline bool
+    is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
+	    _Compare __comp)
+    { return _GLIBCXX_STD_A::is_heap(__first, __last, __comp); }
+#endif
+} // namespace __parallel
+} // namespace
+
+#endif

Property changes on: include/parallel/heap.h
___________________________________________________________________
Added: svn:eol-style
   + native

Index: include/parallel/multiway_mergesort.h
===================================================================
--- include/parallel/multiway_mergesort.h	(revision 173802)
+++ include/parallel/multiway_mergesort.h	(working copy)
@@ -194,6 +194,7 @@
 		 std::iterator_traits<_RAIter>::difference_type
 		 __num_samples) const
       {
+	using namespace std;
 	typedef std::iterator_traits<_RAIter> _TraitsType;
 	typedef typename _TraitsType::value_type _ValueType;
 	typedef typename _TraitsType::difference_type _DifferenceType;
@@ -215,7 +216,7 @@
 	    // For each sequence.
 	    if (__num_samples * __iam > 0)
 	      __sd->_M_pieces[__iam][__s]._M_begin =
-                std::lower_bound(__sd->_M_temporary[__s],
+                _GLIBCXX_STD_A::lower_bound(__sd->_M_temporary[__s],
 				 __sd->_M_temporary[__s]
 				 + (__sd->_M_starts[__s + 1]
 				    - __sd->_M_starts[__s]),
@@ -229,7 +230,7 @@
 	    if ((__num_samples * (__iam + 1)) <
 		(__num_samples * __sd->_M_num_threads))
 	      __sd->_M_pieces[__iam][__s]._M_end =
-                std::lower_bound(__sd->_M_temporary[__s],
+                _GLIBCXX_STD_A::lower_bound(__sd->_M_temporary[__s],
 				 __sd->_M_temporary[__s]
 				 + (__sd->_M_starts[__s + 1]
 				    - __sd->_M_starts[__s]),
Index: include/parallel/partition.h
===================================================================
--- include/parallel/partition.h	(revision 173802)
+++ include/parallel/partition.h	(working copy)
@@ -56,6 +56,7 @@
     __parallel_partition(_RAIter __begin, _RAIter __end,
 			 _Predicate __pred, _ThreadIndex __num_threads)
     {
+      using namespace std;
       typedef std::iterator_traits<_RAIter> _TraitsType;
       typedef typename _TraitsType::value_type _ValueType;
       typedef typename _TraitsType::difference_type _DifferenceType;
@@ -238,7 +239,7 @@
 		  _GLIBCXX_PARALLEL_ASSERT(__swapstart != -1);
 #endif
 
-		  std::swap_ranges(__begin + __thread_left_border
+		  _GLIBCXX_STD_A::swap_ranges(__begin + __thread_left_border
 				   - (__chunk_size - 1),
 				   __begin + __thread_left_border + 1,
 				   __begin + __swapstart);
Index: include/parallel/algobase.h
===================================================================
--- include/parallel/algobase.h	(revision 173802)
+++ include/parallel/algobase.h	(working copy)
@@ -45,6 +45,51 @@
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
+_GLIBCXX_BEGIN_NAMESPACE_PARALLEL_ALGO
+
+  template<typename _ForwardIterator1, typename _ForwardIterator2>
+    inline _ForwardIterator2
+    swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+		_ForwardIterator2 __first2)
+    { return _GLIBCXX_STD_A::swap_ranges(__first1, __last1, __first2); }
+
+  template<typename _II, typename _OI>
+    inline _OI
+    copy(_II __first, _II __last, _OI __result)
+    { return _GLIBCXX_STD_A::copy(__first, __last, __result); }
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  template<typename _II, typename _OI>
+    inline _OI
+    move(_II __first, _II __last, _OI __result)
+    { return _GLIBCXX_STD_A::move(__first, __last, __result); }
+#endif
+
+  template<typename _BI1, typename _BI2>
+    inline _BI2
+    copy_backward(_BI1 __first, _BI1 __last, _BI2 __result)
+    { return _GLIBCXX_STD_A::copy_backward(__first, __last, __result); }
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  template<typename _BI1, typename _BI2>
+    inline _BI2
+    move_backward(_BI1 __first, _BI1 __last, _BI2 __result)
+    { return _GLIBCXX_STD_A::move_backward(__first, __last, __result); }
+#endif
+
+  template<typename _ForwardIterator, typename _Tp>
+    inline void
+    fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value)
+    { _GLIBCXX_STD_A::fill(__first, __last, __value); }
+
+  template<typename _ForwardIterator, typename _Tp>
+    inline _ForwardIterator
+    lower_bound(_ForwardIterator __first, _ForwardIterator __last,
+                const _Tp& __val)
+    { return _GLIBCXX_STD_A::lower_bound(__first, __last, __val); }
+
+_GLIBCXX_END_NAMESPACE_PARALLEL_ALGO
+
 namespace __parallel
 {
   // NB: equal and lexicographical_compare require mismatch.
@@ -62,7 +107,10 @@
     mismatch(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2,
              _Predicate __pred, __gnu_parallel::sequential_tag)
     { return _GLIBCXX_STD_A::mismatch(__begin1, __end1, __begin2, __pred); }
+}
 
+namespace __detail
+{
   // Sequential fallback for input iterator case
   template<typename _IIter1, typename _IIter2,
            typename _Predicate, typename _IteratorTag1, typename _IteratorTag2>
@@ -89,7 +137,10 @@
       else
         return _GLIBCXX_STD_A::mismatch(__begin1, __end1, __begin2, __pred);
     }
+}
 
+_GLIBCXX_BEGIN_NAMESPACE_PARALLEL_ALGO
+
   // Public interface
   template<typename _IIter1, typename _IIter2>
     inline pair<_IIter1, _IIter2>
@@ -104,7 +155,7 @@
 
       typedef __gnu_parallel::_EqualTo<_ValueType1, _ValueType2> _EqualTo;
 
-      return __mismatch_switch(__begin1, __end1, __begin2, _EqualTo(),
+      return __detail::__mismatch_switch(__begin1, __end1, __begin2, _EqualTo(),
                                _IteratorCategory1(), _IteratorCategory2());
     }
 
@@ -119,10 +170,14 @@
       typedef typename _Iterator1Traits::iterator_category _IteratorCategory1;
       typedef typename _Iterator2Traits::iterator_category _IteratorCategory2;
 
-      return __mismatch_switch(__begin1, __end1, __begin2, __pred,
+      return __detail::__mismatch_switch(__begin1, __end1, __begin2, __pred,
                                _IteratorCategory1(), _IteratorCategory2());
     }
 
+_GLIBCXX_END_NAMESPACE_PARALLEL_ALGO
+
+namespace __parallel
+{
   // Sequential fallback
   template<typename _IIter1, typename _IIter2>
     inline bool
@@ -136,7 +191,10 @@
     equal(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2, 
           _Predicate __pred, __gnu_parallel::sequential_tag)
     { return _GLIBCXX_STD_A::equal(__begin1, __end1, __begin2, __pred); }
+}
 
+_GLIBCXX_BEGIN_NAMESPACE_PARALLEL_ALGO
+
   // Public interface
   template<typename _IIter1, typename _IIter2>
     inline bool
@@ -156,6 +214,10 @@
               == __end1;
     }
 
+_GLIBCXX_END_NAMESPACE_PARALLEL_ALGO
+
+namespace __parallel
+{
   // Sequential fallback
   template<typename _IIter1, typename _IIter2>
     inline bool
@@ -173,7 +235,10 @@
                             _Predicate __pred, __gnu_parallel::sequential_tag)
     { return _GLIBCXX_STD_A::lexicographical_compare(
                __begin1, __end1, __begin2, __end2, __pred); }
+}
 
+namespace __detail
+{
   // Sequential fallback for input iterator case
   template<typename _IIter1, typename _IIter2,
            typename _Predicate, typename _IteratorTag1, typename _IteratorTag2>
@@ -211,10 +276,11 @@
           if ((__end1 - __begin1) < (__end2 - __begin2))
             {
               typedef pair<_RAIter1, _RAIter2> _SpotType;
-              _SpotType __mm = __mismatch_switch(__begin1, __end1, __begin2, 
-                                             _EqualFromLessCompare(__pred), 
-                                             random_access_iterator_tag(), 
-                                             random_access_iterator_tag());
+              _SpotType __mm =
+		__detail::__mismatch_switch(__begin1, __end1, __begin2,
+					    _EqualFromLessCompare(__pred),
+					    random_access_iterator_tag(),
+					    random_access_iterator_tag());
 
               return (__mm.first == __end1)
                         || bool(__pred(*__mm.first, *__mm.second));
@@ -222,10 +288,11 @@
           else
             {
               typedef pair<_RAIter2, _RAIter1> _SpotType;
-              _SpotType __mm = __mismatch_switch(__begin2, __end2, __begin1, 
-                                             _EqualFromLessCompare(__pred), 
-                                             random_access_iterator_tag(), 
-                                             random_access_iterator_tag());
+              _SpotType __mm =
+		__detail::__mismatch_switch(__begin2, __end2, __begin1,
+					    _EqualFromLessCompare(__pred),
+					    random_access_iterator_tag(),
+					    random_access_iterator_tag());
 
               return (__mm.first != __end2)
                         && bool(__pred(*__mm.second, *__mm.first));
@@ -235,7 +302,10 @@
         return _GLIBCXX_STD_A::lexicographical_compare(
                  __begin1, __end1, __begin2, __end2, __pred);
     }
+}
 
+_GLIBCXX_BEGIN_NAMESPACE_PARALLEL_ALGO
+
   // Public interface
   template<typename _IIter1, typename _IIter2>
     inline bool
@@ -251,7 +321,7 @@
       typedef typename _TraitsType2::iterator_category _IteratorCategory2;
       typedef __gnu_parallel::_Less<_ValueType1, _ValueType2> _LessType;
 
-      return __lexicographical_compare_switch(
+      return __detail::__lexicographical_compare_switch(
                __begin1, __end1, __begin2, __end2, _LessType(),
                _IteratorCategory1(), _IteratorCategory2());
     }
@@ -269,11 +339,12 @@
       typedef iterator_traits<_IIter2> _TraitsType2;
       typedef typename _TraitsType2::iterator_category _IteratorCategory2;
 
-      return __lexicographical_compare_switch(
+      return __detail::__lexicographical_compare_switch(
                __begin1, __end1, __begin2, __end2, __pred,
                _IteratorCategory1(), _IteratorCategory2());
     }
+
+_GLIBCXX_END_NAMESPACE_PARALLEL_ALGO
 } // end namespace
-} // end namespace
 
 #endif /* _GLIBCXX_PARALLEL_ALGOBASE_H */
Index: include/ext/algorithm
===================================================================
--- include/ext/algorithm	(revision 173802)
+++ include/ext/algorithm	(working copy)
@@ -446,7 +446,7 @@
 	    typename iterator_traits<_RandomAccessIterator>::value_type>)
       __glibcxx_requires_valid_range(__first, __last);
 
-      return std::__is_heap(__first, __last - __first);
+      return std::__detail::__is_heap(__first, __last - __first);
     }
 
   /**
@@ -467,7 +467,7 @@
 	    typename iterator_traits<_RandomAccessIterator>::value_type>)
       __glibcxx_requires_valid_range(__first, __last);
 
-      return std::__is_heap(__first, __comp, __last - __first);
+      return std::__detail::__is_heap(__first, __comp, __last - __first);
     }
 #endif
 
Index: include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp
===================================================================
--- include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp	(revision 173802)
+++ include/ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp	(working copy)
@@ -137,7 +137,8 @@
 PB_DS_CLASS_C_DEC::
 get_nearest_larger_size(size_type n) const
 {
-  const std::size_t* const p_upper = std::upper_bound(detail::g_a_sizes, 
+  using namespace std;
+  const size_t* const p_upper = _GLIBCXX_STD_A::upper_bound(detail::g_a_sizes, 
 		     detail::g_a_sizes + detail::num_distinct_sizes, n);
 
   if (p_upper == detail::g_a_sizes + detail::num_distinct_sizes)
@@ -150,7 +151,8 @@
 PB_DS_CLASS_C_DEC::
 get_nearest_smaller_size(size_type n) const
 {
-  const std::size_t* p_lower = std::lower_bound(detail::g_a_sizes, 
+  using namespace std;
+  const size_t* p_lower = _GLIBCXX_STD_A::lower_bound(detail::g_a_sizes, 
 		       detail::g_a_sizes + detail::num_distinct_sizes, n);
 
   if (*p_lower >= n &&  p_lower != detail::g_a_sizes)
Index: include/bits/hashtable.h
===================================================================
--- include/bits/hashtable.h	(revision 173802)
+++ include/bits/hashtable.h	(working copy)
@@ -539,7 +539,7 @@
       // We allocate one extra bucket to hold a sentinel, an arbitrary
       // non-null pointer.  Iterator increment relies on this.
       _Node** __p = __alloc.allocate(__n + 1);
-      std::fill(__p, __p + __n, (_Node*) 0);
+      _GLIBCXX_STD_A::fill(__p, __p + __n, (_Node*) 0);
       __p[__n] = reinterpret_cast<_Node*>(0x1000);
       return __p;
     }
Index: include/bits/stl_algobase.h
===================================================================
--- include/bits/stl_algobase.h	(revision 173802)
+++ include/bits/stl_algobase.h	(working copy)
@@ -67,11 +67,12 @@
 #include <bits/stl_iterator_base_funcs.h>
 #include <bits/stl_iterator.h>
 #include <bits/concept_check.h>
-#include <debug/debug.h>
 #include <bits/move.h> // For std::swap and _GLIBCXX_MOVE
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
+namespace __detail
+{
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   // See http://gcc.gnu.org/ml/libstdc++/2004-08/msg00167.html: in a
@@ -99,10 +100,14 @@
         static void 
         iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
         {
-          swap(*__a, *__b);
+	  swap(*__a, *__b);
         }
     };
+_GLIBCXX_END_NAMESPACE_VERSION
+}
 
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   /**
    *  @brief Swaps the contents of two iterators.
    *  @ingroup mutating_algorithms
@@ -136,12 +141,15 @@
 	_ReferenceType1;
       typedef typename iterator_traits<_ForwardIterator2>::reference
 	_ReferenceType2;
-      std::__iter_swap<__are_same<_ValueType1, _ValueType2>::__value
+      __detail::__iter_swap<__are_same<_ValueType1, _ValueType2>::__value
 	&& __are_same<_ValueType1&, _ReferenceType1>::__value
 	&& __are_same<_ValueType2&, _ReferenceType2>::__value>::
 	iter_swap(__a, __b);
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   /**
    *  @brief Swap the elements of two sequences.
    *  @ingroup mutating_algorithms
@@ -164,13 +172,15 @@
 				  _ForwardIterator1>)
       __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
 				  _ForwardIterator2>)
-      __glibcxx_requires_valid_range(__first1, __last1);
 
       for (; __first1 != __last1; ++__first1, ++__first2)
 	std::iter_swap(__first1, __first2);
       return __first2;
     }
 
+_GLIBCXX_END_NAMESPACE_ALGO
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   /**
    *  @brief This does what you think it does.
    *  @ingroup sorting_algorithms
@@ -259,6 +269,11 @@
       return __a;
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+namespace __detail
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   // If _Iterator is a __normal_iterator return its base (a plain pointer,
   // normally) otherwise return it untouched.  See copy, fill, ... 
   template<typename _Iterator>
@@ -269,7 +284,7 @@
   template<typename _Iterator>
     inline typename _Niter_base<_Iterator>::iterator_type
     __niter_base(_Iterator __it)
-    { return std::_Niter_base<_Iterator>::_S_base(__it); }
+    { return _Niter_base<_Iterator>::_S_base(__it); }
 
   // Likewise, for move_iterator.
   template<typename _Iterator>
@@ -280,7 +295,7 @@
   template<typename _Iterator>
     inline typename _Miter_base<_Iterator>::iterator_type
     __miter_base(_Iterator __it)
-    { return std::_Miter_base<_Iterator>::_S_base(__it); }
+    { return _Miter_base<_Iterator>::_S_base(__it); }
 
   // All of these auxiliary structs serve two purposes.  (1) Replace
   // calls to copy with memmove whenever possible.  (Memmove, not memcpy,
@@ -380,10 +395,15 @@
 	                     && __is_pointer<_OI>::__value
 			     && __are_same<_ValueTypeI, _ValueTypeO>::__value);
 
-      return std::__copy_move<_IsMove, __simple,
-	                      _Category>::__copy_m(__first, __last, __result);
+      return __copy_move<_IsMove, __simple,
+			 _Category>::__copy_m(__first, __last, __result);
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   // Helpers for streambuf iterators (either istream or ostream).
   // NB: avoid including <iosfwd>, relatively large.
   template<typename _CharT>
@@ -395,6 +415,11 @@
   template<typename _CharT, typename _Traits>
     class ostreambuf_iterator;
 
+_GLIBCXX_END_NAMESPACE_VERSION
+namespace __detail
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   template<bool _IsMove, typename _CharT>
     typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, 
 	     ostreambuf_iterator<_CharT, char_traits<_CharT> > >::__type
@@ -411,17 +436,23 @@
     typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
 				    _CharT*>::__type
     __copy_move_a2(istreambuf_iterator<_CharT, char_traits<_CharT> >,
-		   istreambuf_iterator<_CharT, char_traits<_CharT> >, _CharT*);
+		   istreambuf_iterator<_CharT, char_traits<_CharT> >,
+		   _CharT*);
 
   template<bool _IsMove, typename _II, typename _OI>
     inline _OI
-    __copy_move_a2(_II __first, _II __last, _OI __result)
+    __copy_move_a2(_II __first, _II __last, _OI __res)
     {
-      return _OI(std::__copy_move_a<_IsMove>(std::__niter_base(__first),
-					     std::__niter_base(__last),
-					     std::__niter_base(__result)));
+      return _OI(__detail::__copy_move_a<_IsMove>
+		      (__detail::__niter_base(__first),
+		       __detail::__niter_base(__last),
+		       __detail::__niter_base(__res)));
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   /**
    *  @brief Copies the range [first,last) into result.
    *  @ingroup mutating_algorithms
@@ -447,11 +478,10 @@
       __glibcxx_function_requires(_InputIteratorConcept<_II>)
       __glibcxx_function_requires(_OutputIteratorConcept<_OI,
 	    typename iterator_traits<_II>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
-      return (std::__copy_move_a2<__is_move_iterator<_II>::__value>
-	      (std::__miter_base(__first), std::__miter_base(__last),
-	       __result));
+      return __detail::__copy_move_a2<std::__is_move_iterator<_II>::__value>
+	      (__detail::__miter_base(__first), __detail::__miter_base(__last),
+	       __result);
     }
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
@@ -480,17 +510,22 @@
       __glibcxx_function_requires(_InputIteratorConcept<_II>)
       __glibcxx_function_requires(_OutputIteratorConcept<_OI,
 	    typename iterator_traits<_II>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
-      return std::__copy_move_a2<true>(std::__miter_base(__first),
-				       std::__miter_base(__last), __result);
+      return __detail::__copy_move_a2<true>(__detail::__miter_base(__first),
+					     __detail::__miter_base(__last),
+					     __result);
     }
 
-#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp)
+#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) _GLIBCXX_STD_A::move(_Tp, _Up, _Vp)
 #else
-#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::copy(_Tp, _Up, _Vp)
+#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) _GLIBCXX_STD_A::copy(_Tp, _Up, _Vp)
 #endif
 
+_GLIBCXX_END_NAMESPACE_ALGO
+namespace __detail
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   template<bool, bool, typename>
     struct __copy_move_backward
     {
@@ -575,21 +610,24 @@
 	                     && __is_pointer<_BI2>::__value
 			     && __are_same<_ValueType1, _ValueType2>::__value);
 
-      return std::__copy_move_backward<_IsMove, __simple,
-	                               _Category>::__copy_move_b(__first,
-								 __last,
-								 __result);
+      return __copy_move_backward<_IsMove, __simple,
+				  _Category>::__copy_move_b(__first, __last, __result);
     }
 
   template<bool _IsMove, typename _BI1, typename _BI2>
     inline _BI2
     __copy_move_backward_a2(_BI1 __first, _BI1 __last, _BI2 __result)
     {
-      return _BI2(std::__copy_move_backward_a<_IsMove>
-		  (std::__niter_base(__first), std::__niter_base(__last),
-		   std::__niter_base(__result)));
+      return _BI2(__detail::__copy_move_backward_a<_IsMove>
+		  (__detail::__niter_base(__first),
+		   __detail::__niter_base(__last),
+		   __detail::__niter_base(__result)));
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   /**
    *  @brief Copies the range [first,last) into result.
    *  @ingroup mutating_algorithms
@@ -618,10 +656,11 @@
       __glibcxx_function_requires(_ConvertibleConcept<
 	    typename iterator_traits<_BI1>::value_type,
 	    typename iterator_traits<_BI2>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
-      return (std::__copy_move_backward_a2<__is_move_iterator<_BI1>::__value>
-	      (std::__miter_base(__first), std::__miter_base(__last),
+      const bool __is_move_it = __is_move_iterator<_BI1>::__value;
+      return (__detail::__copy_move_backward_a2<__is_move_it>
+	      (__detail::__miter_base(__first),
+	       __detail::__miter_base(__last),
 	       __result));
     }
 
@@ -654,18 +693,25 @@
       __glibcxx_function_requires(_ConvertibleConcept<
 	    typename iterator_traits<_BI1>::value_type,
 	    typename iterator_traits<_BI2>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
-      return std::__copy_move_backward_a2<true>(std::__miter_base(__first),
-						std::__miter_base(__last),
-						__result);
+      return __detail::__copy_move_backward_a2<true>
+      		(__detail::__miter_base(__first),
+		 __detail::__miter_base(__last),
+		 __result);
     }
 
-#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::move_backward(_Tp, _Up, _Vp)
+#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp)\
+       	_GLIBCXX_STD_A::move_backward(_Tp, _Up, _Vp)
 #else
-#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp) std::copy_backward(_Tp, _Up, _Vp)
+#define _GLIBCXX_MOVE_BACKWARD3(_Tp, _Up, _Vp)\
+       	_GLIBCXX_STD_A::copy_backward(_Tp, _Up, _Vp)
 #endif
 
+_GLIBCXX_END_NAMESPACE_ALGO
+namespace __detail
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   template<typename _ForwardIterator, typename _Tp>
     inline typename
     __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, void>::__type
@@ -698,6 +744,10 @@
 		       __last - __first);
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   /**
    *  @brief Fills the range [first,last) with copies of value.
    *  @ingroup mutating_algorithms
@@ -717,15 +767,21 @@
       // concept requirements
       __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
 				  _ForwardIterator>)
-      __glibcxx_requires_valid_range(__first, __last);
 
-      std::__fill_a(std::__niter_base(__first), std::__niter_base(__last),
-		    __value);
+      __detail::__fill_a(__detail::__niter_base(__first),
+			 __detail::__niter_base(__last),
+			 __value);
     }
 
+_GLIBCXX_END_NAMESPACE_ALGO
+namespace __detail
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   template<typename _OutputIterator, typename _Size, typename _Tp>
     inline typename
-    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
+    __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value,
+			   _OutputIterator>::__type
     __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)
     {
       for (__decltype(__n + 0) __niter = __n;
@@ -736,7 +792,8 @@
 
   template<typename _OutputIterator, typename _Size, typename _Tp>
     inline typename
-    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
+    __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value,
+			   _OutputIterator>::__type
     __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)
     {
       const _Tp __tmp = __value;
@@ -751,10 +808,14 @@
     __gnu_cxx::__enable_if<__is_byte<_Tp>::__value, _Tp*>::__type
     __fill_n_a(_Tp* __first, _Size __n, const _Tp& __c)
     {
-      std::__fill_a(__first, __first + __n, __c);
+      __detail::__fill_a(__first, __first + __n, __c);
       return __first + __n;
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   /**
    *  @brief Fills the range [first,first+n) with copies of value.
    *  @ingroup mutating_algorithms
@@ -777,9 +838,15 @@
       // concept requirements
       __glibcxx_function_requires(_OutputIteratorConcept<_OI, _Tp>)
 
-      return _OI(std::__fill_n_a(std::__niter_base(__first), __n, __value));
+      return _OI(__detail::__fill_n_a(__detail::__niter_base(__first),
+				      __n, __value));
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+namespace __detail
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   template<bool _BoolType>
     struct __equal
     {
@@ -815,9 +882,10 @@
       const bool __simple = (__is_integer<_ValueType1>::__value
 	                     && __is_pointer<_II1>::__value
 	                     && __is_pointer<_II2>::__value
-			     && __are_same<_ValueType1, _ValueType2>::__value);
+			     && __are_same<_ValueType1,
+					   _ValueType2>::__value);
 
-      return std::__equal<__simple>::equal(__first1, __last1, __first2);
+      return __equal<__simple>::equal(__first1, __last1, __first2);
     }
 
 
@@ -836,7 +904,8 @@
     };
 
   template<>
-    struct __lc_rai<random_access_iterator_tag, random_access_iterator_tag>
+    struct __lc_rai<random_access_iterator_tag,
+		    random_access_iterator_tag>
     {
       template<typename _RAI1, typename _RAI2>
         static _RAI1
@@ -869,9 +938,11 @@
       __lexicographical_compare<_BoolType>::
       __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
       {
-	typedef typename iterator_traits<_II1>::iterator_category _Category1;
-	typedef typename iterator_traits<_II2>::iterator_category _Category2;
-	typedef std::__lc_rai<_Category1, _Category2> 	__rai_type;
+	typedef typename iterator_traits<_II1>::iterator_category
+	       	_Category1;
+	typedef typename iterator_traits<_II2>::iterator_category
+	       	_Category2;
+	typedef __detail::__lc_rai<_Category1, _Category2> 	__rai_type;
 	
 	__last1 = __rai_type::__newlast1(__first1, __last1,
 					 __first2, __last2);
@@ -897,7 +968,7 @@
 	  const size_t __len1 = __last1 - __first1;
 	  const size_t __len2 = __last2 - __first2;
 	  const int __result = __builtin_memcmp(__first1, __first2,
-						std::min(__len1, __len2));
+						min(__len1, __len2));
 	  return __result != 0 ? __result < 0 : __len1 < __len2;
 	}
     };
@@ -910,16 +981,21 @@
       typedef typename iterator_traits<_II1>::value_type _ValueType1;
       typedef typename iterator_traits<_II2>::value_type _ValueType2;
       const bool __simple =
-	(__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value
+	(__is_byte<_ValueType1>::__value
+	 && __is_byte<_ValueType2>::__value
 	 && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed
 	 && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed
 	 && __is_pointer<_II1>::__value
 	 && __is_pointer<_II2>::__value);
 
-      return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
-							    __first2, __last2);
+      return __detail::__lexicographical_compare<__simple>::__lc
+	      (__first1, __last1, __first2, __last2);
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   /**
    *  @brief Finds the first position in which @a val could be inserted
    *         without changing the ordering.
@@ -944,7 +1020,6 @@
       // concept requirements
       __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
       __glibcxx_function_requires(_LessThanOpConcept<_ValueType, _Tp>)
-      __glibcxx_requires_partitioned_lower(__first, __last, __val);
 
       _DistanceType __len = std::distance(__first, __last);
 
@@ -965,6 +1040,11 @@
       return __first;
     }
 
+_GLIBCXX_END_NAMESPACE_ALGO
+namespace __detail
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   /// This is a helper function for the sort routines and for random.tcc.
   //  Precondition: __n > 0.
   template<typename _Size>
@@ -990,7 +1070,7 @@
   { return sizeof(long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
 
 _GLIBCXX_END_NAMESPACE_VERSION
-
+}
 _GLIBCXX_BEGIN_NAMESPACE_ALGO
 
   /**
@@ -1015,11 +1095,10 @@
       __glibcxx_function_requires(_EqualOpConcept<
 	    typename iterator_traits<_II1>::value_type,
 	    typename iterator_traits<_II2>::value_type>)
-      __glibcxx_requires_valid_range(__first1, __last1);
 
-      return std::__equal_aux(std::__niter_base(__first1),
-			      std::__niter_base(__last1),
-			      std::__niter_base(__first2));
+      return __detail::__equal_aux(__detail::__niter_base(__first1),
+				   __detail::__niter_base(__last1),
+				   __detail::__niter_base(__first2));
     }
 
   /**
@@ -1045,7 +1124,6 @@
       // concept requirements
       __glibcxx_function_requires(_InputIteratorConcept<_IIter1>)
       __glibcxx_function_requires(_InputIteratorConcept<_IIter2>)
-      __glibcxx_requires_valid_range(__first1, __last1);
 
       for (; __first1 != __last1; ++__first1, ++__first2)
 	if (!bool(__binary_pred(*__first1, *__first2)))
@@ -1080,13 +1158,12 @@
       __glibcxx_function_requires(_InputIteratorConcept<_II2>)
       __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
       __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
-      __glibcxx_requires_valid_range(__first1, __last1);
-      __glibcxx_requires_valid_range(__first2, __last2);
 
-      return std::__lexicographical_compare_aux(std::__niter_base(__first1),
-						std::__niter_base(__last1),
-						std::__niter_base(__first2),
-						std::__niter_base(__last2));
+      return __detail::__lexicographical_compare_aux
+      			(__detail::__niter_base(__first1),
+			 __detail::__niter_base(__last1),
+			 __detail::__niter_base(__first2),
+			 __detail::__niter_base(__last2));
     }
 
   /**
@@ -1109,13 +1186,11 @@
     {
       typedef typename iterator_traits<_II1>::iterator_category _Category1;
       typedef typename iterator_traits<_II2>::iterator_category _Category2;
-      typedef std::__lc_rai<_Category1, _Category2> 	__rai_type;
+      typedef __detail::__lc_rai<_Category1, _Category2> 	__rai_type;
 
       // concept requirements
       __glibcxx_function_requires(_InputIteratorConcept<_II1>)
       __glibcxx_function_requires(_InputIteratorConcept<_II2>)
-      __glibcxx_requires_valid_range(__first1, __last1);
-      __glibcxx_requires_valid_range(__first2, __last2);
 
       __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2);
       for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
@@ -1153,7 +1228,6 @@
       __glibcxx_function_requires(_EqualOpConcept<
 	    typename iterator_traits<_InputIterator1>::value_type,
 	    typename iterator_traits<_InputIterator2>::value_type>)
-      __glibcxx_requires_valid_range(__first1, __last1);
 
       while (__first1 != __last1 && *__first1 == *__first2)
         {
@@ -1188,7 +1262,6 @@
       // concept requirements
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
-      __glibcxx_requires_valid_range(__first1, __last1);
 
       while (__first1 != __last1 && bool(__binary_pred(*__first1, *__first2)))
         {
@@ -1208,4 +1281,8 @@
 # include <parallel/algobase.h>
 #endif
 
+#ifdef _GLIBCXX_DEBUG
+# include <debug/algobase.h>
 #endif
+
+#endif
Index: include/bits/stl_heap.h
===================================================================
--- include/bits/stl_heap.h	(revision 173802)
+++ include/bits/stl_heap.h	(working copy)
@@ -56,11 +56,12 @@
 #ifndef _STL_HEAP_H
 #define _STL_HEAP_H 1
 
-#include <debug/debug.h>
 #include <bits/move.h>
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
+namespace __detail
+{
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /**
@@ -105,24 +106,24 @@
   template<typename _RandomAccessIterator, typename _Distance>
     inline bool
     __is_heap(_RandomAccessIterator __first, _Distance __n)
-    { return std::__is_heap_until(__first, __n) == __n; }
+    { return __detail::__is_heap_until(__first, __n) == __n; }
 
   template<typename _RandomAccessIterator, typename _Compare,
 	   typename _Distance>
     inline bool
     __is_heap(_RandomAccessIterator __first, _Compare __comp, _Distance __n)
-    { return std::__is_heap_until(__first, __n, __comp) == __n; }
+    { return __detail::__is_heap_until(__first, __n, __comp) == __n; }
 
   template<typename _RandomAccessIterator>
     inline bool
     __is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
-    { return std::__is_heap(__first, std::distance(__first, __last)); }
+    { return __detail::__is_heap(__first, std::distance(__first, __last)); }
 
   template<typename _RandomAccessIterator, typename _Compare>
     inline bool
     __is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
 	      _Compare __comp)
-    { return std::__is_heap(__first, __comp, std::distance(__first, __last)); }
+    { return __detail::__is_heap(__first, __comp, std::distance(__first, __last)); }
 
   // Heap-manipulation functions: push_heap, pop_heap, make_heap, sort_heap,
   // + is_heap and is_heap_until in C++0x.
@@ -142,6 +143,10 @@
       *(__first + __holeIndex) = _GLIBCXX_MOVE(__value);
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   /**
    *  @brief  Push an element onto a heap.
    *  @param  first  Start of heap.
@@ -164,14 +169,17 @@
       __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
 	    _RandomAccessIterator>)
       __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
-      __glibcxx_requires_valid_range(__first, __last);
-      __glibcxx_requires_heap(__first, __last - 1);
 
       _ValueType __value = _GLIBCXX_MOVE(*(__last - 1));
-      std::__push_heap(__first, _DistanceType((__last - __first) - 1),
+      __detail::__push_heap(__first, _DistanceType((__last - __first) - 1),
 		       _DistanceType(0), _GLIBCXX_MOVE(__value));
     }
 
+_GLIBCXX_END_NAMESPACE_ALGO
+namespace __detail
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   template<typename _RandomAccessIterator, typename _Distance, typename _Tp,
 	   typename _Compare>
     void
@@ -189,6 +197,10 @@
       *(__first + __holeIndex) = _GLIBCXX_MOVE(__value);
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   /**
    *  @brief  Push an element onto a heap using comparison functor.
    *  @param  first  Start of heap.
@@ -213,14 +225,17 @@
       // concept requirements
       __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
 	    _RandomAccessIterator>)
-      __glibcxx_requires_valid_range(__first, __last);
-      __glibcxx_requires_heap_pred(__first, __last - 1, __comp);
 
       _ValueType __value = _GLIBCXX_MOVE(*(__last - 1));
-      std::__push_heap(__first, _DistanceType((__last - __first) - 1),
+      __detail::__push_heap(__first, _DistanceType((__last - __first) - 1),
 		       _DistanceType(0), _GLIBCXX_MOVE(__value), __comp);
     }
 
+_GLIBCXX_END_NAMESPACE_ALGO
+namespace __detail
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   template<typename _RandomAccessIterator, typename _Distance, typename _Tp>
     void
     __adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex,
@@ -243,7 +258,7 @@
 						     + (__secondChild - 1)));
 	  __holeIndex = __secondChild - 1;
 	}
-      std::__push_heap(__first, __holeIndex, __topIndex,
+      __detail::__push_heap(__first, __holeIndex, __topIndex,
 		       _GLIBCXX_MOVE(__value));
     }
 
@@ -259,11 +274,15 @@
 
       _ValueType __value = _GLIBCXX_MOVE(*__result);
       *__result = _GLIBCXX_MOVE(*__first);
-      std::__adjust_heap(__first, _DistanceType(0),
+      __detail::__adjust_heap(__first, _DistanceType(0),
 			 _DistanceType(__last - __first),
 			 _GLIBCXX_MOVE(__value));
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   /**
    *  @brief  Pop an element off a heap.
    *  @param  first  Start of heap.
@@ -284,13 +303,16 @@
       __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
 	    _RandomAccessIterator>)
       __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
-      __glibcxx_requires_valid_range(__first, __last);
-      __glibcxx_requires_heap(__first, __last);
 
       --__last;
-      std::__pop_heap(__first, __last, __last);
+      __detail::__pop_heap(__first, __last, __last);
     }
 
+_GLIBCXX_END_NAMESPACE_ALGO
+namespace __detail
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   template<typename _RandomAccessIterator, typename _Distance,
 	   typename _Tp, typename _Compare>
     void
@@ -315,7 +337,7 @@
 						     + (__secondChild - 1)));
 	  __holeIndex = __secondChild - 1;
 	}
-      std::__push_heap(__first, __holeIndex, __topIndex, 
+      __detail::__push_heap(__first, __holeIndex, __topIndex, 
 		       _GLIBCXX_MOVE(__value), __comp);      
     }
 
@@ -331,11 +353,15 @@
 
       _ValueType __value = _GLIBCXX_MOVE(*__result);
       *__result = _GLIBCXX_MOVE(*__first);
-      std::__adjust_heap(__first, _DistanceType(0),
+      __detail::__adjust_heap(__first, _DistanceType(0),
 			 _DistanceType(__last - __first),
 			 _GLIBCXX_MOVE(__value), __comp);
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   /**
    *  @brief  Pop an element off a heap using comparison functor.
    *  @param  first  Start of heap.
@@ -355,11 +381,9 @@
       // concept requirements
       __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
 	    _RandomAccessIterator>)
-      __glibcxx_requires_valid_range(__first, __last);
-      __glibcxx_requires_heap_pred(__first, __last, __comp);
 
       --__last;
-      std::__pop_heap(__first, __last, __last, __comp);
+      __detail::__pop_heap(__first, __last, __last, __comp);
     }
 
   /**
@@ -383,7 +407,6 @@
       __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
 	    _RandomAccessIterator>)
       __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__last - __first < 2)
 	return;
@@ -393,7 +416,8 @@
       while (true)
 	{
 	  _ValueType __value = _GLIBCXX_MOVE(*(__first + __parent));
-	  std::__adjust_heap(__first, __parent, __len, _GLIBCXX_MOVE(__value));
+	  __detail::__adjust_heap(__first, __parent, __len,
+				  _GLIBCXX_MOVE(__value));
 	  if (__parent == 0)
 	    return;
 	  __parent--;
@@ -423,7 +447,6 @@
       // concept requirements
       __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
 	    _RandomAccessIterator>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__last - __first < 2)
 	return;
@@ -433,8 +456,8 @@
       while (true)
 	{
 	  _ValueType __value = _GLIBCXX_MOVE(*(__first + __parent));
-	  std::__adjust_heap(__first, __parent, __len, _GLIBCXX_MOVE(__value),
-			     __comp);
+	  __detail::__adjust_heap(__first, __parent, __len,
+				  _GLIBCXX_MOVE(__value), __comp);
 	  if (__parent == 0)
 	    return;
 	  __parent--;
@@ -458,13 +481,11 @@
 	    _RandomAccessIterator>)
       __glibcxx_function_requires(_LessThanComparableConcept<
 	    typename iterator_traits<_RandomAccessIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
-      __glibcxx_requires_heap(__first, __last);
 
       while (__last - __first > 1)
 	{
 	  --__last;
-	  std::__pop_heap(__first, __last, __last);
+	  __detail::__pop_heap(__first, __last, __last);
 	}
     }
 
@@ -486,13 +507,11 @@
       // concept requirements
       __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
 	    _RandomAccessIterator>)
-      __glibcxx_requires_valid_range(__first, __last);
-      __glibcxx_requires_heap_pred(__first, __last, __comp);
 
       while (__last - __first > 1)
 	{
 	  --__last;
-	  std::__pop_heap(__first, __last, __last, __comp);
+	  __detail::__pop_heap(__first, __last, __last, __comp);
 	}
     }
 
@@ -516,9 +535,8 @@
 	    _RandomAccessIterator>)
       __glibcxx_function_requires(_LessThanComparableConcept<
 	    typename iterator_traits<_RandomAccessIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
-      return __first + std::__is_heap_until(__first, std::distance(__first,
+      return __first + __detail::__is_heap_until(__first, std::distance(__first,
 								   __last));
     }
 
@@ -541,9 +559,8 @@
       // concept requirements
       __glibcxx_function_requires(_RandomAccessIteratorConcept<
 	    _RandomAccessIterator>)
-      __glibcxx_requires_valid_range(__first, __last);
 
-      return __first + std::__is_heap_until(__first, std::distance(__first,
+      return __first + __detail::__is_heap_until(__first, std::distance(__first,
 								   __last),
 					    __comp);
     }
@@ -558,7 +575,7 @@
   template<typename _RandomAccessIterator>
     inline bool
     is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
-    { return std::is_heap_until(__first, __last) == __last; }
+    { return _GLIBCXX_STD_A::is_heap_until(__first, __last) == __last; }
 
   /**
    *  @brief  Determines whether a range is a heap using comparison functor.
@@ -572,10 +589,18 @@
     inline bool
     is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
 	    _Compare __comp)
-    { return std::is_heap_until(__first, __last, __comp) == __last; }
+    { return _GLIBCXX_STD_A::is_heap_until(__first, __last, __comp) == __last; }
 #endif
 
-_GLIBCXX_END_NAMESPACE_VERSION
+_GLIBCXX_END_NAMESPACE_ALGO
 } // namespace
 
+#ifdef _GLIBCXX_PARALLEL
+# include <parallel/heap.h>
+#endif
+
+#ifdef _GLIBCXX_DEBUG
+# include <debug/heap.h>
+#endif
+
 #endif /* _STL_HEAP_H */
Index: include/bits/stl_numeric.h
===================================================================
--- include/bits/stl_numeric.h	(revision 173802)
+++ include/bits/stl_numeric.h	(working copy)
@@ -58,15 +58,13 @@
 #define _STL_NUMERIC_H 1
 
 #include <bits/concept_check.h>
-#include <debug/debug.h>
 #include <bits/move.h> // For _GLIBCXX_MOVE
 
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
-
 namespace std _GLIBCXX_VISIBILITY(default)
 {
-_GLIBCXX_BEGIN_NAMESPACE_VERSION
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
   /**
    *  @brief  Create a range of sequentially increasing values.
    *
@@ -87,7 +85,6 @@
 				  _ForwardIterator>)
       __glibcxx_function_requires(_ConvertibleConcept<_Tp,
 	    typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       for (; __first != __last; ++__first)
 	{
@@ -95,16 +92,8 @@
 	  ++__value;
 	}
     }
-
-_GLIBCXX_END_NAMESPACE_VERSION
-} // namespace std
-
 #endif
 
-namespace std _GLIBCXX_VISIBILITY(default)
-{
-_GLIBCXX_BEGIN_NAMESPACE_ALGO
-
   /**
    *  @brief  Accumulate values in a range.
    *
@@ -122,7 +111,6 @@
     {
       // concept requirements
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       for (; __first != __last; ++__first)
 	__init = __init + *__first;
@@ -149,7 +137,6 @@
     {
       // concept requirements
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       for (; __first != __last; ++__first)
 	__init = __binary_op(__init, *__first);
@@ -178,7 +165,6 @@
       // concept requirements
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
-      __glibcxx_requires_valid_range(__first1, __last1);
 
       for (; __first1 != __last1; ++__first1, ++__first2)
 	__init = __init + (*__first1 * *__first2);
@@ -212,7 +198,6 @@
       // concept requirements
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
-      __glibcxx_requires_valid_range(__first1, __last1);
 
       for (; __first1 != __last1; ++__first1, ++__first2)
 	__init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
@@ -244,7 +229,6 @@
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
       __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
 				                         _ValueType>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first == __last)
 	return __result;
@@ -284,7 +268,6 @@
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
       __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
 				                         _ValueType>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first == __last)
 	return __result;
@@ -323,7 +306,6 @@
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
       __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
 				                         _ValueType>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first == __last)
 	return __result;
@@ -365,7 +347,6 @@
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
       __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
 				                         _ValueType>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first == __last)
 	return __result;
Index: include/bits/stl_vector.h
===================================================================
--- include/bits/stl_vector.h	(revision 173802)
+++ include/bits/stl_vector.h	(working copy)
@@ -1272,7 +1272,8 @@
     inline bool
     operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
     { return (__x.size() == __y.size()
-	      && std::equal(__x.begin(), __x.end(), __y.begin())); }
+	      && _GLIBCXX_PARALLEL_A::equal(__x.begin(), __x.end(),
+					    __y.begin())); }
 
   /**
    *  @brief  Vector ordering relation.
@@ -1288,8 +1289,8 @@
   template<typename _Tp, typename _Alloc>
     inline bool
     operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
-    { return std::lexicographical_compare(__x.begin(), __x.end(),
-					  __y.begin(), __y.end()); }
+    { return _GLIBCXX_PARALLEL_A::lexicographical_compare
+	    (__x.begin(), __x.end(), __y.begin(), __y.end()); }
 
   /// Based on operator==
   template<typename _Tp, typename _Alloc>
Index: include/bits/stl_deque.h
===================================================================
--- include/bits/stl_deque.h	(revision 173802)
+++ include/bits/stl_deque.h	(working copy)
@@ -353,77 +353,83 @@
     operator+(ptrdiff_t __n, const _Deque_iterator<_Tp, _Ref, _Ptr>& __x)
     { return __x + __n; }
 
+_GLIBCXX_END_NAMESPACE_CONTAINER
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   template<typename _Tp>
     void
-    fill(const _Deque_iterator<_Tp, _Tp&, _Tp*>&,
-	 const _Deque_iterator<_Tp, _Tp&, _Tp*>&, const _Tp&);
+    fill(const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>&,
+	 const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>&, const _Tp&);
 
   template<typename _Tp>
-    _Deque_iterator<_Tp, _Tp&, _Tp*>
-    copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
-	 _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
-	 _Deque_iterator<_Tp, _Tp&, _Tp*>);
+    _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>
+    copy(_GLIBCXX_STD_C::_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
+	 _GLIBCXX_STD_C::_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
+	 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
 
   template<typename _Tp>
-    inline _Deque_iterator<_Tp, _Tp&, _Tp*>
-    copy(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
-	 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
-	 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
-    { return std::copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first),
-		       _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last),
-		       __result); }
+    inline _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>
+    copy(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
+	 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> __last,
+	 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> __result)
+    {
+      typedef _GLIBCXX_STD_C::_Deque_iterator<_Tp, const _Tp&, const _Tp*> _It;
+      return _GLIBCXX_STD_A::copy(_It(__first), _It(__last), __result);
+    }
 
   template<typename _Tp>
-    _Deque_iterator<_Tp, _Tp&, _Tp*>
-    copy_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
-		  _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
-		  _Deque_iterator<_Tp, _Tp&, _Tp*>);
+    _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>
+    copy_backward(_GLIBCXX_STD_C::_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
+		  _GLIBCXX_STD_C::_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
+		  _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
 
   template<typename _Tp>
-    inline _Deque_iterator<_Tp, _Tp&, _Tp*>
-    copy_backward(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
-		  _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
-		  _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
-    { return std::copy_backward(_Deque_iterator<_Tp,
-				const _Tp&, const _Tp*>(__first),
-				_Deque_iterator<_Tp,
-				const _Tp&, const _Tp*>(__last),
-				__result); }
+    inline _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>
+    copy_backward(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
+		  _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> __last,
+		  _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> __result)
+    {
+      typedef _GLIBCXX_STD_C::_Deque_iterator<_Tp, const _Tp&, const _Tp*> _It;
+      return _GLIBCXX_STD_A::copy_backward(_It(__first), _It(__last), __result);
+    }
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
   template<typename _Tp>
-    _Deque_iterator<_Tp, _Tp&, _Tp*>
-    move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
-	 _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
-	 _Deque_iterator<_Tp, _Tp&, _Tp*>);
+    _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>
+    move(_GLIBCXX_STD_C::_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
+	 _GLIBCXX_STD_C::_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
+	 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
 
   template<typename _Tp>
-    inline _Deque_iterator<_Tp, _Tp&, _Tp*>
-    move(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
-	 _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
-	 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
-    { return std::move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first),
-		       _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last),
-		       __result); }
+    inline _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>
+    move(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
+	 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> __last,
+	 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> __result)
+    {
+      typedef _GLIBCXX_STD_C::_Deque_iterator<_Tp, const _Tp&, const _Tp*> _It;
+      return _GLIBCXX_STD_A::move(_It(__first), _It(__last), __result);
+    }
 
   template<typename _Tp>
-    _Deque_iterator<_Tp, _Tp&, _Tp*>
-    move_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
-		  _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
-		  _Deque_iterator<_Tp, _Tp&, _Tp*>);
+    _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>
+    move_backward(_GLIBCXX_STD_C::_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
+		  _GLIBCXX_STD_C::_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
+		  _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>);
 
   template<typename _Tp>
-    inline _Deque_iterator<_Tp, _Tp&, _Tp*>
-    move_backward(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
-		  _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
-		  _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
-    { return std::move_backward(_Deque_iterator<_Tp,
-				const _Tp&, const _Tp*>(__first),
-				_Deque_iterator<_Tp,
-				const _Tp&, const _Tp*>(__last),
-				__result); }
+    inline _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>
+    move_backward(_GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
+		  _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> __last,
+		  _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> __result)
+    {
+      typedef _GLIBCXX_STD_C::_Deque_iterator<_Tp, const _Tp&, const _Tp*> _It;
+      return _GLIBCXX_STD_A::move_backward(_It(__first), _It(__last), __result);
+    }
 #endif
 
+_GLIBCXX_END_NAMESPACE_ALGO
+_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
+
   /**
    *  Deque base class.  This class provides the unified face for %deque's
    *  allocation.  This class's constructor and destructor allocate and
@@ -1688,11 +1694,11 @@
 	    {
 	      _ForwardIterator __mid = __first;
 	      std::advance(__mid, size());
-	      std::copy(__first, __mid, begin());
+	      _GLIBCXX_STD_A::copy(__first, __mid, begin());
 	      insert(end(), __mid, __last);
 	    }
 	  else
-	    _M_erase_at_end(std::copy(__first, __last, begin()));
+	    _M_erase_at_end(_GLIBCXX_STD_A::copy(__first, __last, begin()));
 	}
 
       // Called by assign(n,t), and the range assign when it turns out
@@ -1702,13 +1708,13 @@
       {
 	if (__n > size())
 	  {
-	    std::fill(begin(), end(), __val);
+	    _GLIBCXX_STD_A::fill(begin(), end(), __val);
 	    insert(end(), __n - size(), __val);
 	  }
 	else
 	  {
 	    _M_erase_at_end(begin() + difference_type(__n));
-	    std::fill(begin(), end(), __val);
+	    _GLIBCXX_STD_A::fill(begin(), end(), __val);
 	  }
       }
 
@@ -1915,9 +1921,10 @@
   template<typename _Tp, typename _Alloc>
     inline bool
     operator==(const deque<_Tp, _Alloc>& __x,
-                         const deque<_Tp, _Alloc>& __y)
+               const deque<_Tp, _Alloc>& __y)
     { return __x.size() == __y.size()
-             && std::equal(__x.begin(), __x.end(), __y.begin()); }
+             && _GLIBCXX_PARALLEL_A::equal(__x.begin(), __x.end(),
+					   __y.begin()); }
 
   /**
    *  @brief  Deque ordering relation.
@@ -1934,8 +1941,12 @@
     inline bool
     operator<(const deque<_Tp, _Alloc>& __x,
 	      const deque<_Tp, _Alloc>& __y)
-    { return std::lexicographical_compare(__x.begin(), __x.end(),
-					  __y.begin(), __y.end()); }
+    {
+      return _GLIBCXX_PARALLEL_A::lexicographical_compare(__x.begin(),
+							  __x.end(),
+							  __y.begin(),
+							  __y.end());
+    }
 
   /// Based on operator==
   template<typename _Tp, typename _Alloc>
Index: include/bits/stl_uninitialized.h
===================================================================
--- include/bits/stl_uninitialized.h	(revision 173802)
+++ include/bits/stl_uninitialized.h	(working copy)
@@ -92,7 +92,7 @@
         static _ForwardIterator
         __uninit_copy(_InputIterator __first, _InputIterator __last,
 		      _ForwardIterator __result)
-        { return std::copy(__first, __last, __result); }
+        { return _GLIBCXX_STD_A::copy(__first, __last, __result); }
     };
 
   /**
@@ -149,7 +149,7 @@
         static void
         __uninit_fill(_ForwardIterator __first, _ForwardIterator __last,
 		      const _Tp& __x)
-        { std::fill(__first, __last, __x); }
+        { _GLIBCXX_STD_A::fill(__first, __last, __x); }
     };
 
   /**
@@ -463,7 +463,7 @@
 	  typedef typename iterator_traits<_ForwardIterator>::value_type
 	    _ValueType;
 
-	  std::fill(__first, __last, _ValueType());
+	  _GLIBCXX_STD_A::fill(__first, __last, _ValueType());
 	}
     };
 
Index: include/bits/stl_algo.h
===================================================================
--- include/bits/stl_algo.h	(revision 173802)
+++ include/bits/stl_algo.h	(working copy)
@@ -72,6 +72,8 @@
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
+namespace __detail
+{
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /// Swaps the median value of *__a, *__b and *__c to *__a
@@ -607,9 +609,10 @@
 
       _RevIterator1 __rlast1(__first1);
       _RevIterator2 __rlast2(__first2);
-      _RevIterator1 __rresult = std::search(_RevIterator1(__last1), __rlast1,
-					    _RevIterator2(__last2), __rlast2,
-					    __comp);
+      _RevIterator1 __rresult =
+	_GLIBCXX_PARALLEL_A::search(_RevIterator1(__last1), __rlast1,
+				    _RevIterator2(__last2), __rlast2,
+				    __comp);
 
       if (__rresult == __rlast1)
 	return __last1;
@@ -621,6 +624,10 @@
 	}
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   /**
    *  @brief  Find last matching subsequence in a sequence.
    *  @ingroup non_mutating_algorithms
@@ -657,10 +664,8 @@
       __glibcxx_function_requires(_EqualOpConcept<
 	    typename iterator_traits<_ForwardIterator1>::value_type,
 	    typename iterator_traits<_ForwardIterator2>::value_type>)
-      __glibcxx_requires_valid_range(__first1, __last1);
-      __glibcxx_requires_valid_range(__first2, __last2);
 
-      return std::__find_end(__first1, __last1, __first2, __last2,
+      return __detail::__find_end(__first1, __last1, __first2, __last2,
 			     std::__iterator_category(__first1),
 			     std::__iterator_category(__first2));
     }
@@ -705,10 +710,8 @@
       __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
 	    typename iterator_traits<_ForwardIterator1>::value_type,
 	    typename iterator_traits<_ForwardIterator2>::value_type>)
-      __glibcxx_requires_valid_range(__first1, __last1);
-      __glibcxx_requires_valid_range(__first2, __last2);
 
-      return std::__find_end(__first1, __last1, __first2, __last2,
+      return __detail::__find_end(__first1, __last1, __first2, __last2,
 			     std::__iterator_category(__first1),
 			     std::__iterator_category(__first2),
 			     __comp);
@@ -730,7 +733,7 @@
   template<typename _InputIterator, typename _Predicate>
     inline bool
     all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
-    { return __last == std::find_if_not(__first, __last, __pred); }
+    { return __last == _GLIBCXX_STD_A::find_if_not(__first, __last, __pred); }
 
   /**
    *  @brief  Checks that a predicate is false for all the elements
@@ -764,7 +767,7 @@
   template<typename _InputIterator, typename _Predicate>
     inline bool
     any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
-    { return !std::none_of(__first, __last, __pred); }
+    { return !_GLIBCXX_STD_A::none_of(__first, __last, __pred); }
 
   /**
    *  @brief  Find the first element in a sequence for which a
@@ -785,8 +788,8 @@
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
       __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
 	      typename iterator_traits<_InputIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
-      return std::__find_if_not(__first, __last, __pred,
+
+      return __detail::__find_if_not(__first, __last, __pred,
 				std::__iterator_category(__first));
     }
 
@@ -805,8 +808,8 @@
     is_partitioned(_InputIterator __first, _InputIterator __last,
 		   _Predicate __pred)
     {
-      __first = std::find_if_not(__first, __last, __pred);
-      return std::none_of(__first, __last, __pred);
+      __first = _GLIBCXX_STD_A::find_if_not(__first, __last, __pred);
+      return _GLIBCXX_STD_A::none_of(__first, __last, __pred);
     }
 
   /**
@@ -828,9 +831,6 @@
       __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
 	      typename iterator_traits<_ForwardIterator>::value_type>)
 
-      // A specific debug-mode test will be necessary...
-      __glibcxx_requires_valid_range(__first, __last);
-
       typedef typename iterator_traits<_ForwardIterator>::difference_type
 	_DistanceType;
 
@@ -882,7 +882,6 @@
 	    typename iterator_traits<_InputIterator>::value_type>)
       __glibcxx_function_requires(_EqualOpConcept<
 	    typename iterator_traits<_InputIterator>::value_type, _Tp>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       for (; __first != __last; ++__first)
 	if (!(*__first == __value))
@@ -920,7 +919,6 @@
 	    typename iterator_traits<_InputIterator>::value_type>)
       __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
 	    typename iterator_traits<_InputIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       for (; __first != __last; ++__first)
 	if (!bool(__pred(*__first)))
@@ -959,7 +957,6 @@
 	    typename iterator_traits<_InputIterator>::value_type>)
       __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
 	    typename iterator_traits<_InputIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       for (; __first != __last; ++__first)
 	if (__pred(*__first))
@@ -970,6 +967,10 @@
       return __result;
     }
 
+_GLIBCXX_END_NAMESPACE_ALGO
+namespace __detail
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template<typename _InputIterator, typename _Size, typename _OutputIterator>
     _OutputIterator
@@ -990,8 +991,12 @@
     inline _OutputIterator
     __copy_n(_RandomAccessIterator __first, _Size __n,
 	     _OutputIterator __result, random_access_iterator_tag)
-    { return std::copy(__first, __first + __n, __result); }
+    { return _GLIBCXX_STD_A::copy(__first, __first + __n, __result); }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   /**
    *  @brief Copies the range [first,first+n) into [result,result+n).
    *  @ingroup mutating_algorithms
@@ -1014,10 +1019,13 @@
       __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
 	    typename iterator_traits<_InputIterator>::value_type>)
 
-      return std::__copy_n(__first, __n, __result,
-			   std::__iterator_category(__first));
+      return __detail::__copy_n(__first, __n, __result,
+				std::__iterator_category(__first));
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   /**
    *  @brief Copy the elements of a sequence to separate output sequences
    *         depending on the truth value of a predicate.
@@ -1048,7 +1056,6 @@
 	    typename iterator_traits<_InputIterator>::value_type>)
       __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
 	    typename iterator_traits<_InputIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
       
       for (; __first != __last; ++__first)
 	if (__pred(*__first))
@@ -1093,7 +1100,6 @@
 				  _ForwardIterator>)
       __glibcxx_function_requires(_EqualOpConcept<
 	    typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       __first = _GLIBCXX_STD_A::find(__first, __last, __value);
       if(__first == __last)
@@ -1136,7 +1142,6 @@
 				  _ForwardIterator>)
       __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
 	    typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       __first = _GLIBCXX_STD_A::find_if(__first, __last, __pred);
       if(__first == __last)
@@ -1175,7 +1180,6 @@
 				  _ForwardIterator>)
       __glibcxx_function_requires(_EqualityComparableConcept<
 		     typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       // Skip the beginning, if already unique.
       __first = _GLIBCXX_STD_A::adjacent_find(__first, __last);
@@ -1217,7 +1221,6 @@
       __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
 		typename iterator_traits<_ForwardIterator>::value_type,
 		typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       // Skip the beginning, if already unique.
       __first = _GLIBCXX_STD_A::adjacent_find(__first, __last, __binary_pred);
@@ -1233,6 +1236,11 @@
       return ++__dest;
     }
 
+_GLIBCXX_END_NAMESPACE_ALGO
+namespace __detail
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   /**
    *  This is an uglified unique_copy(_InputIterator, _InputIterator,
    *                                  _OutputIterator)
@@ -1422,6 +1430,10 @@
 	}
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   /**
    *  @brief Reverse a sequence.
    *  @ingroup mutating_algorithms
@@ -1441,8 +1453,7 @@
       // concept requirements
       __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
 				  _BidirectionalIterator>)
-      __glibcxx_requires_valid_range(__first, __last);
-      std::__reverse(__first, __last, std::__iterator_category(__first));
+      __detail::__reverse(__first, __last, std::__iterator_category(__first));
     }
 
   /**
@@ -1471,7 +1482,6 @@
 				  _BidirectionalIterator>)
       __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
 		typename iterator_traits<_BidirectionalIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       while (__first != __last)
 	{
@@ -1482,6 +1492,11 @@
       return __result;
     }
 
+_GLIBCXX_END_NAMESPACE_ALGO
+namespace __detail
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   /**
    *  This is a helper function for the rotate algorithm specialized on RAIs.
    *  It returns the greatest common divisor of two integer values.
@@ -1550,8 +1565,8 @@
       if (__first == __middle || __last  == __middle)
 	return;
 
-      std::__reverse(__first,  __middle, bidirectional_iterator_tag());
-      std::__reverse(__middle, __last,   bidirectional_iterator_tag());
+      __detail::__reverse(__first,  __middle, bidirectional_iterator_tag());
+      __detail::__reverse(__middle, __last,   bidirectional_iterator_tag());
 
       while (__first != __middle && __middle != __last)
 	{
@@ -1560,9 +1575,9 @@
 	}
 
       if (__first == __middle)
-	std::__reverse(__middle, __last,   bidirectional_iterator_tag());
+	__detail::__reverse(__middle, __last,   bidirectional_iterator_tag());
       else
-	std::__reverse(__first,  __middle, bidirectional_iterator_tag());
+	__detail::__reverse(__first,  __middle, bidirectional_iterator_tag());
     }
 
   /// This is a helper function for the rotate algorithm.
@@ -1590,7 +1605,7 @@
 
       if (__k == __n - __k)
 	{
-	  std::swap_ranges(__first, __middle, __middle);
+	  _GLIBCXX_STD_A::swap_ranges(__first, __middle, __middle);
 	  return;
 	}
 
@@ -1646,6 +1661,10 @@
 	}
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   /**
    *  @brief Rotate the elements of a sequence.
    *  @ingroup mutating_algorithms
@@ -1673,12 +1692,10 @@
       // concept requirements
       __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
 				  _ForwardIterator>)
-      __glibcxx_requires_valid_range(__first, __middle);
-      __glibcxx_requires_valid_range(__middle, __last);
 
       typedef typename iterator_traits<_ForwardIterator>::iterator_category
 	_IterType;
-      std::__rotate(__first, __middle, __last, _IterType());
+      __detail::__rotate(__first, __middle, __last, _IterType());
     }
 
   /**
@@ -1708,13 +1725,16 @@
       __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
       __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
 		typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __middle);
-      __glibcxx_requires_valid_range(__middle, __last);
 
-      return std::copy(__first, __middle,
-                       std::copy(__middle, __last, __result));
+      return _GLIBCXX_STD_A::copy(__first, __middle,
+                       _GLIBCXX_STD_A::copy(__middle, __last, __result));
     }
 
+_GLIBCXX_END_NAMESPACE_ALGO
+namespace __detail
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   /// This is a helper function...
   template<typename _ForwardIterator, typename _Predicate>
     _ForwardIterator
@@ -1781,15 +1801,13 @@
 	return __pred(*__first) ? __last : __first;
       _ForwardIterator __middle = __first;
       std::advance(__middle, __len / 2);
-      _ForwardIterator __begin = std::__inplace_stable_partition(__first,
-								 __middle,
-								 __pred,
-								 __len / 2);
-      _ForwardIterator __end = std::__inplace_stable_partition(__middle, __last,
-							       __pred,
-							       __len
-							       - __len / 2);
-      std::rotate(__begin, __middle, __end);
+      _ForwardIterator __begin =
+	__detail::__inplace_stable_partition(__first, __middle,
+					     __pred, __len / 2);
+      _ForwardIterator __end =
+	__detail::__inplace_stable_partition(__middle, __last,
+					     __pred, __len - __len / 2);
+      _GLIBCXX_STD_A::rotate(__begin, __middle, __end);
       std::advance(__begin, std::distance(__middle, __end));
       return __begin;
     }
@@ -1827,19 +1845,23 @@
 	  _ForwardIterator __middle = __first;
 	  std::advance(__middle, __len / 2);
 	  _ForwardIterator __begin =
-	    std::__stable_partition_adaptive(__first, __middle, __pred,
+	    __detail::__stable_partition_adaptive(__first, __middle, __pred,
 					     __len / 2, __buffer,
 					     __buffer_size);
 	  _ForwardIterator __end =
-	    std::__stable_partition_adaptive(__middle, __last, __pred,
+	    __detail::__stable_partition_adaptive(__middle, __last, __pred,
 					     __len - __len / 2,
 					     __buffer, __buffer_size);
-	  std::rotate(__begin, __middle, __end);
+	  _GLIBCXX_STD_A::rotate(__begin, __middle, __end);
 	  std::advance(__begin, std::distance(__middle, __end));
 	  return __begin;
 	}
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   /**
    *  @brief Move elements for which a predicate is true to the beginning
    *         of a sequence, preserving relative ordering.
@@ -1867,7 +1889,6 @@
 				  _ForwardIterator>)
       __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
 	    typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first == __last)
 	return __first;
@@ -1882,17 +1903,22 @@
 								__last);
 	if (__buf.size() > 0)
 	  return
-	    std::__stable_partition_adaptive(__first, __last, __pred,
+	    __detail::__stable_partition_adaptive(__first, __last, __pred,
 					  _DistanceType(__buf.requested_size()),
 					  __buf.begin(),
 					  _DistanceType(__buf.size()));
 	else
 	  return
-	    std::__inplace_stable_partition(__first, __last, __pred,
+	    __detail::__inplace_stable_partition(__first, __last, __pred,
 					 _DistanceType(__buf.requested_size()));
 	}
     }
 
+_GLIBCXX_END_NAMESPACE_ALGO
+namespace __detail
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   /// This is a helper function for the sort routines.
   template<typename _RandomAccessIterator>
     void
@@ -1900,10 +1926,10 @@
 		  _RandomAccessIterator __middle,
 		  _RandomAccessIterator __last)
     {
-      std::make_heap(__first, __middle);
+      _GLIBCXX_STD_A::make_heap(__first, __middle);
       for (_RandomAccessIterator __i = __middle; __i < __last; ++__i)
 	if (*__i < *__first)
-	  std::__pop_heap(__first, __middle, __i);
+	  __detail::__pop_heap(__first, __middle, __i);
     }
 
   /// This is a helper function for the sort routines.
@@ -1913,12 +1939,16 @@
 		  _RandomAccessIterator __middle,
 		  _RandomAccessIterator __last, _Compare __comp)
     {
-      std::make_heap(__first, __middle, __comp);
+      _GLIBCXX_STD_A::make_heap(__first, __middle, __comp);
       for (_RandomAccessIterator __i = __middle; __i < __last; ++__i)
 	if (__comp(*__i, *__first))
-	  std::__pop_heap(__first, __middle, __i, __comp);
+	  __detail::__pop_heap(__first, __middle, __i, __comp);
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   // partial_sort
 
   /**
@@ -1959,8 +1989,6 @@
       __glibcxx_function_requires(_LessThanOpConcept<_InputValueType,
 				                     _OutputValueType>)
       __glibcxx_function_requires(_LessThanComparableConcept<_OutputValueType>)
-      __glibcxx_requires_valid_range(__first, __last);
-      __glibcxx_requires_valid_range(__result_first, __result_last);
 
       if (__result_first == __result_last)
 	return __result_last;
@@ -1971,17 +1999,17 @@
 	  ++__result_real_last;
 	  ++__first;
 	}
-      std::make_heap(__result_first, __result_real_last);
+      _GLIBCXX_STD_A::make_heap(__result_first, __result_real_last);
       while (__first != __last)
 	{
 	  if (*__first < *__result_first)
-	    std::__adjust_heap(__result_first, _DistanceType(0),
+	    __detail::__adjust_heap(__result_first, _DistanceType(0),
 			       _DistanceType(__result_real_last
 					     - __result_first),
 			       _InputValueType(*__first));
 	  ++__first;
 	}
-      std::sort_heap(__result_first, __result_real_last);
+      _GLIBCXX_STD_A::sort_heap(__result_first, __result_real_last);
       return __result_real_last;
     }
 
@@ -2029,8 +2057,6 @@
 				  _InputValueType, _OutputValueType>)
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
 				  _OutputValueType, _OutputValueType>)
-      __glibcxx_requires_valid_range(__first, __last);
-      __glibcxx_requires_valid_range(__result_first, __result_last);
 
       if (__result_first == __result_last)
 	return __result_last;
@@ -2041,21 +2067,26 @@
 	  ++__result_real_last;
 	  ++__first;
 	}
-      std::make_heap(__result_first, __result_real_last, __comp);
+      _GLIBCXX_STD_A::make_heap(__result_first, __result_real_last, __comp);
       while (__first != __last)
 	{
 	  if (__comp(*__first, *__result_first))
-	    std::__adjust_heap(__result_first, _DistanceType(0),
+	    __detail::__adjust_heap(__result_first, _DistanceType(0),
 			       _DistanceType(__result_real_last
 					     - __result_first),
 			       _InputValueType(*__first),
 			       __comp);
 	  ++__first;
 	}
-      std::sort_heap(__result_first, __result_real_last, __comp);
+      _GLIBCXX_STD_A::sort_heap(__result_first, __result_real_last, __comp);
       return __result_real_last;
     }
 
+_GLIBCXX_END_NAMESPACE_ALGO
+namespace __detail
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   /// This is a helper function for the sort routine.
   template<typename _RandomAccessIterator>
     void
@@ -2112,7 +2143,7 @@
 	      *__first = _GLIBCXX_MOVE(__val);
 	    }
 	  else
-	    std::__unguarded_linear_insert(__i);
+	    __detail::__unguarded_linear_insert(__i);
 	}
     }
 
@@ -2134,7 +2165,7 @@
 	      *__first = _GLIBCXX_MOVE(__val);
 	    }
 	  else
-	    std::__unguarded_linear_insert(__i, __comp);
+	    __detail::__unguarded_linear_insert(__i, __comp);
 	}
     }
 
@@ -2148,7 +2179,7 @@
 	_ValueType;
 
       for (_RandomAccessIterator __i = __first; __i != __last; ++__i)
-	std::__unguarded_linear_insert(__i);
+	__detail::__unguarded_linear_insert(__i);
     }
 
   /// This is a helper function for the sort routine.
@@ -2161,7 +2192,7 @@
 	_ValueType;
 
       for (_RandomAccessIterator __i = __first; __i != __last; ++__i)
-	std::__unguarded_linear_insert(__i, __comp);
+	__detail::__unguarded_linear_insert(__i, __comp);
     }
 
   /**
@@ -2178,11 +2209,11 @@
     {
       if (__last - __first > int(_S_threshold))
 	{
-	  std::__insertion_sort(__first, __first + int(_S_threshold));
-	  std::__unguarded_insertion_sort(__first + int(_S_threshold), __last);
+	  __detail::__insertion_sort(__first, __first + int(_S_threshold));
+	  __detail::__unguarded_insertion_sort(__first + int(_S_threshold), __last);
 	}
       else
-	std::__insertion_sort(__first, __last);
+	__detail::__insertion_sort(__first, __last);
     }
 
   /// This is a helper function for the sort routine.
@@ -2193,12 +2224,12 @@
     {
       if (__last - __first > int(_S_threshold))
 	{
-	  std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
-	  std::__unguarded_insertion_sort(__first + int(_S_threshold), __last,
+	  __detail::__insertion_sort(__first, __first + int(_S_threshold), __comp);
+	  __detail::__unguarded_insertion_sort(__first + int(_S_threshold), __last,
 					  __comp);
 	}
       else
-	std::__insertion_sort(__first, __last, __comp);
+	__detail::__insertion_sort(__first, __last, __comp);
     }
 
   /// This is a helper function...
@@ -2249,8 +2280,8 @@
 				_RandomAccessIterator __last)
     {
       _RandomAccessIterator __mid = __first + (__last - __first) / 2;
-      std::__move_median_first(__first, __mid, (__last - 1));
-      return std::__unguarded_partition(__first + 1, __last, *__first);
+      __detail::__move_median_first(__first, __mid, (__last - 1));
+      return __detail::__unguarded_partition(__first + 1, __last, *__first);
     }
 
 
@@ -2261,8 +2292,9 @@
 				_RandomAccessIterator __last, _Compare __comp)
     {
       _RandomAccessIterator __mid = __first + (__last - __first) / 2;
-      std::__move_median_first(__first, __mid, (__last - 1), __comp);
-      return std::__unguarded_partition(__first + 1, __last, *__first, __comp);
+      __detail::__move_median_first(__first, __mid, (__last - 1), __comp);
+      return __detail::__unguarded_partition(__first + 1, __last, *__first,
+					     __comp);
     }
 
   /// This is a helper function for the sort routine.
@@ -2281,8 +2313,8 @@
 	    }
 	  --__depth_limit;
 	  _RandomAccessIterator __cut =
-	    std::__unguarded_partition_pivot(__first, __last);
-	  std::__introsort_loop(__cut, __last, __depth_limit);
+	    __detail::__unguarded_partition_pivot(__first, __last);
+	  __detail::__introsort_loop(__cut, __last, __depth_limit);
 	  __last = __cut;
 	}
     }
@@ -2303,8 +2335,8 @@
 	    }
 	  --__depth_limit;
 	  _RandomAccessIterator __cut =
-	    std::__unguarded_partition_pivot(__first, __last, __comp);
-	  std::__introsort_loop(__cut, __last, __depth_limit, __comp);
+	    __detail::__unguarded_partition_pivot(__first, __last, __comp);
+	  __detail::__introsort_loop(__cut, __last, __depth_limit, __comp);
 	  __last = __cut;
 	}
     }
@@ -2323,7 +2355,7 @@
 	{
 	  if (__depth_limit == 0)
 	    {
-	      std::__heap_select(__first, __nth + 1, __last);
+	      __detail::__heap_select(__first, __nth + 1, __last);
 
 	      // Place the nth largest element in its final position.
 	      std::iter_swap(__first, __nth);
@@ -2331,13 +2363,13 @@
 	    }
 	  --__depth_limit;
 	  _RandomAccessIterator __cut =
-	    std::__unguarded_partition_pivot(__first, __last);
+	    __detail::__unguarded_partition_pivot(__first, __last);
 	  if (__cut <= __nth)
 	    __first = __cut;
 	  else
 	    __last = __cut;
 	}
-      std::__insertion_sort(__first, __last);
+      __detail::__insertion_sort(__first, __last);
     }
 
   template<typename _RandomAccessIterator, typename _Size, typename _Compare>
@@ -2353,22 +2385,26 @@
 	{
 	  if (__depth_limit == 0)
 	    {
-	      std::__heap_select(__first, __nth + 1, __last, __comp);
+	      __detail::__heap_select(__first, __nth + 1, __last, __comp);
 	      // Place the nth largest element in its final position.
 	      std::iter_swap(__first, __nth);
 	      return;
 	    }
 	  --__depth_limit;
 	  _RandomAccessIterator __cut =
-	    std::__unguarded_partition_pivot(__first, __last, __comp);
+	    __detail::__unguarded_partition_pivot(__first, __last, __comp);
 	  if (__cut <= __nth)
 	    __first = __cut;
 	  else
 	    __last = __cut;
 	}
-      std::__insertion_sort(__first, __last, __comp);
+      __detail::__insertion_sort(__first, __last, __comp);
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   // nth_element
 
   // lower_bound moved to stl_algobase.h
@@ -2403,8 +2439,6 @@
       __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
 				  _ValueType, _Tp>)
-      __glibcxx_requires_partitioned_lower_pred(__first, __last,
-						__val, __comp);
 
       _DistanceType __len = std::distance(__first, __last);
 
@@ -2449,7 +2483,6 @@
       // concept requirements
       __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
       __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>)
-      __glibcxx_requires_partitioned_upper(__first, __last, __val);
 
       _DistanceType __len = std::distance(__first, __last);
 
@@ -2499,8 +2532,6 @@
       __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
 				  _Tp, _ValueType>)
-      __glibcxx_requires_partitioned_upper_pred(__first, __last,
-						__val, __comp);
 
       _DistanceType __len = std::distance(__first, __last);
 
@@ -2552,8 +2583,6 @@
       __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
       __glibcxx_function_requires(_LessThanOpConcept<_ValueType, _Tp>)
       __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>)	
-      __glibcxx_requires_partitioned_lower(__first, __last, __val);
-      __glibcxx_requires_partitioned_upper(__first, __last, __val);      
 
       _DistanceType __len = std::distance(__first, __last);
  
@@ -2572,11 +2601,11 @@
 	    __len = __half;
 	  else
 	    {
-	      _ForwardIterator __left = std::lower_bound(__first, __middle,
-							 __val);
+	      _ForwardIterator __left =
+		_GLIBCXX_STD_A::lower_bound(__first, __middle, __val);
 	      std::advance(__first, __len);
-	      _ForwardIterator __right = std::upper_bound(++__middle, __first,
-							  __val);
+	      _ForwardIterator __right =
+		_GLIBCXX_STD_A::upper_bound(++__middle, __first, __val);
 	      return pair<_ForwardIterator, _ForwardIterator>(__left, __right);
 	    }
 	}
@@ -2616,10 +2645,6 @@
 				  _ValueType, _Tp>)
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
 				  _Tp, _ValueType>)
-      __glibcxx_requires_partitioned_lower_pred(__first, __last,
-						__val, __comp);
-      __glibcxx_requires_partitioned_upper_pred(__first, __last,
-						__val, __comp);
 
       _DistanceType __len = std::distance(__first, __last);
 
@@ -2638,11 +2663,11 @@
 	    __len = __half;
 	  else
 	    {
-	      _ForwardIterator __left = std::lower_bound(__first, __middle,
-							 __val, __comp);
+	      _ForwardIterator __left =
+		_GLIBCXX_STD_A::lower_bound(__first, __middle, __val, __comp);
 	      std::advance(__first, __len);
-	      _ForwardIterator __right = std::upper_bound(++__middle, __first,
-							  __val, __comp);
+	      _ForwardIterator __right =
+		_GLIBCXX_STD_A::upper_bound(++__middle, __first, __val, __comp);
 	      return pair<_ForwardIterator, _ForwardIterator>(__left, __right);
 	    }
 	}
@@ -2671,10 +2696,9 @@
       // concept requirements
       __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
       __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>)
-      __glibcxx_requires_partitioned_lower(__first, __last, __val);
-      __glibcxx_requires_partitioned_upper(__first, __last, __val);
 
-      _ForwardIterator __i = std::lower_bound(__first, __last, __val);
+      _ForwardIterator __i =
+	_GLIBCXX_STD_A::lower_bound(__first, __last, __val);
       return __i != __last && !(__val < *__i);
     }
 
@@ -2705,17 +2729,20 @@
       __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
 				  _Tp, _ValueType>)
-      __glibcxx_requires_partitioned_lower_pred(__first, __last,
-						__val, __comp);
-      __glibcxx_requires_partitioned_upper_pred(__first, __last,
-						__val, __comp);
 
-      _ForwardIterator __i = std::lower_bound(__first, __last, __val, __comp);
+      _ForwardIterator __i =
+	_GLIBCXX_STD_A::lower_bound(__first, __last, __val, __comp);
       return __i != __last && !bool(__comp(__val, *__i));
     }
 
+_GLIBCXX_END_NAMESPACE_ALGO
+
   // merge
 
+namespace __detail
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   /// This is a helper function for the merge routines.
   template<typename _BidirectionalIterator1, typename _BidirectionalIterator2,
 	   typename _BidirectionalIterator3>
@@ -2868,7 +2895,7 @@
 	}
       else
 	{
-	  std::rotate(__first, __middle, __last);
+	  _GLIBCXX_STD_A::rotate(__first, __middle, __last);
 	  std::advance(__first, std::distance(__middle, __last));
 	  return __first;
 	}
@@ -2887,13 +2914,13 @@
       if (__len1 <= __len2 && __len1 <= __buffer_size)
 	{
 	  _Pointer __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer);
-	  std::__move_merge(__buffer, __buffer_end, __middle, __last, __first);
+	  __detail::__move_merge(__buffer, __buffer_end, __middle, __last, __first);
 	}
       else if (__len2 <= __buffer_size)
 	{
 	  _Pointer __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer);
-	  std::__move_merge_backward(__first, __middle, __buffer,
-				    __buffer_end, __last);
+	  __detail::__move_merge_backward(__first, __middle, __buffer,
+					  __buffer_end, __last);
 	}
       else
 	{
@@ -2905,25 +2932,25 @@
 	    {
 	      __len11 = __len1 / 2;
 	      std::advance(__first_cut, __len11);
-	      __second_cut = std::lower_bound(__middle, __last,
-					      *__first_cut);
+	      __second_cut =
+		_GLIBCXX_STD_A::lower_bound(__middle, __last, *__first_cut);
 	      __len22 = std::distance(__middle, __second_cut);
 	    }
 	  else
 	    {
 	      __len22 = __len2 / 2;
 	      std::advance(__second_cut, __len22);
-	      __first_cut = std::upper_bound(__first, __middle,
-					     *__second_cut);
+	      __first_cut =
+		_GLIBCXX_STD_A::upper_bound(__first, __middle, *__second_cut);
 	      __len11 = std::distance(__first, __first_cut);
 	    }
 	  _BidirectionalIterator __new_middle =
-	    std::__rotate_adaptive(__first_cut, __middle, __second_cut,
+	    __detail::__rotate_adaptive(__first_cut, __middle, __second_cut,
 				   __len1 - __len11, __len22, __buffer,
 				   __buffer_size);
-	  std::__merge_adaptive(__first, __first_cut, __new_middle, __len11,
+	  __detail::__merge_adaptive(__first, __first_cut, __new_middle, __len11,
 				__len22, __buffer, __buffer_size);
-	  std::__merge_adaptive(__new_middle, __second_cut, __last,
+	  __detail::__merge_adaptive(__new_middle, __second_cut, __last,
 				__len1 - __len11,
 				__len2 - __len22, __buffer, __buffer_size);
 	}
@@ -2943,14 +2970,14 @@
       if (__len1 <= __len2 && __len1 <= __buffer_size)
 	{
 	  _Pointer __buffer_end = _GLIBCXX_MOVE3(__first, __middle, __buffer);
-	  std::__move_merge(__buffer, __buffer_end, __middle, __last,
-			    __first, __comp);
+	  __detail::__move_merge(__buffer, __buffer_end, __middle, __last,
+				 __first, __comp);
 	}
       else if (__len2 <= __buffer_size)
 	{
 	  _Pointer __buffer_end = _GLIBCXX_MOVE3(__middle, __last, __buffer);
-	  std::__move_merge_backward(__first, __middle, __buffer, __buffer_end,
-				     __last, __comp);
+	  __detail::__move_merge_backward(__first, __middle, __buffer, __buffer_end,
+					  __last, __comp);
 	}
       else
 	{
@@ -2962,25 +2989,27 @@
 	    {
 	      __len11 = __len1 / 2;
 	      std::advance(__first_cut, __len11);
-	      __second_cut = std::lower_bound(__middle, __last, *__first_cut,
-					      __comp);
+	      __second_cut =
+		_GLIBCXX_STD_A::lower_bound(__middle, __last, *__first_cut,
+					    __comp);
 	      __len22 = std::distance(__middle, __second_cut);
 	    }
 	  else
 	    {
 	      __len22 = __len2 / 2;
 	      std::advance(__second_cut, __len22);
-	      __first_cut = std::upper_bound(__first, __middle, *__second_cut,
-					     __comp);
+	      __first_cut =
+		_GLIBCXX_STD_A::upper_bound(__first, __middle, *__second_cut,
+					    __comp);
 	      __len11 = std::distance(__first, __first_cut);
 	    }
 	  _BidirectionalIterator __new_middle =
-	    std::__rotate_adaptive(__first_cut, __middle, __second_cut,
+	    __detail::__rotate_adaptive(__first_cut, __middle, __second_cut,
 				   __len1 - __len11, __len22, __buffer,
 				   __buffer_size);
-	  std::__merge_adaptive(__first, __first_cut, __new_middle, __len11,
+	  __detail::__merge_adaptive(__first, __first_cut, __new_middle, __len11,
 				__len22, __buffer, __buffer_size, __comp);
-	  std::__merge_adaptive(__new_middle, __second_cut, __last,
+	  __detail::__merge_adaptive(__new_middle, __second_cut, __last,
 				__len1 - __len11,
 				__len2 - __len22, __buffer,
 				__buffer_size, __comp);
@@ -3011,23 +3040,25 @@
 	{
 	  __len11 = __len1 / 2;
 	  std::advance(__first_cut, __len11);
-	  __second_cut = std::lower_bound(__middle, __last, *__first_cut);
+	  __second_cut =
+	    _GLIBCXX_STD_A::lower_bound(__middle, __last, *__first_cut);
 	  __len22 = std::distance(__middle, __second_cut);
 	}
       else
 	{
 	  __len22 = __len2 / 2;
 	  std::advance(__second_cut, __len22);
-	  __first_cut = std::upper_bound(__first, __middle, *__second_cut);
+	  __first_cut =
+	    _GLIBCXX_STD_A::upper_bound(__first, __middle, *__second_cut);
 	  __len11 = std::distance(__first, __first_cut);
 	}
-      std::rotate(__first_cut, __middle, __second_cut);
+      _GLIBCXX_STD_A::rotate(__first_cut, __middle, __second_cut);
       _BidirectionalIterator __new_middle = __first_cut;
       std::advance(__new_middle, std::distance(__middle, __second_cut));
-      std::__merge_without_buffer(__first, __first_cut, __new_middle,
+      __detail::__merge_without_buffer(__first, __first_cut, __new_middle,
 				  __len11, __len22);
-      std::__merge_without_buffer(__new_middle, __second_cut, __last,
-				  __len1 - __len11, __len2 - __len22);
+      __detail::__merge_without_buffer(__new_middle, __second_cut, __last,
+				       __len1 - __len11, __len2 - __len22);
     }
 
   /// This is a helper function for the merge routines.
@@ -3056,27 +3087,33 @@
 	{
 	  __len11 = __len1 / 2;
 	  std::advance(__first_cut, __len11);
-	  __second_cut = std::lower_bound(__middle, __last, *__first_cut,
-					  __comp);
+	  __second_cut =
+	    _GLIBCXX_STD_A::lower_bound(__middle, __last, *__first_cut,
+					__comp);
 	  __len22 = std::distance(__middle, __second_cut);
 	}
       else
 	{
 	  __len22 = __len2 / 2;
 	  std::advance(__second_cut, __len22);
-	  __first_cut = std::upper_bound(__first, __middle, *__second_cut,
-					 __comp);
+	  __first_cut =
+	    _GLIBCXX_STD_A::upper_bound(__first, __middle, *__second_cut,
+					__comp);
 	  __len11 = std::distance(__first, __first_cut);
 	}
-      std::rotate(__first_cut, __middle, __second_cut);
+      _GLIBCXX_STD_A::rotate(__first_cut, __middle, __second_cut);
       _BidirectionalIterator __new_middle = __first_cut;
       std::advance(__new_middle, std::distance(__middle, __second_cut));
-      std::__merge_without_buffer(__first, __first_cut, __new_middle,
+      __detail::__merge_without_buffer(__first, __first_cut, __new_middle,
 				  __len11, __len22, __comp);
-      std::__merge_without_buffer(__new_middle, __second_cut, __last,
+      __detail::__merge_without_buffer(__new_middle, __second_cut, __last,
 				  __len1 - __len11, __len2 - __len22, __comp);
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   /**
    *  @brief Merges two sorted ranges in place.
    *  @ingroup sorting_algorithms
@@ -3110,8 +3147,6 @@
       __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
 	    _BidirectionalIterator>)
       __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
-      __glibcxx_requires_sorted(__first, __middle);
-      __glibcxx_requires_sorted(__middle, __last);
 
       if (__first == __middle || __middle == __last)
 	return;
@@ -3122,9 +3157,9 @@
       _Temporary_buffer<_BidirectionalIterator, _ValueType> __buf(__first,
 								  __last);
       if (__buf.begin() == 0)
-	std::__merge_without_buffer(__first, __middle, __last, __len1, __len2);
+	__detail::__merge_without_buffer(__first, __middle, __last, __len1, __len2);
       else
-	std::__merge_adaptive(__first, __middle, __last, __len1, __len2,
+	__detail::__merge_adaptive(__first, __middle, __last, __len1, __len2,
 			      __buf.begin(), _DistanceType(__buf.size()));
     }
 
@@ -3167,8 +3202,6 @@
 	    _BidirectionalIterator>)
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
 	    _ValueType, _ValueType>)
-      __glibcxx_requires_sorted_pred(__first, __middle, __comp);
-      __glibcxx_requires_sorted_pred(__middle, __last, __comp);
 
       if (__first == __middle || __middle == __last)
 	return;
@@ -3179,14 +3212,19 @@
       _Temporary_buffer<_BidirectionalIterator, _ValueType> __buf(__first,
 								  __last);
       if (__buf.begin() == 0)
-	std::__merge_without_buffer(__first, __middle, __last, __len1,
+	__detail::__merge_without_buffer(__first, __middle, __last, __len1,
 				    __len2, __comp);
       else
-	std::__merge_adaptive(__first, __middle, __last, __len1, __len2,
+	__detail::__merge_adaptive(__first, __middle, __last, __len1, __len2,
 			      __buf.begin(), _DistanceType(__buf.size()),
 			      __comp);
     }
 
+_GLIBCXX_END_NAMESPACE_ALGO
+namespace __detail
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   template<typename _RandomAccessIterator1, typename _RandomAccessIterator2,
 	   typename _Distance>
     void
@@ -3199,15 +3237,15 @@
 
       while (__last - __first >= __two_step)
 	{
-	  __result = std::__move_merge(__first, __first + __step_size,
-				       __first + __step_size,
-				       __first + __two_step, __result);
+	  __result = __detail::__move_merge(__first, __first + __step_size,
+					    __first + __step_size,
+					    __first + __two_step, __result);
 	  __first += __two_step;
 	}
 
       __step_size = std::min(_Distance(__last - __first), __step_size);
-      std::__move_merge(__first, __first + __step_size,
-			__first + __step_size, __last, __result);
+      __detail::__move_merge(__first, __first + __step_size,
+			     __first + __step_size, __last, __result);
     }
 
   template<typename _RandomAccessIterator1, typename _RandomAccessIterator2,
@@ -3222,16 +3260,16 @@
 
       while (__last - __first >= __two_step)
 	{
-	  __result = std::__move_merge(__first, __first + __step_size,
-				       __first + __step_size,
-				       __first + __two_step,
-				       __result, __comp);
+	  __result = __detail::__move_merge(__first, __first + __step_size,
+					    __first + __step_size,
+					    __first + __two_step,
+					    __result, __comp);
 	  __first += __two_step;
 	}
       __step_size = std::min(_Distance(__last - __first), __step_size);
 
-      std::__move_merge(__first,__first + __step_size,
-			__first + __step_size, __last, __result, __comp);
+      __detail::__move_merge(__first,__first + __step_size,
+			     __first + __step_size, __last, __result, __comp);
     }
 
   template<typename _RandomAccessIterator, typename _Distance>
@@ -3242,10 +3280,10 @@
     {
       while (__last - __first >= __chunk_size)
 	{
-	  std::__insertion_sort(__first, __first + __chunk_size);
+	  __detail::__insertion_sort(__first, __first + __chunk_size);
 	  __first += __chunk_size;
 	}
-      std::__insertion_sort(__first, __last);
+      __detail::__insertion_sort(__first, __last);
     }
 
   template<typename _RandomAccessIterator, typename _Distance,
@@ -3257,10 +3295,10 @@
     {
       while (__last - __first >= __chunk_size)
 	{
-	  std::__insertion_sort(__first, __first + __chunk_size, __comp);
+	  __detail::__insertion_sort(__first, __first + __chunk_size, __comp);
 	  __first += __chunk_size;
 	}
-      std::__insertion_sort(__first, __last, __comp);
+      __detail::__insertion_sort(__first, __last, __comp);
     }
 
   enum { _S_chunk_size = 7 };
@@ -3278,13 +3316,14 @@
       const _Pointer __buffer_last = __buffer + __len;
 
       _Distance __step_size = _S_chunk_size;
-      std::__chunk_insertion_sort(__first, __last, __step_size);
+      __detail::__chunk_insertion_sort(__first, __last, __step_size);
 
       while (__step_size < __len)
 	{
-	  std::__merge_sort_loop(__first, __last, __buffer, __step_size);
+	  __detail::__merge_sort_loop(__first, __last, __buffer, __step_size);
 	  __step_size *= 2;
-	  std::__merge_sort_loop(__buffer, __buffer_last, __first, __step_size);
+	  __detail::__merge_sort_loop(__buffer, __buffer_last, __first,
+				      __step_size);
 	  __step_size *= 2;
 	}
     }
@@ -3302,15 +3341,15 @@
       const _Pointer __buffer_last = __buffer + __len;
 
       _Distance __step_size = _S_chunk_size;
-      std::__chunk_insertion_sort(__first, __last, __step_size, __comp);
+      __detail::__chunk_insertion_sort(__first, __last, __step_size, __comp);
 
       while (__step_size < __len)
 	{
-	  std::__merge_sort_loop(__first, __last, __buffer,
-				 __step_size, __comp);
+	  __detail::__merge_sort_loop(__first, __last, __buffer,
+				      __step_size, __comp);
 	  __step_size *= 2;
-	  std::__merge_sort_loop(__buffer, __buffer_last, __first,
-				 __step_size, __comp);
+	  __detail::__merge_sort_loop(__buffer, __buffer_last, __first,
+				      __step_size, __comp);
 	  __step_size *= 2;
 	}
     }
@@ -3326,20 +3365,20 @@
       const _RandomAccessIterator __middle = __first + __len;
       if (__len > __buffer_size)
 	{
-	  std::__stable_sort_adaptive(__first, __middle,
-				      __buffer, __buffer_size);
-	  std::__stable_sort_adaptive(__middle, __last,
-				      __buffer, __buffer_size);
+	  __detail::__stable_sort_adaptive(__first, __middle,
+					   __buffer, __buffer_size);
+	  __detail::__stable_sort_adaptive(__middle, __last,
+					   __buffer, __buffer_size);
 	}
       else
 	{
-	  std::__merge_sort_with_buffer(__first, __middle, __buffer);
-	  std::__merge_sort_with_buffer(__middle, __last, __buffer);
+	  __detail::__merge_sort_with_buffer(__first, __middle, __buffer);
+	  __detail::__merge_sort_with_buffer(__middle, __last, __buffer);
 	}
-      std::__merge_adaptive(__first, __middle, __last,
-			    _Distance(__middle - __first),
-			    _Distance(__last - __middle),
-			    __buffer, __buffer_size);
+      __detail::__merge_adaptive(__first, __middle, __last,
+				 _Distance(__middle - __first),
+				 _Distance(__last - __middle),
+				 __buffer, __buffer_size);
     }
 
   template<typename _RandomAccessIterator, typename _Pointer,
@@ -3354,21 +3393,23 @@
       const _RandomAccessIterator __middle = __first + __len;
       if (__len > __buffer_size)
 	{
-	  std::__stable_sort_adaptive(__first, __middle, __buffer,
-				      __buffer_size, __comp);
-	  std::__stable_sort_adaptive(__middle, __last, __buffer,
-				      __buffer_size, __comp);
+	  __detail::__stable_sort_adaptive(__first, __middle, __buffer,
+					   __buffer_size, __comp);
+	  __detail::__stable_sort_adaptive(__middle, __last, __buffer,
+					   __buffer_size, __comp);
 	}
       else
 	{
-	  std::__merge_sort_with_buffer(__first, __middle, __buffer, __comp);
-	  std::__merge_sort_with_buffer(__middle, __last, __buffer, __comp);
+	  __detail::__merge_sort_with_buffer(__first, __middle, __buffer,
+					     __comp);
+	  __detail::__merge_sort_with_buffer(__middle, __last, __buffer,
+					     __comp);
 	}
-      std::__merge_adaptive(__first, __middle, __last,
-			    _Distance(__middle - __first),
-			    _Distance(__last - __middle),
-			    __buffer, __buffer_size,
-			    __comp);
+      __detail::__merge_adaptive(__first, __middle, __last,
+				 _Distance(__middle - __first),
+				 _Distance(__last - __middle),
+				 __buffer, __buffer_size,
+				 __comp);
     }
 
   /// This is a helper function for the stable sorting routines.
@@ -3379,15 +3420,15 @@
     {
       if (__last - __first < 15)
 	{
-	  std::__insertion_sort(__first, __last);
+	  __detail::__insertion_sort(__first, __last);
 	  return;
 	}
       _RandomAccessIterator __middle = __first + (__last - __first) / 2;
-      std::__inplace_stable_sort(__first, __middle);
-      std::__inplace_stable_sort(__middle, __last);
-      std::__merge_without_buffer(__first, __middle, __last,
-				  __middle - __first,
-				  __last - __middle);
+      __detail::__inplace_stable_sort(__first, __middle);
+      __detail::__inplace_stable_sort(__middle, __last);
+      __detail::__merge_without_buffer(__first, __middle, __last,
+				       __middle - __first,
+				       __last - __middle);
     }
 
   /// This is a helper function for the stable sorting routines.
@@ -3398,18 +3439,22 @@
     {
       if (__last - __first < 15)
 	{
-	  std::__insertion_sort(__first, __last, __comp);
+	  __detail::__insertion_sort(__first, __last, __comp);
 	  return;
 	}
       _RandomAccessIterator __middle = __first + (__last - __first) / 2;
-      std::__inplace_stable_sort(__first, __middle, __comp);
-      std::__inplace_stable_sort(__middle, __last, __comp);
-      std::__merge_without_buffer(__first, __middle, __last,
-				  __middle - __first,
-				  __last - __middle,
-				  __comp);
+      __detail::__inplace_stable_sort(__first, __middle, __comp);
+      __detail::__inplace_stable_sort(__middle, __last, __comp);
+      __detail::__merge_without_buffer(__first, __middle, __last,
+				       __middle - __first,
+				       __last - __middle,
+				       __comp);
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   // stable_sort
 
   // Set algorithms: includes, set_union, set_intersection, set_difference,
@@ -3448,8 +3493,6 @@
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
       __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
       __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
-      __glibcxx_requires_sorted_set(__first1, __last1, __first2);
-      __glibcxx_requires_sorted_set(__first2, __last2, __first1);
 
       while (__first1 != __last1 && __first2 != __last2)
 	if (*__first2 < *__first1)
@@ -3501,8 +3544,6 @@
 				  _ValueType1, _ValueType2>)
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
 				  _ValueType2, _ValueType1>)
-      __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
-      __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
 
       while (__first1 != __last1 && __first2 != __last2)
 	if (__comp(*__first2, *__first1))
@@ -3547,7 +3588,6 @@
 				  _BidirectionalIterator>)
       __glibcxx_function_requires(_LessThanComparableConcept<
 	    typename iterator_traits<_BidirectionalIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first == __last)
 	return false;
@@ -3568,12 +3608,12 @@
 	      while (!(*__i < *--__j))
 		{}
 	      std::iter_swap(__i, __j);
-	      std::reverse(__ii, __last);
+	      _GLIBCXX_STD_A::reverse(__ii, __last);
 	      return true;
 	    }
 	  if (__i == __first)
 	    {
-	      std::reverse(__first, __last);
+	      _GLIBCXX_STD_A::reverse(__first, __last);
 	      return false;
 	    }
 	}
@@ -3605,7 +3645,6 @@
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
 	    typename iterator_traits<_BidirectionalIterator>::value_type,
 	    typename iterator_traits<_BidirectionalIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first == __last)
 	return false;
@@ -3626,12 +3665,12 @@
 	      while (!bool(__comp(*__i, *--__j)))
 		{}
 	      std::iter_swap(__i, __j);
-	      std::reverse(__ii, __last);
+	      _GLIBCXX_STD_A::reverse(__ii, __last);
 	      return true;
 	    }
 	  if (__i == __first)
 	    {
-	      std::reverse(__first, __last);
+	      _GLIBCXX_STD_A::reverse(__first, __last);
 	      return false;
 	    }
 	}
@@ -3660,7 +3699,6 @@
 				  _BidirectionalIterator>)
       __glibcxx_function_requires(_LessThanComparableConcept<
 	    typename iterator_traits<_BidirectionalIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first == __last)
 	return false;
@@ -3681,12 +3719,12 @@
 	      while (!(*--__j < *__i))
 		{}
 	      std::iter_swap(__i, __j);
-	      std::reverse(__ii, __last);
+	      _GLIBCXX_STD_A::reverse(__ii, __last);
 	      return true;
 	    }
 	  if (__i == __first)
 	    {
-	      std::reverse(__first, __last);
+	      _GLIBCXX_STD_A::reverse(__first, __last);
 	      return false;
 	    }
 	}
@@ -3718,7 +3756,6 @@
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
 	    typename iterator_traits<_BidirectionalIterator>::value_type,
 	    typename iterator_traits<_BidirectionalIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first == __last)
 	return false;
@@ -3739,12 +3776,12 @@
 	      while (!bool(__comp(*--__j, *__i)))
 		{}
 	      std::iter_swap(__i, __j);
-	      std::reverse(__ii, __last);
+	      _GLIBCXX_STD_A::reverse(__ii, __last);
 	      return true;
 	    }
 	  if (__i == __first)
 	    {
-	      std::reverse(__first, __last);
+	      _GLIBCXX_STD_A::reverse(__first, __last);
 	      return false;
 	    }
 	}
@@ -3779,7 +3816,6 @@
 	    typename iterator_traits<_InputIterator>::value_type>)
       __glibcxx_function_requires(_EqualOpConcept<
 	    typename iterator_traits<_InputIterator>::value_type, _Tp>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       for (; __first != __last; ++__first, ++__result)
 	if (*__first == __old_value)
@@ -3817,7 +3853,6 @@
 	    typename iterator_traits<_InputIterator>::value_type>)
       __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
 	    typename iterator_traits<_InputIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       for (; __first != __last; ++__first, ++__result)
 	if (__pred(*__first))
@@ -3838,7 +3873,7 @@
   template<typename _ForwardIterator>
     inline bool
     is_sorted(_ForwardIterator __first, _ForwardIterator __last)
-    { return std::is_sorted_until(__first, __last) == __last; }
+    { return _GLIBCXX_STD_A::is_sorted_until(__first, __last) == __last; }
 
   /**
    *  @brief  Determines whether the elements of a sequence are sorted
@@ -3853,7 +3888,8 @@
     inline bool
     is_sorted(_ForwardIterator __first, _ForwardIterator __last,
 	      _Compare __comp)
-    { return std::is_sorted_until(__first, __last, __comp) == __last; }
+    { return _GLIBCXX_STD_A::is_sorted_until(__first, __last, __comp) ==
+		 __last; }
 
   /**
    *  @brief  Determines the end of a sorted sequence.
@@ -3871,7 +3907,6 @@
       __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
       __glibcxx_function_requires(_LessThanComparableConcept<
 	    typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first == __last)
 	return __last;
@@ -3902,7 +3937,6 @@
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
 	    typename iterator_traits<_ForwardIterator>::value_type,
 	    typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first == __last)
 	return __last;
@@ -3914,6 +3948,9 @@
       return __next;
     }
 
+_GLIBCXX_END_NAMESPACE_ALGO
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   /**
    *  @brief  Determines min and max at once as an ordered pair.
    *  @ingroup sorting_algorithms
@@ -3948,6 +3985,9 @@
 	                      : pair<const _Tp&, const _Tp&>(__a, __b);
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   /**
    *  @brief  Return a pair of iterators pointing to the minimum and maximum
    *          elements in a range.
@@ -3967,7 +4007,6 @@
       __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
       __glibcxx_function_requires(_LessThanComparableConcept<
 	    typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       _ForwardIterator __next = __first;
       if (__first == __last
@@ -4045,7 +4084,6 @@
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
 	    typename iterator_traits<_ForwardIterator>::value_type,
 	    typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       _ForwardIterator __next = __first;
       if (__first == __last
@@ -4101,33 +4139,36 @@
       return std::make_pair(__min, __max);
     }
 
+_GLIBCXX_END_NAMESPACE_ALGO
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   // N2722 + DR 915.
   template<typename _Tp>
     inline _Tp
     min(initializer_list<_Tp> __l)
-    { return *std::min_element(__l.begin(), __l.end()); }
+    { return *_GLIBCXX_STD_A::min_element(__l.begin(), __l.end()); }
 
   template<typename _Tp, typename _Compare>
     inline _Tp
     min(initializer_list<_Tp> __l, _Compare __comp)
-    { return *std::min_element(__l.begin(), __l.end(), __comp); }
+    { return *_GLIBCXX_STD_A::min_element(__l.begin(), __l.end(), __comp); }
 
   template<typename _Tp>
     inline _Tp
     max(initializer_list<_Tp> __l)
-    { return *std::max_element(__l.begin(), __l.end()); }
+    { return *_GLIBCXX_STD_A::max_element(__l.begin(), __l.end()); }
 
   template<typename _Tp, typename _Compare>
     inline _Tp
     max(initializer_list<_Tp> __l, _Compare __comp)
-    { return *std::max_element(__l.begin(), __l.end(), __comp); }
+    { return *_GLIBCXX_STD_A::max_element(__l.begin(), __l.end(), __comp); }
 
   template<typename _Tp>
     inline pair<_Tp, _Tp>
     minmax(initializer_list<_Tp> __l)
     {
       pair<const _Tp*, const _Tp*> __p =
-	std::minmax_element(__l.begin(), __l.end());
+	_GLIBCXX_STD_A::minmax_element(__l.begin(), __l.end());
       return std::make_pair(*__p.first, *__p.second);
     }
 
@@ -4136,10 +4177,13 @@
     minmax(initializer_list<_Tp> __l, _Compare __comp)
     {
       pair<const _Tp*, const _Tp*> __p =
-	std::minmax_element(__l.begin(), __l.end(), __comp);
+	_GLIBCXX_STD_A::minmax_element(__l.begin(), __l.end(), __comp);
       return std::make_pair(*__p.first, *__p.second);
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   /**
    *  @brief  Checks whether a permutaion of the second sequence is equal
    *          to the first sequence.
@@ -4175,9 +4219,9 @@
 	  if (__scan != _GLIBCXX_STD_A::find(__first1, __scan, *__scan))
 	    continue; // We've seen this one before.
 
-	  auto __matches = std::count(__first2, __last2, *__scan);
+	  auto __matches = _GLIBCXX_STD_A::count(__first2, __last2, *__scan);
 	  if (0 == __matches
-	      || std::count(__scan, __last1, *__scan) != __matches)
+	      || _GLIBCXX_STD_A::count(__scan, __last1, *__scan) != __matches)
 	    return false;
 	}
       return true;
@@ -4223,10 +4267,10 @@
 						std::bind(__pred, _1, *__scan)))
 	    continue; // We've seen this one before.
 	  
-	  auto __matches = std::count_if(__first2, __last2,
+	  auto __matches = _GLIBCXX_STD_A::count_if(__first2, __last2,
 					 std::bind(__pred, _1, *__scan));
 	  if (0 == __matches
-	      || std::count_if(__scan, __last1,
+	      || _GLIBCXX_STD_A::count_if(__scan, __last1,
 			       std::bind(__pred, _1, *__scan)) != __matches)
 	    return false;
 	}
@@ -4255,7 +4299,6 @@
       // concept requirements
       __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
 	    _RandomAccessIterator>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first == __last)
 	return;
@@ -4269,16 +4312,12 @@
       __distr_type __d;
 
       for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
-	std::iter_swap(__i, __first + __d(__g, __p_type(0, __i - __first)));
+	_GLIBCXX_STD_A::iter_swap(__i, __first + __d(__g, __p_type(0, __i - __first)));
     }
 #endif
 
 #endif // __GXX_EXPERIMENTAL_CXX0X__
 
-_GLIBCXX_END_NAMESPACE_VERSION
-
-_GLIBCXX_BEGIN_NAMESPACE_ALGO
-
   /**
    *  @brief Apply a function to every element of a sequence.
    *  @ingroup non_mutating_algorithms
@@ -4297,7 +4336,6 @@
     {
       // concept requirements
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
-      __glibcxx_requires_valid_range(__first, __last);
       for (; __first != __last; ++__first)
 	__f(*__first);
       return _GLIBCXX_MOVE(__f);
@@ -4321,8 +4359,7 @@
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
       __glibcxx_function_requires(_EqualOpConcept<
 		typename iterator_traits<_InputIterator>::value_type, _Tp>)
-      __glibcxx_requires_valid_range(__first, __last);
-      return std::__find(__first, __last, __val,
+      return __detail::__find(__first, __last, __val,
 		         std::__iterator_category(__first));
     }
 
@@ -4345,8 +4382,7 @@
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
       __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
 	      typename iterator_traits<_InputIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
-      return std::__find_if(__first, __last, __pred,
+      return __detail::__find_if(__first, __last, __pred,
 			    std::__iterator_category(__first));
     }
 
@@ -4376,8 +4412,6 @@
       __glibcxx_function_requires(_EqualOpConcept<
 	    typename iterator_traits<_InputIterator>::value_type,
 	    typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first1, __last1);
-      __glibcxx_requires_valid_range(__first2, __last2);
 
       for (; __first1 != __last1; ++__first1)
 	for (_ForwardIterator __iter = __first2; __iter != __last2; ++__iter)
@@ -4417,8 +4451,6 @@
       __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
 	    typename iterator_traits<_InputIterator>::value_type,
 	    typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first1, __last1);
-      __glibcxx_requires_valid_range(__first2, __last2);
 
       for (; __first1 != __last1; ++__first1)
 	for (_ForwardIterator __iter = __first2; __iter != __last2; ++__iter)
@@ -4444,7 +4476,6 @@
       __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
       __glibcxx_function_requires(_EqualityComparableConcept<
 	    typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
       if (__first == __last)
 	return __last;
       _ForwardIterator __next = __first;
@@ -4478,7 +4509,6 @@
       __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
 	    typename iterator_traits<_ForwardIterator>::value_type,
 	    typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
       if (__first == __last)
 	return __last;
       _ForwardIterator __next = __first;
@@ -4508,7 +4538,6 @@
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
       __glibcxx_function_requires(_EqualOpConcept<
 	typename iterator_traits<_InputIterator>::value_type, _Tp>)
-      __glibcxx_requires_valid_range(__first, __last);
       typename iterator_traits<_InputIterator>::difference_type __n = 0;
       for (; __first != __last; ++__first)
 	if (*__first == __value)
@@ -4533,7 +4562,6 @@
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
       __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
 	    typename iterator_traits<_InputIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
       typename iterator_traits<_InputIterator>::difference_type __n = 0;
       for (; __first != __last; ++__first)
 	if (__pred(*__first))
@@ -4576,8 +4604,6 @@
       __glibcxx_function_requires(_EqualOpConcept<
 	    typename iterator_traits<_ForwardIterator1>::value_type,
 	    typename iterator_traits<_ForwardIterator2>::value_type>)
-      __glibcxx_requires_valid_range(__first1, __last1);
-      __glibcxx_requires_valid_range(__first2, __last2);
 
       // Test for empty ranges
       if (__first1 == __last1 || __first2 == __last2)
@@ -4649,8 +4675,6 @@
       __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
 	    typename iterator_traits<_ForwardIterator1>::value_type,
 	    typename iterator_traits<_ForwardIterator2>::value_type>)
-      __glibcxx_requires_valid_range(__first1, __last1);
-      __glibcxx_requires_valid_range(__first2, __last2);
 
       // Test for empty ranges
       if (__first1 == __last1 || __first2 == __last2)
@@ -4719,13 +4743,12 @@
       __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
       __glibcxx_function_requires(_EqualOpConcept<
 	typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__count <= 0)
 	return __first;
       if (__count == 1)
 	return _GLIBCXX_STD_A::find(__first, __last, __val);
-      return std::__search_n(__first, __last, __count, __val,
+      return __detail::__search_n(__first, __last, __count, __val,
 			     std::__iterator_category(__first));
     }
 
@@ -4757,7 +4780,6 @@
       __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
       __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
 	    typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__count <= 0)
 	return __first;
@@ -4767,7 +4789,7 @@
 	    ++__first;
 	  return __first;
 	}
-      return std::__search_n(__first, __last, __count, __val, __binary_pred,
+      return __detail::__search_n(__first, __last, __count, __val, __binary_pred,
 			     std::__iterator_category(__first));
     }
 
@@ -4799,7 +4821,6 @@
       __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
             // "the type returned by a _UnaryOperation"
             __typeof__(__unary_op(*__first))>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       for (; __first != __last; ++__first, ++__result)
 	*__result = __unary_op(*__first);
@@ -4837,7 +4858,6 @@
       __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
             // "the type returned by a _BinaryOperation"
             __typeof__(__binary_op(*__first1,*__first2))>)
-      __glibcxx_requires_valid_range(__first1, __last1);
 
       for (; __first1 != __last1; ++__first1, ++__first2, ++__result)
 	*__result = __binary_op(*__first1, *__first2);
@@ -4869,7 +4889,6 @@
 	    typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
       __glibcxx_function_requires(_ConvertibleConcept<_Tp,
 	    typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       for (; __first != __last; ++__first)
 	if (*__first == __old_value)
@@ -4901,7 +4920,6 @@
 	    typename iterator_traits<_ForwardIterator>::value_type>)
       __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
 	    typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       for (; __first != __last; ++__first)
 	if (__pred(*__first))
@@ -4930,7 +4948,6 @@
       __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
       __glibcxx_function_requires(_GeneratorConcept<_Generator,
 	    typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       for (; __first != __last; ++__first)
 	*__first = __gen();
@@ -5000,11 +5017,10 @@
 	    typename iterator_traits<_InputIterator>::value_type>)
       __glibcxx_function_requires(_EqualityComparableConcept<
 	    typename iterator_traits<_InputIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first == __last)
 	return __result;
-      return std::__unique_copy(__first, __last, __result,
+      return __detail::__unique_copy(__first, __last, __result,
 				std::__iterator_category(__first),
 				std::__iterator_category(__result));
     }
@@ -5039,11 +5055,10 @@
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
       __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
 	    typename iterator_traits<_InputIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first == __last)
 	return __result;
-      return std::__unique_copy(__first, __last, __result, __binary_pred,
+      return __detail::__unique_copy(__first, __last, __result, __binary_pred,
 				std::__iterator_category(__first),
 				std::__iterator_category(__result));
     }
@@ -5067,7 +5082,6 @@
       // concept requirements
       __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
 	    _RandomAccessIterator>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first != __last)
 	for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
@@ -5100,7 +5114,6 @@
       // concept requirements
       __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
 	    _RandomAccessIterator>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first == __last)
 	return;
@@ -5134,9 +5147,8 @@
 				  _ForwardIterator>)
       __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate,
 	    typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
-      return std::__partition(__first, __last, __pred,
+      return __detail::__partition(__first, __last, __pred,
 			      std::__iterator_category(__first));
     }
 
@@ -5171,11 +5183,9 @@
       __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
 	    _RandomAccessIterator>)
       __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
-      __glibcxx_requires_valid_range(__first, __middle);
-      __glibcxx_requires_valid_range(__middle, __last);
 
-      std::__heap_select(__first, __middle, __last);
-      std::sort_heap(__first, __middle);
+      __detail::__heap_select(__first, __middle, __last);
+      _GLIBCXX_STD_A::sort_heap(__first, __middle);
     }
 
   /**
@@ -5212,11 +5222,9 @@
 	    _RandomAccessIterator>)
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
 				  _ValueType, _ValueType>)
-      __glibcxx_requires_valid_range(__first, __middle);
-      __glibcxx_requires_valid_range(__middle, __last);
 
-      std::__heap_select(__first, __middle, __last, __comp);
-      std::sort_heap(__first, __middle, __comp);
+      __detail::__heap_select(__first, __middle, __last, __comp);
+      _GLIBCXX_STD_A::sort_heap(__first, __middle, __comp);
     }
 
   /**
@@ -5247,14 +5255,12 @@
       __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
 				  _RandomAccessIterator>)
       __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
-      __glibcxx_requires_valid_range(__first, __nth);
-      __glibcxx_requires_valid_range(__nth, __last);
 
       if (__first == __last || __nth == __last)
 	return;
 
-      std::__introselect(__first, __nth, __last,
-			 std::__lg(__last - __first) * 2);
+      __detail::__introselect(__first, __nth, __last,
+			 __detail::__lg(__last - __first) * 2);
     }
 
   /**
@@ -5287,14 +5293,12 @@
 				  _RandomAccessIterator>)
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
 				  _ValueType, _ValueType>)
-      __glibcxx_requires_valid_range(__first, __nth);
-      __glibcxx_requires_valid_range(__nth, __last);
 
       if (__first == __last || __nth == __last)
 	return;
 
-      std::__introselect(__first, __nth, __last,
-			 std::__lg(__last - __first) * 2, __comp);
+      __detail::__introselect(__first, __nth, __last,
+			 __detail::__lg(__last - __first) * 2, __comp);
     }
 
 
@@ -5323,13 +5327,12 @@
       __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
 	    _RandomAccessIterator>)
       __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first != __last)
 	{
-	  std::__introsort_loop(__first, __last,
-				std::__lg(__last - __first) * 2);
-	  std::__final_insertion_sort(__first, __last);
+	  __detail::__introsort_loop(__first, __last,
+				__detail::__lg(__last - __first) * 2);
+	  __detail::__final_insertion_sort(__first, __last);
 	}
     }
 
@@ -5361,13 +5364,12 @@
 	    _RandomAccessIterator>)
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, _ValueType,
 				  _ValueType>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first != __last)
 	{
-	  std::__introsort_loop(__first, __last,
-				std::__lg(__last - __first) * 2, __comp);
-	  std::__final_insertion_sort(__first, __last, __comp);
+	  __detail::__introsort_loop(__first, __last,
+				__detail::__lg(__last - __first) * 2, __comp);
+	  __detail::__final_insertion_sort(__first, __last, __comp);
 	}
     }
 
@@ -5409,8 +5411,6 @@
       __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
 				  _ValueType2>)
       __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)	
-      __glibcxx_requires_sorted_set(__first1, __last1, __first2);
-      __glibcxx_requires_sorted_set(__first2, __last2, __first1);
 
       while (__first1 != __last1 && __first2 != __last2)
 	{
@@ -5426,8 +5426,9 @@
 	    }
 	  ++__result;
 	}
-      return std::copy(__first2, __last2, std::copy(__first1, __last1,
-						    __result));
+      return _GLIBCXX_STD_A::copy(__first2, __last2,
+				  _GLIBCXX_STD_A::copy(__first1, __last1,
+						       __result));
     }
 
   /**
@@ -5473,8 +5474,6 @@
 				  _ValueType2>)
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
 				  _ValueType2, _ValueType1>)
-      __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
-      __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
 
       while (__first1 != __last1 && __first2 != __last2)
 	{
@@ -5490,8 +5489,9 @@
 	    }
 	  ++__result;
 	}
-      return std::copy(__first2, __last2, std::copy(__first1, __last1,
-						    __result));
+      return _GLIBCXX_STD_A::copy(__first2, __last2,
+				  _GLIBCXX_STD_A::copy(__first1, __last1,
+						       __result));
     }
 
 
@@ -5525,14 +5525,13 @@
       __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
 	    _RandomAccessIterator>)
       __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       _Temporary_buffer<_RandomAccessIterator, _ValueType> __buf(__first,
 								 __last);
       if (__buf.begin() == 0)
-	std::__inplace_stable_sort(__first, __last);
+	__detail::__inplace_stable_sort(__first, __last);
       else
-	std::__stable_sort_adaptive(__first, __last, __buf.begin(),
+	__detail::__stable_sort_adaptive(__first, __last, __buf.begin(),
 				    _DistanceType(__buf.size()));
     }
 
@@ -5570,14 +5569,13 @@
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
 				  _ValueType,
 				  _ValueType>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       _Temporary_buffer<_RandomAccessIterator, _ValueType> __buf(__first,
 								 __last);
       if (__buf.begin() == 0)
-	std::__inplace_stable_sort(__first, __last, __comp);
+	__detail::__inplace_stable_sort(__first, __last, __comp);
       else
-	std::__stable_sort_adaptive(__first, __last, __buf.begin(),
+	__detail::__stable_sort_adaptive(__first, __last, __buf.begin(),
 				    _DistanceType(__buf.size()), __comp);
     }
 
@@ -5621,8 +5619,6 @@
 				  _ValueType2>)
       __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
       __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
-      __glibcxx_requires_sorted_set(__first1, __last1, __first2);
-      __glibcxx_requires_sorted_set(__first2, __last2, __first1);
 
       while (__first1 != __last1 && __first2 != __last2)
 	{
@@ -5644,8 +5640,9 @@
 	    }
 	  ++__result;
 	}
-      return std::copy(__first2, __last2, std::copy(__first1, __last1,
-						    __result));
+      return _GLIBCXX_STD_A::copy(__first2, __last2,
+				  _GLIBCXX_STD_A::copy(__first1, __last1,
+						       __result));
     }
 
   /**
@@ -5690,8 +5687,6 @@
 				  _ValueType1, _ValueType2>)
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
 				  _ValueType2, _ValueType1>)
-      __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
-      __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
 
       while (__first1 != __last1 && __first2 != __last2)
 	{
@@ -5713,8 +5708,9 @@
 	    }
 	  ++__result;
 	}
-      return std::copy(__first2, __last2, std::copy(__first1, __last1,
-						    __result));
+      return _GLIBCXX_STD_A::copy(__first2, __last2,
+				  _GLIBCXX_STD_A::copy(__first1, __last1,
+						       __result));
     }
 
   /**
@@ -5753,8 +5749,6 @@
 				  _ValueType1>)
       __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
       __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
-      __glibcxx_requires_sorted_set(__first1, __last1, __first2);
-      __glibcxx_requires_sorted_set(__first2, __last2, __first1);
 
       while (__first1 != __last1 && __first2 != __last2)
 	if (*__first1 < *__first2)
@@ -5812,8 +5806,6 @@
 				  _ValueType1, _ValueType2>)
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
 				  _ValueType2, _ValueType1>)
-      __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
-      __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
 
       while (__first1 != __last1 && __first2 != __last2)
 	if (__comp(*__first1, *__first2))
@@ -5868,8 +5860,6 @@
 				  _ValueType1>)
       __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
       __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)	
-      __glibcxx_requires_sorted_set(__first1, __last1, __first2);
-      __glibcxx_requires_sorted_set(__first2, __last2, __first1);
 
       while (__first1 != __last1 && __first2 != __last2)
 	if (*__first1 < *__first2)
@@ -5885,7 +5875,7 @@
 	    ++__first1;
 	    ++__first2;
 	  }
-      return std::copy(__first1, __last1, __result);
+      return _GLIBCXX_STD_A::copy(__first1, __last1, __result);
     }
 
   /**
@@ -5931,8 +5921,6 @@
 				  _ValueType1, _ValueType2>)
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
 				  _ValueType2, _ValueType1>)
-      __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
-      __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
 
       while (__first1 != __last1 && __first2 != __last2)
 	if (__comp(*__first1, *__first2))
@@ -5948,7 +5936,7 @@
 	    ++__first1;
 	    ++__first2;
 	  }
-      return std::copy(__first1, __last1, __result);
+      return _GLIBCXX_STD_A::copy(__first1, __last1, __result);
     }
 
   /**
@@ -5989,8 +5977,6 @@
 				  _ValueType2>)
       __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
       __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)	
-      __glibcxx_requires_sorted_set(__first1, __last1, __first2);
-      __glibcxx_requires_sorted_set(__first2, __last2, __first1);
 
       while (__first1 != __last1 && __first2 != __last2)
 	if (*__first1 < *__first2)
@@ -6010,8 +5996,9 @@
 	    ++__first1;
 	    ++__first2;
 	  }
-      return std::copy(__first2, __last2, std::copy(__first1,
-						    __last1, __result));
+      return _GLIBCXX_STD_A::copy(__first2, __last2,
+				  _GLIBCXX_STD_A::copy(__first1, __last1,
+						       __result));
     }
 
   /**
@@ -6058,8 +6045,6 @@
 				  _ValueType1, _ValueType2>)
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
 				  _ValueType2, _ValueType1>)
-      __glibcxx_requires_sorted_set_pred(__first1, __last1, __first2, __comp);
-      __glibcxx_requires_sorted_set_pred(__first2, __last2, __first1, __comp);
 
       while (__first1 != __last1 && __first2 != __last2)
 	if (__comp(*__first1, *__first2))
@@ -6079,8 +6064,8 @@
 	    ++__first1;
 	    ++__first2;
 	  }
-      return std::copy(__first2, __last2, 
-		       std::copy(__first1, __last1, __result));
+      return _GLIBCXX_STD_A::copy(__first2, __last2, 
+		       _GLIBCXX_STD_A::copy(__first1, __last1, __result));
     }
 
 
@@ -6099,7 +6084,6 @@
       __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
       __glibcxx_function_requires(_LessThanComparableConcept<
 	    typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first == __last)
 	return __first;
@@ -6129,7 +6113,6 @@
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
 	    typename iterator_traits<_ForwardIterator>::value_type,
 	    typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first == __last)
 	return __first;
@@ -6155,7 +6138,6 @@
       __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
       __glibcxx_function_requires(_LessThanComparableConcept<
 	    typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first == __last)
 	return __first;
@@ -6185,7 +6167,6 @@
       __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
 	    typename iterator_traits<_ForwardIterator>::value_type,
 	    typename iterator_traits<_ForwardIterator>::value_type>)
-      __glibcxx_requires_valid_range(__first, __last);
 
       if (__first == __last) return __first;
       _ForwardIterator __result = __first;
Index: include/bits/c++config
===================================================================
--- include/bits/c++config	(revision 173802)
+++ include/bits/c++config	(working copy)
@@ -245,9 +245,6 @@
 }
 
 // Check for invalid usage and unsupported mixed-mode use.
-# if defined(_GLIBCXX_DEBUG) && defined(_GLIBCXX_PARALLEL)
-#  error illegal use of multiple inlined namespaces
-# endif
 # if defined(_GLIBCXX_PROFILE) && defined(_GLIBCXX_DEBUG)
 #  error illegal use of multiple inlined namespaces
 # endif
@@ -282,18 +279,33 @@
 # define _GLIBCXX_EXTERN_TEMPLATE -1
 #endif
 
-#ifdef _GLIBCXX_PARALLEL
+#if defined(_GLIBCXX_DEBUG) || defined(_GLIBCXX_PARALLEL)
 # define _GLIBCXX_STD_A __cxx1998
 # define _GLIBCXX_BEGIN_NAMESPACE_ALGO \
 	 namespace _GLIBCXX_STD_A { _GLIBCXX_BEGIN_NAMESPACE_VERSION
 # define _GLIBCXX_END_NAMESPACE_ALGO \
 	 } _GLIBCXX_END_NAMESPACE_VERSION
+# if defined(_GLIBCXX_PARALLEL)
+#  if defined(_GLIBCXX_DEBUG)
+#   define _GLIBCXX_PARALLEL_A __parallel_algos
+#  else
+#   define _GLIBCXX_PARALLEL_A __parallel
+#  endif
+#  define _GLIBCXX_BEGIN_NAMESPACE_PARALLEL_ALGO \
+	namespace _GLIBCXX_PARALLEL_A { _GLIBCXX_BEGIN_NAMESPACE_VERSION
+#  define _GLIBCXX_END_NAMESPACE_PARALLEL_ALGO \
+	   } _GLIBCXX_END_NAMESPACE_VERSION
+# endif
 #endif
 
 #ifndef _GLIBCXX_STD_A
 # define _GLIBCXX_STD_A std
 #endif
 
+#ifndef _GLIBCXX_PARALLEL_A
+# define _GLIBCXX_PARALLEL_A _GLIBCXX_STD_A
+#endif
+
 #ifndef _GLIBCXX_STD_C
 # define _GLIBCXX_STD_C std
 #endif
Index: include/bits/vector.tcc
===================================================================
--- include/bits/vector.tcc	(revision 173802)
+++ include/bits/vector.tcc	(working copy)
@@ -175,12 +175,12 @@
 	    }
 	  else if (size() >= __xlen)
 	    {
-	      std::_Destroy(std::copy(__x.begin(), __x.end(), begin()),
+	      std::_Destroy(_GLIBCXX_STD_A::copy(__x.begin(), __x.end(), begin()),
 			    end(), _M_get_Tp_allocator());
 	    }
 	  else
 	    {
-	      std::copy(__x._M_impl._M_start, __x._M_impl._M_start + size(),
+	      _GLIBCXX_STD_A::copy(__x._M_impl._M_start, __x._M_impl._M_start + size(),
 			this->_M_impl._M_start);
 	      std::__uninitialized_copy_a(__x._M_impl._M_start + size(),
 					  __x._M_impl._M_finish,
@@ -204,7 +204,7 @@
 	}
       else if (__n > size())
 	{
-	  std::fill(begin(), end(), __val);
+	  _GLIBCXX_STD_A::fill(begin(), end(), __val);
 	  std::__uninitialized_fill_n_a(this->_M_impl._M_finish,
 					__n - size(), __val,
 					_M_get_Tp_allocator());
@@ -253,12 +253,12 @@
 	    this->_M_impl._M_end_of_storage = this->_M_impl._M_finish;
 	  }
 	else if (size() >= __len)
-	  _M_erase_at_end(std::copy(__first, __last, this->_M_impl._M_start));
+	  _M_erase_at_end(_GLIBCXX_STD_A::copy(__first, __last, this->_M_impl._M_start));
 	else
 	  {
 	    _ForwardIterator __mid = __first;
 	    std::advance(__mid, size());
-	    std::copy(__first, __mid, this->_M_impl._M_start);
+	    _GLIBCXX_STD_A::copy(__first, __mid, this->_M_impl._M_start);
 	    this->_M_impl._M_finish =
 	      std::__uninitialized_copy_a(__mid, __last,
 					  this->_M_impl._M_finish,
@@ -391,8 +391,9 @@
 		  this->_M_impl._M_finish += __n;
 		  _GLIBCXX_MOVE_BACKWARD3(__position.base(),
 					  __old_finish - __n, __old_finish);
-		  std::fill(__position.base(), __position.base() + __n,
-			    __x_copy);
+		  _GLIBCXX_STD_A::fill(__position.base(),
+				       __position.base() + __n,
+				       __x_copy);
 		}
 	      else
 		{
@@ -405,7 +406,7 @@
 					      this->_M_impl._M_finish,
 					      _M_get_Tp_allocator());
 		  this->_M_impl._M_finish += __elems_after;
-		  std::fill(__position.base(), __old_finish, __x_copy);
+		  _GLIBCXX_STD_A::fill(__position.base(), __old_finish, __x_copy);
 		}
 	    }
 	  else
@@ -551,7 +552,7 @@
 		    this->_M_impl._M_finish += __n;
 		    _GLIBCXX_MOVE_BACKWARD3(__position.base(),
 					    __old_finish - __n, __old_finish);
-		    std::copy(__first, __last, __position);
+		    _GLIBCXX_STD_A::copy(__first, __last, __position);
 		  }
 		else
 		  {
@@ -566,7 +567,7 @@
 						this->_M_impl._M_finish,
 						_M_get_Tp_allocator());
 		    this->_M_impl._M_finish += __elems_after;
-		    std::copy(__first, __mid, __position);
+		    _GLIBCXX_STD_A::copy(__first, __mid, __position);
 		  }
 	      }
 	    else
@@ -642,9 +643,10 @@
 	return;
       if (capacity() - size() >= __n)
 	{
-	  std::copy_backward(__position, end(),
+	  _GLIBCXX_STD_A::copy_backward(__position, end(),
 			     this->_M_impl._M_finish + difference_type(__n));
-	  std::fill(__position, __position + difference_type(__n), __x);
+	  _GLIBCXX_STD_A::fill(__position,
+			       __position + difference_type(__n), __x);
 	  this->_M_impl._M_finish += difference_type(__n);
 	}
       else
@@ -654,8 +656,8 @@
 	  _Bit_type * __q = this->_M_allocate(__len);
 	  iterator __i = _M_copy_aligned(begin(), __position,
 					 iterator(__q, 0));
-	  std::fill(__i, __i + difference_type(__n), __x);
-	  this->_M_impl._M_finish = std::copy(__position, end(),
+	  _GLIBCXX_STD_A::fill(__i, __i + difference_type(__n), __x);
+	  this->_M_impl._M_finish = _GLIBCXX_STD_A::copy(__position, end(),
 					      __i + difference_type(__n));
 	  this->_M_deallocate();
 	  this->_M_impl._M_end_of_storage = (__q + ((__len
@@ -677,10 +679,10 @@
 	    size_type __n = std::distance(__first, __last);
 	    if (capacity() - size() >= __n)
 	      {
-		std::copy_backward(__position, end(),
+		_GLIBCXX_STD_A::copy_backward(__position, end(),
 				   this->_M_impl._M_finish
 				   + difference_type(__n));
-		std::copy(__first, __last, __position);
+		_GLIBCXX_STD_A::copy(__first, __last, __position);
 		this->_M_impl._M_finish += difference_type(__n);
 	      }
 	    else
@@ -690,8 +692,8 @@
 		_Bit_type * __q = this->_M_allocate(__len);
 		iterator __i = _M_copy_aligned(begin(), __position,
 					       iterator(__q, 0));
-		__i = std::copy(__first, __last, __i);
-		this->_M_impl._M_finish = std::copy(__position, end(), __i);
+		__i = _GLIBCXX_STD_A::copy(__first, __last, __i);
+		this->_M_impl._M_finish = _GLIBCXX_STD_A::copy(__position, end(), __i);
 		this->_M_deallocate();
 		this->_M_impl._M_end_of_storage = (__q
 						   + ((__len
@@ -709,7 +711,7 @@
     {
       if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage)
 	{
-	  std::copy_backward(__position, this->_M_impl._M_finish, 
+	  _GLIBCXX_STD_A::copy_backward(__position, this->_M_impl._M_finish, 
 			     this->_M_impl._M_finish + 1);
 	  *__position = __x;
 	  ++this->_M_impl._M_finish;
@@ -722,7 +724,8 @@
 	  iterator __i = _M_copy_aligned(begin(), __position,
 					 iterator(__q, 0));
 	  *__i++ = __x;
-	  this->_M_impl._M_finish = std::copy(__position, end(), __i);
+	  this->_M_impl._M_finish = _GLIBCXX_STD_A::copy(__position, end(),
+			 				 __i);
 	  this->_M_deallocate();
 	  this->_M_impl._M_end_of_storage = (__q + ((__len
 						     + int(_S_word_bit) - 1)
Index: include/bits/deque.tcc
===================================================================
--- include/bits/deque.tcc	(revision 173802)
+++ include/bits/deque.tcc	(working copy)
@@ -98,12 +98,12 @@
       if (&__x != this)
 	{
 	  if (__len >= __x.size())
-	    _M_erase_at_end(std::copy(__x.begin(), __x.end(),
+	    _M_erase_at_end(_GLIBCXX_STD_A::copy(__x.begin(), __x.end(),
 				      this->_M_impl._M_start));
 	  else
 	    {
 	      const_iterator __mid = __x.begin() + difference_type(__len);
-	      std::copy(__x.begin(), __mid, this->_M_impl._M_start);
+	      _GLIBCXX_STD_A::copy(__x.begin(), __mid, this->_M_impl._M_start);
 	      insert(this->_M_impl._M_finish, __mid, __x.end());
 	    }
 	}
@@ -510,7 +510,7 @@
       _M_range_insert_aux(iterator __pos,
                           _InputIterator __first, _InputIterator __last,
                           std::input_iterator_tag)
-      { std::copy(__first, __last, std::inserter(*this, __pos)); }
+      { _GLIBCXX_STD_A::copy(__first, __last, std::inserter(*this, __pos)); }
 
   template <typename _Tp, typename _Alloc>
     template <typename _ForwardIterator>
@@ -624,7 +624,8 @@
 					      _M_get_Tp_allocator());
 		  this->_M_impl._M_start = __new_start;
 		  _GLIBCXX_MOVE3(__start_n, __pos, __old_start);
-		  std::fill(__pos - difference_type(__n), __pos, __x_copy);
+		  _GLIBCXX_STD_A::fill(__pos - difference_type(__n),
+				       __pos, __x_copy);
 		}
 	      else
 		{
@@ -634,7 +635,7 @@
 						 __x_copy,
 						 _M_get_Tp_allocator());
 		  this->_M_impl._M_start = __new_start;
-		  std::fill(__old_start, __pos, __x_copy);
+		  _GLIBCXX_STD_A::fill(__old_start, __pos, __x_copy);
 		}
 	    }
 	  __catch(...)
@@ -663,7 +664,7 @@
 					      _M_get_Tp_allocator());
 		  this->_M_impl._M_finish = __new_finish;
 		  _GLIBCXX_MOVE_BACKWARD3(__pos, __finish_n, __old_finish);
-		  std::fill(__pos, __pos + difference_type(__n), __x_copy);
+		  _GLIBCXX_STD_A::fill(__pos, __pos + difference_type(__n), __x_copy);
 		}
 	      else
 		{
@@ -673,7 +674,7 @@
 						 this->_M_impl._M_finish,
 						 _M_get_Tp_allocator());
 		  this->_M_impl._M_finish = __new_finish;
-		  std::fill(__pos, __old_finish, __x_copy);
+		  _GLIBCXX_STD_A::fill(__pos, __old_finish, __x_copy);
 		}
 	    }
 	  __catch(...)
@@ -711,7 +712,8 @@
 						_M_get_Tp_allocator());
 		    this->_M_impl._M_start = __new_start;
 		    _GLIBCXX_MOVE3(__start_n, __pos, __old_start);
-		    std::copy(__first, __last, __pos - difference_type(__n));
+		    _GLIBCXX_STD_A::copy(__first, __last,
+					 __pos - difference_type(__n));
 		  }
 		else
 		  {
@@ -722,7 +724,7 @@
 						   __new_start,
 						   _M_get_Tp_allocator());
 		    this->_M_impl._M_start = __new_start;
-		    std::copy(__mid, __last, __old_start);
+		    _GLIBCXX_STD_A::copy(__mid, __last, __old_start);
 		  }
 	      }
 	    __catch(...)
@@ -751,7 +753,7 @@
 					      _M_get_Tp_allocator());
 		  this->_M_impl._M_finish = __new_finish;
 		  _GLIBCXX_MOVE_BACKWARD3(__pos, __finish_n, __old_finish);
-		  std::copy(__first, __last, __pos);
+		  _GLIBCXX_STD_A::copy(__first, __last, __pos);
 		}
               else
 		{
@@ -762,7 +764,7 @@
 						 this->_M_impl._M_finish,
 						 _M_get_Tp_allocator());
 		  this->_M_impl._M_finish = __new_finish;
-		  std::copy(__first, __mid, __pos);
+		  _GLIBCXX_STD_A::copy(__first, __mid, __pos);
 		}
             }
           __catch(...)
@@ -862,11 +864,11 @@
 					 - __new_num_nodes) / 2
 	                 + (__add_at_front ? __nodes_to_add : 0);
 	  if (__new_nstart < this->_M_impl._M_start._M_node)
-	    std::copy(this->_M_impl._M_start._M_node,
+	    _GLIBCXX_STD_A::copy(this->_M_impl._M_start._M_node,
 		      this->_M_impl._M_finish._M_node + 1,
 		      __new_nstart);
 	  else
-	    std::copy_backward(this->_M_impl._M_start._M_node,
+	    _GLIBCXX_STD_A::copy_backward(this->_M_impl._M_start._M_node,
 			       this->_M_impl._M_finish._M_node + 1,
 			       __new_nstart + __old_num_nodes);
 	}
@@ -879,7 +881,7 @@
 	  _Map_pointer __new_map = this->_M_allocate_map(__new_map_size);
 	  __new_nstart = __new_map + (__new_map_size - __new_num_nodes) / 2
 	                 + (__add_at_front ? __nodes_to_add : 0);
-	  std::copy(this->_M_impl._M_start._M_node,
+	  _GLIBCXX_STD_A::copy(this->_M_impl._M_start._M_node,
 		    this->_M_impl._M_finish._M_node + 1,
 		    __new_nstart);
 	  _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
@@ -892,35 +894,42 @@
       this->_M_impl._M_finish._M_set_node(__new_nstart + __old_num_nodes - 1);
     }
 
+_GLIBCXX_END_NAMESPACE_CONTAINER
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
+
   // Overload for deque::iterators, exploiting the "segmented-iterator
   // optimization".
   template<typename _Tp>
     void
-    fill(const _Deque_iterator<_Tp, _Tp&, _Tp*>& __first,
-	 const _Deque_iterator<_Tp, _Tp&, _Tp*>& __last, const _Tp& __value)
+    fill(const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>& __first,
+	 const _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>& __last,
+	 const _Tp& __value)
     {
-      typedef typename _Deque_iterator<_Tp, _Tp&, _Tp*>::_Self _Self;
+      typedef typename _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>::_Self
+	_Self;
 
       for (typename _Self::_Map_pointer __node = __first._M_node + 1;
            __node < __last._M_node; ++__node)
-	std::fill(*__node, *__node + _Self::_S_buffer_size(), __value);
+	_GLIBCXX_STD_A::fill(*__node, *__node + _Self::_S_buffer_size(),
+			     __value);
 
       if (__first._M_node != __last._M_node)
 	{
-	  std::fill(__first._M_cur, __first._M_last, __value);
-	  std::fill(__last._M_first, __last._M_cur, __value);
+	  _GLIBCXX_STD_A::fill(__first._M_cur, __first._M_last, __value);
+	  _GLIBCXX_STD_A::fill(__last._M_first, __last._M_cur, __value);
 	}
       else
-	std::fill(__first._M_cur, __last._M_cur, __value);
+	_GLIBCXX_STD_A::fill(__first._M_cur, __last._M_cur, __value);
     }
 
   template<typename _Tp>
-    _Deque_iterator<_Tp, _Tp&, _Tp*>
-    copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*> __first,
-	 _Deque_iterator<_Tp, const _Tp&, const _Tp*> __last,
-	 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
+    _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>
+    copy(_GLIBCXX_STD_C::_Deque_iterator<_Tp, const _Tp&, const _Tp*> __first,
+	 _GLIBCXX_STD_C::_Deque_iterator<_Tp, const _Tp&, const _Tp*> __last,
+	 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> __result)
     {
-      typedef typename _Deque_iterator<_Tp, _Tp&, _Tp*>::_Self _Self;
+      typedef typename _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>::_Self
+	_Self;
       typedef typename _Self::difference_type difference_type;
 
       difference_type __len = __last - __first;
@@ -929,7 +938,8 @@
 	  const difference_type __clen
 	    = std::min(__len, std::min(__first._M_last - __first._M_cur,
 				       __result._M_last - __result._M_cur));
-	  std::copy(__first._M_cur, __first._M_cur + __clen, __result._M_cur);
+	  _GLIBCXX_STD_A::copy(__first._M_cur, __first._M_cur + __clen,
+			       __result._M_cur);
 	  __first += __clen;
 	  __result += __clen;
 	  __len -= __clen;
@@ -938,12 +948,14 @@
     }
 
   template<typename _Tp>
-    _Deque_iterator<_Tp, _Tp&, _Tp*>
-    copy_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*> __first,
-		  _Deque_iterator<_Tp, const _Tp&, const _Tp*> __last,
-		  _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
+    _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>
+    copy_backward(
+      _GLIBCXX_STD_C::_Deque_iterator<_Tp, const _Tp&, const _Tp*> __first,
+      _GLIBCXX_STD_C::_Deque_iterator<_Tp, const _Tp&, const _Tp*> __last,
+      _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> __result)
     {
-      typedef typename _Deque_iterator<_Tp, _Tp&, _Tp*>::_Self _Self;
+      typedef typename _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>::_Self
+	_Self;
       typedef typename _Self::difference_type difference_type;
 
       difference_type __len = __last - __first;
@@ -968,7 +980,7 @@
 
 	  const difference_type __clen = std::min(__len,
 						  std::min(__llen, __rlen));
-	  std::copy_backward(__lend - __clen, __lend, __rend);
+	  _GLIBCXX_STD_A::copy_backward(__lend - __clen, __lend, __rend);
 	  __last -= __clen;
 	  __result -= __clen;
 	  __len -= __clen;
@@ -978,12 +990,13 @@
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
   template<typename _Tp>
-    _Deque_iterator<_Tp, _Tp&, _Tp*>
-    move(_Deque_iterator<_Tp, const _Tp&, const _Tp*> __first,
-	 _Deque_iterator<_Tp, const _Tp&, const _Tp*> __last,
-	 _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
+    _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>
+    move(_GLIBCXX_STD_C::_Deque_iterator<_Tp, const _Tp&, const _Tp*> __first,
+	 _GLIBCXX_STD_C::_Deque_iterator<_Tp, const _Tp&, const _Tp*> __last,
+	 _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> __result)
     {
-      typedef typename _Deque_iterator<_Tp, _Tp&, _Tp*>::_Self _Self;
+      typedef typename _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>::_Self
+	_Self;
       typedef typename _Self::difference_type difference_type;
 
       difference_type __len = __last - __first;
@@ -992,7 +1005,8 @@
 	  const difference_type __clen
 	    = std::min(__len, std::min(__first._M_last - __first._M_cur,
 				       __result._M_last - __result._M_cur));
-	  std::move(__first._M_cur, __first._M_cur + __clen, __result._M_cur);
+	  _GLIBCXX_STD_A::move(__first._M_cur, __first._M_cur + __clen,
+			       __result._M_cur);
 	  __first += __clen;
 	  __result += __clen;
 	  __len -= __clen;
@@ -1001,12 +1015,14 @@
     }
 
   template<typename _Tp>
-    _Deque_iterator<_Tp, _Tp&, _Tp*>
-    move_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*> __first,
-		  _Deque_iterator<_Tp, const _Tp&, const _Tp*> __last,
-		  _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
+    _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>
+    move_backward(
+      _GLIBCXX_STD_C::_Deque_iterator<_Tp, const _Tp&, const _Tp*> __first,
+      _GLIBCXX_STD_C::_Deque_iterator<_Tp, const _Tp&, const _Tp*> __last,
+      _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*> __result)
     {
-      typedef typename _Deque_iterator<_Tp, _Tp&, _Tp*>::_Self _Self;
+      typedef typename _GLIBCXX_STD_C::_Deque_iterator<_Tp, _Tp&, _Tp*>::_Self
+	_Self;
       typedef typename _Self::difference_type difference_type;
 
       difference_type __len = __last - __first;
@@ -1031,7 +1047,7 @@
 
 	  const difference_type __clen = std::min(__len,
 						  std::min(__llen, __rlen));
-	  std::move_backward(__lend - __clen, __lend, __rend);
+	  _GLIBCXX_STD_A::move_backward(__lend - __clen, __lend, __rend);
 	  __last -= __clen;
 	  __result -= __clen;
 	  __len -= __clen;
@@ -1040,7 +1056,7 @@
     }
 #endif
 
-_GLIBCXX_END_NAMESPACE_CONTAINER
+_GLIBCXX_END_NAMESPACE_ALGO
 } // namespace std
 
 #endif
Index: include/bits/stl_bvector.h
===================================================================
--- include/bits/stl_bvector.h	(revision 173802)
+++ include/bits/stl_bvector.h	(working copy)
@@ -364,7 +364,7 @@
   {
     if (__first._M_p != __last._M_p)
       {
-	std::fill(__first._M_p + 1, __last._M_p, __x ? ~0 : 0);
+	_GLIBCXX_STD_A::fill(__first._M_p + 1, __last._M_p, __x ? ~0 : 0);
 	__fill_bvector(__first, _Bit_iterator(__first._M_p + 1, 0), __x);
 	__fill_bvector(_Bit_iterator(__last._M_p, 0), __last, __x);
       }
@@ -520,8 +520,9 @@
     : _Base(__a)
     {
       _M_initialize(__n);
-      std::fill(this->_M_impl._M_start._M_p, this->_M_impl._M_end_of_storage, 
-		__value ? ~0 : 0);
+      _GLIBCXX_STD_A::fill(this->_M_impl._M_start._M_p,
+			   this->_M_impl._M_end_of_storage,
+			   __value ? ~0 : 0);
     }
 
     vector(const vector& __x)
@@ -813,7 +814,7 @@
     erase(iterator __position)
     {
       if (__position + 1 != end())
-        std::copy(__position + 1, end(), __position);
+        _GLIBCXX_STD_A::copy(__position + 1, end(), __position);
       --this->_M_impl._M_finish;
       return __position;
     }
@@ -821,7 +822,7 @@
     iterator
     erase(iterator __first, iterator __last)
     {
-      _M_erase_at_end(std::copy(__last, end(), __first));
+      _M_erase_at_end(_GLIBCXX_STD_A::copy(__last, end(), __first));
       return __first;
     }
 
@@ -859,9 +860,10 @@
     _M_copy_aligned(const_iterator __first, const_iterator __last,
 		    iterator __result)
     {
-      _Bit_type* __q = std::copy(__first._M_p, __last._M_p, __result._M_p);
-      return std::copy(const_iterator(__last._M_p, 0), __last,
-		       iterator(__q, 0));
+      _Bit_type* __q = _GLIBCXX_STD_A::copy(__first._M_p, __last._M_p,
+					    __result._M_p);
+      return _GLIBCXX_STD_A::copy(const_iterator(__last._M_p, 0), __last,
+				  iterator(__q, 0));
     }
 
     void
@@ -884,8 +886,8 @@
       _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
       {
 	_M_initialize(static_cast<size_type>(__n));
-	std::fill(this->_M_impl._M_start._M_p, 
-		  this->_M_impl._M_end_of_storage, __x ? ~0 : 0);
+	_GLIBCXX_STD_A::fill(this->_M_impl._M_start._M_p, 
+			     this->_M_impl._M_end_of_storage, __x ? ~0 : 0);
       }
 
     template<typename _InputIterator>
@@ -911,7 +913,7 @@
       {
 	const size_type __n = std::distance(__first, __last);
 	_M_initialize(__n);
-	std::copy(__first, __last, this->_M_impl._M_start);
+	_GLIBCXX_STD_A::copy(__first, __last, this->_M_impl._M_start);
       }
 
     // _GLIBCXX_RESOLVE_LIB_DEFECTS
@@ -932,15 +934,15 @@
     {
       if (__n > size())
 	{
-	  std::fill(this->_M_impl._M_start._M_p, 
-		    this->_M_impl._M_end_of_storage, __x ? ~0 : 0);
+	  _GLIBCXX_STD_A::fill(this->_M_impl._M_start._M_p, 
+			       this->_M_impl._M_end_of_storage, __x ? ~0 : 0);
 	  insert(end(), __n - size(), __x);
 	}
       else
 	{
 	  _M_erase_at_end(begin() + __n);
-	  std::fill(this->_M_impl._M_start._M_p, 
-		    this->_M_impl._M_end_of_storage, __x ? ~0 : 0);
+	  _GLIBCXX_STD_A::fill(this->_M_impl._M_start._M_p, 
+			       this->_M_impl._M_end_of_storage, __x ? ~0 : 0);
 	}
     }
 
@@ -965,12 +967,12 @@
       {
 	const size_type __len = std::distance(__first, __last);
 	if (__len < size())
-	  _M_erase_at_end(std::copy(__first, __last, begin()));
+	  _M_erase_at_end(_GLIBCXX_STD_A::copy(__first, __last, begin()));
 	else
 	  {
 	    _ForwardIterator __mid = __first;
 	    std::advance(__mid, size());
-	    std::copy(__first, __mid, begin());
+	    _GLIBCXX_STD_A::copy(__first, __mid, begin());
 	    insert(end(), __mid, __last);
 	  }
       }
Index: include/bits/algorithmfwd.h
===================================================================
--- include/bits/algorithmfwd.h	(revision 173802)
+++ include/bits/algorithmfwd.h	(working copy)
@@ -39,7 +39,7 @@
 
 namespace std _GLIBCXX_VISIBILITY(default)
 {
-_GLIBCXX_BEGIN_NAMESPACE_VERSION
+_GLIBCXX_BEGIN_NAMESPACE_ALGO
 
   /*
     adjacent_find
@@ -579,10 +579,6 @@
     _FIter 
     upper_bound(_FIter, _FIter, const _Tp&, _Compare);
 
-_GLIBCXX_END_NAMESPACE_VERSION
-
-_GLIBCXX_BEGIN_NAMESPACE_ALGO
-
   template<typename _FIter>
     _FIter 
     adjacent_find(_FIter, _FIter);
Index: include/bits/streambuf_iterator.h
===================================================================
--- include/bits/streambuf_iterator.h	(revision 173802)
+++ include/bits/streambuf_iterator.h	(working copy)
@@ -73,8 +73,8 @@
       template<bool _IsMove, typename _CharT2>
 	friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, 
 					       _CharT2*>::__type
-	__copy_move_a2(istreambuf_iterator<_CharT2>,
-		       istreambuf_iterator<_CharT2>, _CharT2*);
+	__detail::__copy_move_a2(istreambuf_iterator<_CharT2>,
+				 istreambuf_iterator<_CharT2>, _CharT2*);
 
       template<typename _CharT2>
 	friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
@@ -294,6 +294,11 @@
       return __result;
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+namespace detail
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   template<bool _IsMove, typename _CharT>
     typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, 
     				    ostreambuf_iterator<_CharT> >::__type
@@ -324,10 +329,10 @@
     __copy_move_a2(istreambuf_iterator<_CharT> __first,
 		   istreambuf_iterator<_CharT> __last, _CharT* __result)
     {
-      typedef istreambuf_iterator<_CharT>                  __is_iterator_type;
-      typedef typename __is_iterator_type::traits_type     traits_type;
-      typedef typename __is_iterator_type::streambuf_type  streambuf_type;
-      typedef typename traits_type::int_type               int_type;
+      typedef istreambuf_iterator<_CharT>		  __is_iterator_type;
+      typedef typename __is_iterator_type::traits_type	  traits_type;
+      typedef typename __is_iterator_type::streambuf_type streambuf_type;
+      typedef typename traits_type::int_type		  int_type;
 
       if (__first._M_sbuf && !__last._M_sbuf)
 	{
@@ -353,6 +358,10 @@
       return __result;
     }
 
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
   template<typename _CharT>
     typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
 		  		    istreambuf_iterator<_CharT> >::__type
Index: include/bits/random.tcc
===================================================================
--- include/bits/random.tcc	(revision 173802)
+++ include/bits/random.tcc	(working copy)
@@ -150,7 +150,7 @@
       seed(_Sseq& __q)
       {
 	const _UIntType __k0 = __m == 0 ? std::numeric_limits<_UIntType>::digits
-	                                : std::__lg(__m);
+	                                : __detail::__lg(__m);
 	const _UIntType __k = (__k0 + 31) / 32;
 	uint_least32_t __arr[__k + 3];
 	__q.generate(__arr + 0, __arr + __k + 3);
@@ -2750,7 +2750,7 @@
       if (__begin == __end)
 	return;
 
-      std::fill(__begin, __end, _Type(0x8b8b8b8bu));
+      _GLIBCXX_STD_A::fill(__begin, __end, _Type(0x8b8b8b8bu));
 
       const size_t __n = __end - __begin;
       const size_t __s = _M_v.size();
Index: include/bits/random.h
===================================================================
--- include/bits/random.h	(revision 173802)
+++ include/bits/random.h	(working copy)
@@ -488,7 +488,8 @@
       friend bool
       operator==(const mersenne_twister_engine& __lhs,
 		 const mersenne_twister_engine& __rhs)
-      { return std::equal(__lhs._M_x, __lhs._M_x + state_size, __rhs._M_x); }
+      { return _GLIBCXX_PARALLEL_A::equal(__lhs._M_x, __lhs._M_x + state_size,
+				      __rhs._M_x); }
 
       /**
        * @brief Inserts the current state of a % mersenne_twister_engine
@@ -702,7 +703,8 @@
       friend bool
       operator==(const subtract_with_carry_engine& __lhs,
 		 const subtract_with_carry_engine& __rhs)
-      { return std::equal(__lhs._M_x, __lhs._M_x + long_lag, __rhs._M_x); }
+      { return _GLIBCXX_PARALLEL_A::equal(__lhs._M_x, __lhs._M_x + long_lag,
+				      __rhs._M_x); }
 
       /**
        * @brief Inserts the current state of a % subtract_with_carry_engine
@@ -5377,7 +5379,7 @@
     template<typename OutputIterator>
       void
       param(OutputIterator __dest) const
-      { std::copy(_M_v.begin(), _M_v.end(), __dest); }
+      { _GLIBCXX_PARALLEL_A::copy(_M_v.begin(), _M_v.end(), __dest); }
 
   private:
     ///
Index: include/bits/stl_tree.h
===================================================================
--- include/bits/stl_tree.h	(revision 173802)
+++ include/bits/stl_tree.h	(working copy)
@@ -847,7 +847,7 @@
 	       const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y)
     {
       return __x.size() == __y.size()
-	     && std::equal(__x.begin(), __x.end(), __y.begin());
+	     && _GLIBCXX_PARALLEL_A::equal(__x.begin(), __x.end(), __y.begin());
     }
 
   template<typename _Key, typename _Val, typename _KeyOfValue,
Index: include/tr1/hashtable.h
===================================================================
--- include/tr1/hashtable.h	(revision 173802)
+++ include/tr1/hashtable.h	(working copy)
@@ -491,7 +491,7 @@
       // We allocate one extra bucket to hold a sentinel, an arbitrary
       // non-null pointer.  Iterator increment relies on this.
       _Node** __p = __alloc.allocate(__n + 1);
-      std::fill(__p, __p + __n, (_Node*) 0);
+      _GLIBCXX_PARALLEL_A::fill(__p, __p + __n, (_Node*) 0);
       __p[__n] = reinterpret_cast<_Node*>(0x1000);
       return __p;
     }
Index: include/tr1/hashtable_policy.h
===================================================================
--- include/tr1/hashtable_policy.h	(revision 173802)
+++ include/tr1/hashtable_policy.h	(working copy)
@@ -420,8 +420,9 @@
   _Prime_rehash_policy::
   _M_next_bkt(std::size_t __n) const
   {
-    const unsigned long* __p = std::lower_bound(__prime_list, __prime_list
-						+ _S_n_primes, __n);
+    const unsigned long* __p =
+      _GLIBCXX_PARALLEL_A::lower_bound(__prime_list, __prime_list + _S_n_primes,
+				   __n);
     _M_next_resize = 
       static_cast<std::size_t>(__builtin_ceil(*__p * _M_max_load_factor));
     return *__p;
@@ -434,8 +435,9 @@
   _M_bkt_for_elements(std::size_t __n) const
   {
     const float __min_bkts = __n / _M_max_load_factor;
-    const unsigned long* __p = std::lower_bound(__prime_list, __prime_list
-						+ _S_n_primes, __min_bkts);
+    const unsigned long* __p =
+      _GLIBCXX_PARALLEL_A::lower_bound(__prime_list, __prime_list + _S_n_primes,
+				   __min_bkts);
     _M_next_resize =
       static_cast<std::size_t>(__builtin_ceil(*__p * _M_max_load_factor));
     return *__p;
@@ -463,8 +465,9 @@
 	  {
 	    __min_bkts = std::max(__min_bkts, _M_growth_factor * __n_bkt);
 	    const unsigned long* __p =
-	      std::lower_bound(__prime_list, __prime_list + _S_n_primes,
-			       __min_bkts);
+	      _GLIBCXX_PARALLEL_A::lower_bound(__prime_list,
+					       __prime_list + _S_n_primes,
+					       __min_bkts);
 	    _M_next_resize = static_cast<std::size_t>
 	      (__builtin_ceil(*__p * _M_max_load_factor));
 	    return std::make_pair(true, *__p);
Index: include/Makefile.am
===================================================================
--- include/Makefile.am	(revision 173802)
+++ include/Makefile.am	(working copy)
@@ -701,18 +701,25 @@
 debug_srcdir = ${glibcxx_srcdir}/include/debug
 debug_builddir = ./debug
 debug_headers = \
+	${debug_srcdir}/algorithm \
+	${debug_srcdir}/algorithmfwd.h \
+	${debug_srcdir}/algo.h \
+	${debug_srcdir}/algobase.h \
 	${debug_srcdir}/bitset \
 	${debug_srcdir}/debug.h \
 	${debug_srcdir}/deque \
 	${debug_srcdir}/formatter.h \
 	${debug_srcdir}/forward_list \
 	${debug_srcdir}/functions.h \
+	${debug_srcdir}/heap.h \
 	${debug_srcdir}/list \
 	${debug_srcdir}/map \
 	${debug_srcdir}/macros.h \
 	${debug_srcdir}/map.h \
 	${debug_srcdir}/multimap.h \
 	${debug_srcdir}/multiset.h \
+	${debug_srcdir}/numeric \
+	${debug_srcdir}/numeric.h \
 	${debug_srcdir}/safe_base.h \
 	${debug_srcdir}/safe_iterator.h \
 	${debug_srcdir}/safe_iterator.tcc \
@@ -746,6 +753,7 @@
         ${parallel_srcdir}/find_selectors.h \
         ${parallel_srcdir}/for_each.h \
         ${parallel_srcdir}/for_each_selectors.h \
+        ${parallel_srcdir}/heap.h \
         ${parallel_srcdir}/iterator.h \
         ${parallel_srcdir}/list_partition.h \
         ${parallel_srcdir}/losertree.h \
Index: testsuite/25_algorithms/heap/moveable2.cc
===================================================================
--- testsuite/25_algorithms/heap/moveable2.cc	(revision 173802)
+++ testsuite/25_algorithms/heap/moveable2.cc	(working copy)
@@ -60,7 +60,7 @@
   std::make_heap(makecon_ref.begin(), makecon_ref.end(), are_ordered_int);
   for (int z = 0; z < length; ++z)
     VERIFY( makeheap[z] == makeheap_ref[z] );
-  VERIFY( std::__is_heap(makecon.begin(), makecon.end(), are_ordered) );
+  VERIFY( std::is_heap(makecon.begin(), makecon.end(), are_ordered) );
   for (int z = 0; z < length; ++z)
     VERIFY( makeheap[z].valid );
 }
@@ -80,7 +80,7 @@
   std::pop_heap(popcon_ref.begin(), popcon_ref.end(), are_ordered_int);
   for (int z = 0; z < length; ++z)
     VERIFY( popheap[z] == popheap_ref[z] );
-  VERIFY( (std::__is_heap(popheap, popheap + length - 1), are_ordered) );
+  VERIFY( (std::is_heap(popheap, popheap + length - 1), are_ordered) );
   for (int z = 0; z < length; ++z)
     VERIFY( popheap[z].val <= popheap[length-1].val && popheap[z].valid );
 }
@@ -122,7 +122,7 @@
   std::push_heap(pushcon_ref.begin(), pushcon_ref.end(), are_ordered_int);
   for (int z = 0; z < length + 1; ++z)
     VERIFY( pushheap[z] == pushheap_ref[z] );
-  VERIFY( std::__is_heap(pushheap, pushheap + length + 1) );
+  VERIFY( std::is_heap(pushheap, pushheap + length + 1) );
   for (int z = 0; z < length + 1; ++z)
     VERIFY( pushheap[z].valid );
 }
@@ -138,7 +138,7 @@
       while (std::next_permutation(array, array + i))
 	{
 	  check_make(array, i);
-	  if (std::__is_heap(array, array + i, are_ordered_int))
+	  if (std::is_heap(array, array + i, are_ordered_int))
 	    {
 	      check_pop(array, i);
 	      check_sort(array, i);
Index: testsuite/25_algorithms/heap/moveable.cc
===================================================================
--- testsuite/25_algorithms/heap/moveable.cc	(revision 173802)
+++ testsuite/25_algorithms/heap/moveable.cc	(working copy)
@@ -55,7 +55,7 @@
   std::make_heap(makecon_ref.begin(), makecon_ref.end());
   for (int z = 0; z < length; ++z)
     VERIFY( makeheap[z] == makeheap_ref[z] );
-  VERIFY( std::__is_heap(makecon.begin(), makecon.end()) );
+  VERIFY( std::is_heap(makecon.begin(), makecon.end()) );
   for (int z = 0; z < length; ++z)
     VERIFY( makeheap[z].valid );
 }
@@ -75,7 +75,7 @@
   std::pop_heap(popcon_ref.begin(), popcon_ref.end());
   for (int z = 0; z < length; ++z)
     VERIFY( popheap[z] == popheap_ref[z] );
-  VERIFY( (std::__is_heap(popheap, popheap + length - 1)) );
+  VERIFY( (std::is_heap(popheap, popheap + length - 1)) );
   for (int z = 0; z < length; ++z)
     VERIFY( popheap[z].val <= popheap[length-1].val && popheap[z].valid );
 }
@@ -117,7 +117,7 @@
   std::push_heap(pushcon_ref.begin(), pushcon_ref.end());
   for (int z = 0; z < length + 1; ++z)
     VERIFY( pushheap[z] == pushheap_ref[z] );
-  VERIFY( std::__is_heap(pushheap, pushheap + length + 1) );
+  VERIFY( std::is_heap(pushheap, pushheap + length + 1) );
   for (int z = 0; z < length + 1; ++z)
     VERIFY( pushheap[z].valid );
 }
@@ -133,7 +133,7 @@
       while (std::next_permutation(array, array + i))
 	{
 	  check_make(array, i);
-	  if (std::__is_heap(array, array + i))
+	  if (std::is_heap(array, array + i))
 	    {
 	      check_pop(array, i);
 	      check_sort(array, i);
Index: testsuite/23_containers/deque/requirements/dr438/assign_neg.cc
===================================================================
--- testsuite/23_containers/deque/requirements/dr438/assign_neg.cc	(revision 173802)
+++ testsuite/23_containers/deque/requirements/dr438/assign_neg.cc	(working copy)
@@ -18,7 +18,7 @@
 // <http://www.gnu.org/licenses/>.
 
 // { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1661 }
+// { dg-error "no matching" "" { target *-*-* } 1667 }
 // { dg-excess-errors "" }
 
 #include <deque>
Index: testsuite/23_containers/deque/requirements/dr438/insert_neg.cc
===================================================================
--- testsuite/23_containers/deque/requirements/dr438/insert_neg.cc	(revision 173802)
+++ testsuite/23_containers/deque/requirements/dr438/insert_neg.cc	(working copy)
@@ -18,7 +18,7 @@
 // <http://www.gnu.org/licenses/>.
 
 // { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1745 }
+// { dg-error "no matching" "" { target *-*-* } 1751 }
 // { dg-excess-errors "" }
 
 #include <deque>
Index: testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc
===================================================================
--- testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc	(revision 173802)
+++ testsuite/23_containers/deque/requirements/dr438/constructor_1_neg.cc	(working copy)
@@ -18,7 +18,7 @@
 // <http://www.gnu.org/licenses/>.
 
 // { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1594 }
+// { dg-error "no matching" "" { target *-*-* } 1600 }
 // { dg-excess-errors "" }
 
 #include <deque>
Index: testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc
===================================================================
--- testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc	(revision 173802)
+++ testsuite/23_containers/deque/requirements/dr438/constructor_2_neg.cc	(working copy)
@@ -18,7 +18,7 @@
 // <http://www.gnu.org/licenses/>.
 
 // { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1594 }
+// { dg-error "no matching" "" { target *-*-* } 1600 }
 // { dg-excess-errors "" }
 
 #include <deque>

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