Index: libstdc++-v3/include/Makefile.in
===================================================================
--- libstdc++-v3/include/Makefile.in	(revision 139583)
+++ libstdc++-v3/include/Makefile.in	(working copy)
@@ -732,6 +732,7 @@
 	${ext_srcdir}/atomicity.h \
 	${ext_srcdir}/array_allocator.h \
 	${ext_srcdir}/bitmap_allocator.h \
+	${ext_srcdir}/cast.h \
 	${ext_srcdir}/codecvt_specializations.h \
 	${ext_srcdir}/concurrence.h \
 	${ext_srcdir}/debug_allocator.h \
@@ -744,9 +745,11 @@
 	${ext_srcdir}/memory \
 	${ext_srcdir}/mt_allocator.h \
 	${ext_srcdir}/new_allocator.h \
+	${ext_srcdir}/nonstd_allocator.h \
 	${ext_srcdir}/numeric \
 	${ext_srcdir}/numeric_traits.h \
 	${ext_srcdir}/pod_char_traits.h \
+	${ext_srcdir}/pointer.h \
 	${ext_srcdir}/pool_allocator.h \
 	${ext_srcdir}/rb_tree \
 	${ext_srcdir}/rope \
Index: libstdc++-v3/include/ext/cast.h
===================================================================
--- libstdc++-v3/include/ext/cast.h	(revision 0)
+++ libstdc++-v3/include/ext/cast.h	(revision 0)
@@ -0,0 +1,90 @@
+// Pointer casting classes -*- C++ -*-
+
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
+// 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 2, 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.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// This version of cast_to<> is based on an original version used
+// in Boost.interprocess, and is
+// (C) Copyright Ion Gaztañaga 2005-2007. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/interprocess for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef _GCC_EXT_CAST_TO_
+#define _GCC_EXT_CAST_TO_
+
+_GLIBCXX_BEGIN_NAMESPACE(__gcc_cxx);
+
+
+// Provides a class for casting between pointer types.
+// T must be a pointer type.
+// examples:
+//
+//  const T* cp;
+//  T* p = cast_to<T*>::using_const_cast(cp);
+//
+//	relative_ptr<const T> cp;
+//  relative_ptr<T> p = cast_to< relative_ptr<const T> >::using const_cast(cp);
+
+template<typename _T, typename _S>
+_T
+static_pointer_cast(_S * const arg)
+{
+    return static_cast<_T>( arg );
+}
+
+template<typename _T, typename _S>
+_T
+dynamic_pointer_cast(_S * const arg)
+{
+    return dynamic_cast<_T>( arg );
+}
+
+template<typename _T, typename _S>
+_T
+const_pointer_cast(_S * const arg)
+{
+    return const_cast<_T>( arg );
+}
+
+template<typename _T, typename _S>
+_T
+reinterpret_pointer_cast(_S * const arg)
+{
+    return reinterpret_cast<_T>( arg );
+}
+
+
+_GLIBCXX_END_NAMESPACE
+
+#endif 
Index: libstdc++-v3/include/ext/nonstd_allocator.h
===================================================================
--- libstdc++-v3/include/ext/nonstd_allocator.h	(revision 0)
+++ libstdc++-v3/include/ext/nonstd_allocator.h	(revision 0)
@@ -0,0 +1,165 @@
+#ifndef _NONSTD_ALLOCATOR_H_
+#define _NONSTD_ALLOCATOR_H_
+
+#include <memory>
+#include <limits>
+#include <ext/pointer.h>
+
+using __gcc_cxx::_Pointer_adapter;
+using __gcc_cxx::_Relative_pointer_impl;
+using __gcc_cxx::static_pointer_cast;
+using __gcc_cxx::const_pointer_cast;
+
+
+_GLIBCXX_BEGIN_NAMESPACE(__gcc_cxx)
+
+
+  // forward declaration
+  template<typename _Tp>
+    class _NonStd_allocator;
+
+    
+  /// _NonStd_allocator<void> specialization.
+  template<>
+    class _NonStd_allocator<void>
+    {
+    public:
+      typedef size_t      size_type;
+      typedef ptrdiff_t   difference_type;
+      
+      // Note the non-standard pointer types
+      typedef _Pointer_adapter<_Relative_pointer_impl<void> >       pointer;
+      typedef _Pointer_adapter<_Relative_pointer_impl<const void> > const_pointer;
+      
+      typedef void        value_type;
+
+      template<typename _Tp1>
+        struct rebind
+        { typedef _NonStd_allocator<_Tp1> other; };
+    };
+
+    
+  /**
+   * @brief An example of a statefull allocator which 
+   * uses a non-standard pointer type.
+   * 
+   * In this case, the allocator itself holds state, as might be needed
+   * with specialized allocators.  This is valid, but recognize that when
+   * a type that uses an allocator template parameter is itself used within
+   * a container (e.g. vector<basic_string<_Tp>>) allocator instances will
+   * be created using their default constructor.  Internally, the allocator
+   * might share some static or thread-specific memory among all
+   * instances in order to cope with this.
+   * 
+   * The second quality of this example is that it
+   * specifies that the container it is used with
+   * must use a relative pointer as their physical storage mechanism.
+   * This might be done (for example) to create containers which are safe
+   * in shared memory segments mapped at different virtual addresses by different
+   * processes.  It can also
+   * be used to enable smart pointers although that would have some implications
+   * for the destroy() and deallocate() methods as well.
+   * Being an example, this implementation just a private instance of std::allocator
+   * for its implementation.
+   */
+  template<typename _Tp>
+    class _NonStd_allocator
+    {
+   public:
+      typedef size_t     size_type;
+      typedef ptrdiff_t  difference_type;
+
+      // Note the non-standard pointer types.  Store pointers as a relative value
+      typedef _Pointer_adapter<_Relative_pointer_impl<_Tp> >       pointer;
+      typedef _Pointer_adapter<_Relative_pointer_impl<const _Tp> > const_pointer;
+
+      typedef _Tp&       reference;
+      typedef const _Tp& const_reference;
+      typedef _Tp        value_type;
+
+      template<typename _Tp1>
+        struct rebind
+        { typedef _NonStd_allocator<_Tp1> other; };
+
+      _NonStd_allocator() throw() : _m_real_alloc()
+        { }
+
+      _NonStd_allocator(const _NonStd_allocator &__rarg) throw() 
+        : _m_real_alloc(__rarg._m_real_alloc)
+        { }
+
+      template <class _Tp1> 
+      _NonStd_allocator(const _NonStd_allocator<_Tp1>& __rarg) throw() 
+        : _m_real_alloc(__rarg.getUnderlyingImp())
+        { }
+
+      ~_NonStd_allocator() throw()
+        { }
+    	
+      pointer address(reference __x) const
+        { return &__x; }
+
+      const_pointer address(const_reference __x) const
+        { return &__x; }
+
+      pointer allocate(size_type __n, void* __hint = 0 )
+    	{ return _m_real_alloc.allocate(__n,__hint); }
+    	  
+      void deallocate(pointer __p, size_type __n)
+    	{ _m_real_alloc.deallocate(static_pointer_cast<_Tp*>(__p), __n); }
+
+      size_type max_size() const throw()
+        { return std::numeric_limits<size_type>::max() / sizeof(_Tp); }
+    	
+      void construct(pointer __p, const _Tp& __val)
+        { new(static_pointer_cast<void*>(__p)) _Tp(__val); }
+
+      void destroy(pointer __p)
+        { __p->~_Tp(); }
+
+      template<typename _T1>
+      inline bool
+      operator==(const _NonStd_allocator<_T1>& __rarg)
+        { return _m_real_alloc == __rarg.getUnderlyingImp(); }
+
+      inline bool
+      operator==(const _NonStd_allocator& __rarg)
+        { return _m_real_alloc == __rarg._m_real_alloc; }
+
+      template<typename _T1>
+      inline bool
+      operator!=(const _NonStd_allocator<_T1>& __rarg)
+        { return _m_real_alloc != __rarg.getUnderlyingImp(); }
+
+      inline bool
+      operator!=(const _NonStd_allocator& __rarg)
+        { return _m_real_alloc != __rarg._m_real_alloc; }
+
+      template<typename _U>
+      inline friend void
+      swap(_NonStd_allocator<_U>& __larg, _NonStd_allocator<_U>& __rarg);
+
+      // A method specific to this implementation.
+      const std::allocator<_Tp>& 
+      getUnderlyingImp() const
+      { return _m_real_alloc; }
+      
+   private:
+	   // simlated state data.
+	   std::allocator<_Tp>  _m_real_alloc;
+    };
+
+
+    template<typename _Tp>
+    inline void 
+    swap(_NonStd_allocator<_Tp>& __larg, _NonStd_allocator<_Tp>& __rarg) 
+    {
+	  std::allocator<_Tp> temp = __rarg._m_real_alloc;
+	  __rarg._m_real_alloc = __larg._m_real_alloc;
+	  __larg._m_real_alloc = temp;
+    }
+    
+
+_GLIBCXX_END_NAMESPACE
+
+#endif /*_NONSTD_ALLOCATOR_H_*/
Index: libstdc++-v3/include/ext/pointer.h
===================================================================
--- libstdc++-v3/include/ext/pointer.h	(revision 0)
+++ libstdc++-v3/include/ext/pointer.h	(revision 0)
@@ -0,0 +1,474 @@
+// Custom pointer shell and pointer types
+
+// Copyright (C) 2008
+// 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 2, 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.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+/**
+ * @file ext/pointer.h
+ * @author Bob Walters <bob.s.walters _at_ gmail>
+ *
+ * Provides reusable _Pointer shell for assisting in the development of
+ * custom pointer types that can be used with libstdc++ STL containers via
+ * the allocator::pointer and allocator::const_pointer typedefs.
+ */
+
+#ifndef _GCC_EXT_POINTER_ADAPTER
+#define _GCC_EXT_POINTER_ADAPTER 1
+
+#include <ostream>
+#include <ext/cast.h>
+#include <bits/concept_check.h>
+
+
+// forward declaration of the iterator tag
+namespace std {
+    struct random_access_iterator_tag;
+};
+
+
+_GLIBCXX_BEGIN_NAMESPACE(__gcc_cxx)
+
+
+// The following is the contract that a type must meet to work as the
+// _Storage_policy type for the _Pointer_adapter template below.
+// 3 things:
+// 1) A get() API for returning the stored pointer value.
+// 2) An set() API for storing a pointer value.
+// 3) An element_type typedef to define the type this points to.
+//
+// In this example, _Std_pointer_impl is a storage policy for
+// storing pointers normaly (using _T*)
+template <typename _T> 
+class _Std_pointer_impl {
+public:
+    // the type this pointer points to.
+    typedef _T element_type;
+
+    // A method to fetch the pointer value as a standard T* value;
+    inline _T* 
+    get() const 
+    { return _M_value; }
+
+    // A method to set the pointer value, from a standard T* value;
+    inline void 
+    set( _T* __arg ) 
+    { _M_value = __arg; }
+
+private:
+    _T* _M_value;
+};
+
+
+// The following is a second example impl.  This one stores the pointer
+// value as a byte offset value relative to 'this'.  This is intended for
+// pointer within shared memory regions which might be mapped at different
+// addresses by different processes.  For null pointers, a value of 1 is
+// used.  (0 is legitimate sometimes for nodes in circularly linked lists)
+// This value was chosen as the least likely to generate an incorrect null,
+// As there is no reason why any normal pointer would point 1 byte into
+// its own pointer address.
+template <typename _T> 
+class _Relative_pointer_impl {
+public:
+    typedef _T element_type;
+
+    _T* 
+    get() const 
+    {
+        if ( _M_diff == 1 )
+            return NULL;
+        else
+            return reinterpret_cast<_T*>( 
+                          const_cast<char*>(reinterpret_cast<const char*>(this))
+                          + _M_diff );
+    }
+
+    void 
+    set( _T* __arg )
+    {
+        if (__arg == NULL)
+            _M_diff = 1;
+        else
+            _M_diff = reinterpret_cast<char*>(__arg) 
+                              - reinterpret_cast<char*>(this);
+    }
+
+private:
+    ptrdiff_t _M_diff;
+};
+
+// Relative_pointer_impl needs a specialization for const T because of
+// the casting done during pointer arithmetic.
+template <typename _T> class _Relative_pointer_impl<const _T> {
+public:
+    typedef const _T element_type;
+
+    const _T* 
+    get() const
+    {
+        if ( _M_diff == 1 )
+            return NULL;
+        else
+            return reinterpret_cast<const _T*>(
+                            (reinterpret_cast<const char*>(this)) + _M_diff );
+    }
+
+    void 
+    set( const _T* __arg ) 
+    {
+        if (__arg == NULL)
+            _M_diff = 1;
+        else
+            _M_diff = reinterpret_cast<const char*>(__arg) 
+                              - reinterpret_cast<const char*>(this);
+    }
+
+private:
+    ptrdiff_t _M_diff;
+};
+
+
+
+
+// The specialization on this type helps resolve the problem of
+// reference to void, and eliminates the need to specialize _Pointer_adapter
+// for cases of void*, const void*, and so on.
+struct _Invalid_type { };
+
+template <typename _T>
+struct _Reference_type {
+    typedef _T& reference;
+};
+template <> 
+struct _Reference_type<void> {
+    typedef _Invalid_type& reference;
+};
+template <> 
+struct _Reference_type<const void> {
+    typedef const _Invalid_type& reference;
+};
+template <> 
+struct _Reference_type<volatile void> {
+    typedef volatile _Invalid_type&  reference;
+};
+template <> 
+struct _Reference_type<volatile const void> {
+    typedef const volatile _Invalid_type&  reference;
+};
+
+
+// This structure accomodates the way in which std::iterator_traits<>
+// is normally specialized for const T*, so that value_type is still T.
+template <typename T> 
+struct _Unqualified_type {
+    typedef T type;
+};
+template <typename T> 
+struct _Unqualified_type<const T> {
+    typedef T type;
+};
+template <typename T> 
+struct _Unqualified_type<volatile T> {
+    typedef volatile T type;
+};
+template <typename T> 
+struct _Unqualified_type<volatile const T> {
+    typedef volatile T type;
+};
+
+
+
+/**
+ * The following type is a functioning 'alternative pointer' that works with 
+ * libstdc++-v3 containers when provided as the pointer typedef of the 
+ * allocator passed to the container.
+ * 
+ * The pointer type used with the containers doesn't have to be this class,
+ * but it will have to support the implicit conversions, pointer arithmetic,
+ * comparison operators, etc. that are supported by this implementation
+ * without additional ambiguities.  Because creating a working pointer can
+ * be challenging, this pointer template was redesigned to support an 
+ * easier impl type, so that it becomes reusable for anyone who wants to
+ * create a custom pointer type of their own.  Just write a pointer_impl,
+ * and plug it in.
+ *
+ * Note:  The const qualifier works with this pointer adapter as follows:
+ *
+ * T*              ==  _Pointer_adapter<_Std_pointer_impl<T> >;
+ * const T*        ==  _Pointer_adapter<_Std_pointer_impl<const T> >;
+ * T* const        ==  const _Pointer_adapter<_Std_pointer_impl<T> >;
+ * const T* const  ==  const _Pointer_adapter<_Std_pointer_impl<const T> >;
+ */
+
+template <typename _Storage_policy >
+class _Pointer_adapter {
+public:
+    typedef typename _Storage_policy::element_type   element_type; // shorthand
+
+    // These are needed for iterator_traits
+    typedef std::random_access_iterator_tag          iterator_category;
+    typedef typename _Unqualified_type<element_type>::type     value_type;
+    typedef ptrdiff_t                                difference_type;
+    typedef _Pointer_adapter                         pointer;
+    typedef typename _Reference_type<element_type>::reference  reference;
+
+    // Reminder: 'const' methods mean that the method is valid when the pointer
+    // is immutable, and has nothing to do with whether the 'pointee' is const.
+
+    // Default Constructor (Convert from element_type*)
+    _Pointer_adapter( element_type * __arg = NULL )
+    { _M_impl.set( __arg ); }
+
+    // Copy constructor from _Pointer_adapter of same type.
+    _Pointer_adapter( const _Pointer_adapter& __arg ) 
+    { _M_impl.set( __arg.get() ); }
+
+    // Convert from _U* if conversion to element_type* is valid.
+    template <typename _U>
+    _Pointer_adapter( _U *__arg )
+    {
+  	  __glibcxx_function_requires(_ConvertibleConcept<element_type*, _U*>);
+  	  _M_impl.set( static_cast<element_type*>(__arg) ); 
+  	}
+
+    // Conversion from another _Pointer_adapter if _U if static cast is valid.
+    template <typename _U>
+    _Pointer_adapter( const _Pointer_adapter<_U>& __arg )
+    { _M_impl.set( static_cast<element_type*>(__arg.get()) ); }
+
+    // Destructor
+    ~_Pointer_adapter() { }
+
+    _Pointer_adapter&
+    operator=( const _Pointer_adapter& __arg ) 
+    { _M_impl.set( __arg.get() ); }
+
+ 
+    inline element_type* 
+    get() const 
+    { return _M_impl.get(); }
+    
+    // Operator*, returns element_type&
+    inline reference 
+    operator*() const 
+    { return *(_M_impl.get()); }
+
+    // Operator->, returns element_type*
+    inline element_type* 
+    operator->() const 
+    { return _M_impl.get(); }
+
+    // Operator[], returns a element_type& to the item at that loc.
+    inline reference 
+    operator[](int __index) const
+    { return _M_impl.get()[__index]; }
+
+    // Implicit conversion to "bool"
+  private:
+	typedef element_type * (_Pointer_adapter::*__unspecified_bool_type)() const;
+
+  public:
+    operator __unspecified_bool_type() const // never throws
+    { return _M_impl.get() == 0 ? 0 : &_Pointer_adapter::get; }
+
+    // ! operator (for: if (!ptr)...)
+    inline bool 
+    operator!() const 
+    { return (_M_impl.get()==NULL); }
+
+    
+    // Pointer differences
+    inline friend std::ptrdiff_t 
+    operator-(const _Pointer_adapter& __lhs, element_type* __rhs) 
+    { return (__lhs.get() - __rhs); }
+
+    inline friend std::ptrdiff_t 
+    operator-(element_type* __lhs, const _Pointer_adapter& __rhs) 
+    { return (__lhs - __rhs.get()); }
+
+    template <class _U>
+    inline friend std::ptrdiff_t 
+    operator-(const _Pointer_adapter& __lhs, _U* __rhs) 
+    { return (__lhs.get() - __rhs); }
+
+    template <class _U>
+    inline friend std::ptrdiff_t 
+    operator-(_U* __lhs, const _Pointer_adapter& __rhs)
+    { return (__lhs - __rhs.get()); }
+
+    template <typename _U>
+    inline std::ptrdiff_t 
+    operator-(const _Pointer_adapter<_U>& __rhs) const 
+    { return (_M_impl.get() - __rhs.get()); }
+
+    // Pointer math
+    // Note: There is a reason for all this overloading based on different
+    // integer types.  In some libstdc++-v3 test cases, a templated
+    // operator+ is declared which can match anything.  This templated operator
+    // tends to "steal" the recognition of these operator+ unless the integer
+    // type matches perfectly.
+
+#define _GCC_CXX_POINTER_ARITH_OPERATOR_SET(INT_TYPE) \
+    inline friend _Pointer_adapter \
+    operator+ ( const _Pointer_adapter& __lhs, INT_TYPE __offset) \
+    { return _Pointer_adapter(__lhs.get() + __offset); } \
+\
+    inline friend _Pointer_adapter \
+    operator+ ( INT_TYPE __offset, const _Pointer_adapter& __rhs) \
+    { return _Pointer_adapter(__rhs.get() + __offset); } \
+\
+    inline friend _Pointer_adapter \
+    operator- ( const _Pointer_adapter& __lhs, INT_TYPE __offset) \
+    { return _Pointer_adapter(__lhs.get() - __offset); } \
+\
+    inline _Pointer_adapter& \
+    operator+= ( INT_TYPE __offset) \
+    { \
+        _M_impl.set( _M_impl.get() + __offset ); \
+        return *this; \
+    } \
+\
+    inline _Pointer_adapter& \
+    operator-= ( INT_TYPE __offset) \
+    { \
+        _M_impl.set( _M_impl.get() - __offset ); \
+        return *this; \
+    } 
+// END of _GCC_CXX_POINTER_ARITH_OPERATOR_SET macro
+
+    // Expand into the various pointer arithmatic operators needed.
+    _GCC_CXX_POINTER_ARITH_OPERATOR_SET(int);
+    _GCC_CXX_POINTER_ARITH_OPERATOR_SET(unsigned int);
+    _GCC_CXX_POINTER_ARITH_OPERATOR_SET(long);
+    _GCC_CXX_POINTER_ARITH_OPERATOR_SET(unsigned long);
+
+    // Mathematical Manipulators
+    inline _Pointer_adapter& 
+    operator++ ()
+    {
+        _M_impl.set( _M_impl.get() + 1 ); 
+        return *this;
+    }
+
+    inline _Pointer_adapter 
+    operator++ (int unused) 
+    {
+    	_Pointer_adapter tmp( *this );
+        _M_impl.set( _M_impl.get() + 1 );
+        return tmp;
+    }
+
+    inline _Pointer_adapter& 
+    operator-- () 
+    {
+        _M_impl.set( _M_impl.get() - 1 ); 
+        return *this;
+    }
+
+    inline _Pointer_adapter
+    operator-- (int unused) 
+    {
+    	_Pointer_adapter tmp( *this );
+        _M_impl.set( _M_impl.get() - 1 );
+        return tmp;
+    }
+
+private:
+    _Storage_policy                   _M_impl;
+
+}; // class _Pointer_adapter
+
+
+#define _GCC_CXX_POINTER_COMPARISON_OPERATION_SET(OPERATOR,BLANK) \
+    template <typename _U, typename _V> \
+    inline bool \
+    operator OPERATOR##BLANK (const _Pointer_adapter<_V>& __lhs, _U* __rhs) \
+    { return __lhs.get() OPERATOR##BLANK __rhs; } \
+\
+    template <typename _U, typename _V> \
+    inline bool \
+    operator OPERATOR##BLANK (_U* __lhs, const _Pointer_adapter<_V>& __rhs) \
+    { return __lhs OPERATOR##BLANK __rhs.get(); } \
+\
+    template <typename _U, typename _V> \
+    inline bool \
+    operator OPERATOR##BLANK (const _Pointer_adapter<_U>& __lhs, const _Pointer_adapter<_V>& __rhs) \
+    { return __lhs.get() OPERATOR##BLANK __rhs.get(); } \
+\
+// End GCC_CXX_POINTER_COMPARISON_OPERATION_SET Macro
+
+// Expand into the various comparison operators needed.
+_GCC_CXX_POINTER_COMPARISON_OPERATION_SET(==,);
+_GCC_CXX_POINTER_COMPARISON_OPERATION_SET(!=,);
+_GCC_CXX_POINTER_COMPARISON_OPERATION_SET(<,);
+_GCC_CXX_POINTER_COMPARISON_OPERATION_SET(<=,);
+_GCC_CXX_POINTER_COMPARISON_OPERATION_SET(>,);
+_GCC_CXX_POINTER_COMPARISON_OPERATION_SET(>=,);
+
+
+template <class _E, class _T, class _Y>
+std::basic_ostream<_E, _T>&
+operator<< (std::basic_ostream<_E, _T> &os, _Pointer_adapter<_Y> const& p)
+{
+	os << p.get();
+	return os;
+}
+
+
+template<typename T, typename U>
+inline T
+static_pointer_cast(_Pointer_adapter<U> const& arg)
+{
+    return static_cast<T>( arg.get() );
+}
+
+template<typename T, typename U>
+inline T
+dynamic_pointer_cast(_Pointer_adapter<U> const& arg)
+{
+    return dynamic_cast<T>( arg.get() );
+}
+
+template<typename T, typename U>
+inline T
+const_pointer_cast(_Pointer_adapter<U> const& arg)
+{
+    return const_cast<T>( arg.get() );
+}
+
+template<typename T, typename U>
+inline T
+reinterpret_pointer_cast(_Pointer_adapter<U> const& arg)
+{
+    return reinterpret_cast<T>( arg.get() );
+}
+
+_GLIBCXX_END_NAMESPACE
+
+
+#endif /* _GCC_EXT_POINTER_ADAPTER */
Index: libstdc++-v3/include/bits/stl_vector.h
===================================================================
--- libstdc++-v3/include/bits/stl_vector.h	(revision 139583)
+++ libstdc++-v3/include/bits/stl_vector.h	(working copy)
@@ -78,9 +78,9 @@
       struct _Vector_impl 
       : public _Tp_alloc_type
       {
-	_Tp*           _M_start;
-	_Tp*           _M_finish;
-	_Tp*           _M_end_of_storage;
+	typename _Tp_alloc_type::pointer  _M_start;
+	typename _Tp_alloc_type::pointer  _M_finish;
+	typename _Tp_alloc_type::pointer  _M_end_of_storage;
 
 	_Vector_impl()
 	: _Tp_alloc_type(), _M_start(0), _M_finish(0), _M_end_of_storage(0)
@@ -140,12 +140,12 @@
     public:
       _Vector_impl _M_impl;
 
-      _Tp*
+      typename _Tp_alloc_type::pointer
       _M_allocate(size_t __n)
       { return __n != 0 ? _M_impl.allocate(__n) : 0; }
 
       void
-      _M_deallocate(_Tp* __p, size_t __n)
+      _M_deallocate(typename _Tp_alloc_type::pointer __p, size_t __n)
       {
 	if (__p)
 	  _M_impl.deallocate(__p, __n);
@@ -1104,7 +1104,7 @@
         _M_insert_dispatch(iterator __pos, _InputIterator __first,
 			   _InputIterator __last, __false_type)
         {
-	  typedef typename std::iterator_traits<_InputIterator>::
+         typedef typename std::iterator_traits<_InputIterator>::
 	    iterator_category _IterCategory;
 	  _M_range_insert(__pos, __first, __last, _IterCategory());
 	}
Index: libstdc++-v3/include/Makefile.am
===================================================================
--- libstdc++-v3/include/Makefile.am	(revision 139583)
+++ libstdc++-v3/include/Makefile.am	(working copy)
@@ -480,6 +480,7 @@
 	${ext_srcdir}/atomicity.h \
 	${ext_srcdir}/array_allocator.h \
 	${ext_srcdir}/bitmap_allocator.h \
+	${ext_srcdir}/cast.h \
 	${ext_srcdir}/codecvt_specializations.h \
 	${ext_srcdir}/concurrence.h \
 	${ext_srcdir}/debug_allocator.h \
@@ -492,9 +493,11 @@
 	${ext_srcdir}/memory \
 	${ext_srcdir}/mt_allocator.h \
 	${ext_srcdir}/new_allocator.h \
+	${ext_srcdir}/nonstd_allocator.h \
 	${ext_srcdir}/numeric \
 	${ext_srcdir}/numeric_traits.h \
 	${ext_srcdir}/pod_char_traits.h \
+	${ext_srcdir}/pointer.h \
 	${ext_srcdir}/pool_allocator.h \
 	${ext_srcdir}/rb_tree \
 	${ext_srcdir}/rope \
Index: libstdc++-v3/testsuite/ext/nonstd_pointer/1.cc
===================================================================
--- libstdc++-v3/testsuite/ext/nonstd_pointer/1.cc	(revision 0)
+++ libstdc++-v3/testsuite/ext/nonstd_pointer/1.cc	(revision 0)
@@ -0,0 +1,172 @@
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <ext/pointer.h>
+
+using __gcc_cxx::_Pointer_adapter;
+using __gcc_cxx::_Relative_pointer_impl;
+using __gcc_cxx::static_pointer_cast;
+using __gcc_cxx::const_pointer_cast;
+
+
+void 
+test01() {
+
+  typedef _Pointer_adapter<_Relative_pointer_impl<int> >       pointer;
+  typedef _Pointer_adapter<_Relative_pointer_impl<const int> > const_pointer;
+
+  int A[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+
+  // basic pointer assignment/access tests.
+  pointer x = &A[0];
+  VERIFY( *x == 0 );
+  VERIFY( std::equal( x, x+10, A ) ); 
+  pointer y ( &A[9] );
+  VERIFY( *y == 9 );
+
+  // assignability
+  pointer z(x);
+  VERIFY(z==x);
+  VERIFY(*z == 0);
+
+  z = y;
+  VERIFY(z==y);
+  VERIFY(z!=x);
+  VERIFY(z>x);
+  VERIFY(*z == 9);
+  
+  // pointer arithmetic
+  VERIFY( *++x == 1 );
+  VERIFY( *--x == 0 );
+  VERIFY( *(x++) == 0 );
+  VERIFY( *(x--) == 1 );
+  VERIFY( *(x+2) == 2 );
+  VERIFY( *(2+x) == 2 );
+  VERIFY( *(y-2) == 7 );
+  VERIFY( y - x == 9 );
+  VERIFY( &*y - x == 9 );
+  VERIFY( y - &*x == 9 );
+  
+  size_t s( y - x );
+  VERIFY( s == 9 );
+}
+
+
+struct A {
+    mutable int i;
+};
+struct B : public A{
+    mutable int j;
+};
+typedef _Pointer_adapter<_Relative_pointer_impl<B> > B_pointer; 
+typedef _Pointer_adapter<_Relative_pointer_impl<const B> > const_B_pointer; 
+typedef _Pointer_adapter<_Relative_pointer_impl<A> > A_pointer; 
+typedef _Pointer_adapter<_Relative_pointer_impl<const A> > const_A_pointer; 
+
+
+// Test implicit conversion from B* to A*
+void inc( _Pointer_adapter<_Relative_pointer_impl<A> > a ) {
+    a->i++;
+}
+// Test implicit conversion from B* to const B*
+void inc2( _Pointer_adapter<_Relative_pointer_impl<const B> > b ) {
+    b->i++;
+    b->j++;
+}
+// Test implicit conversion from B* to const A*
+void inc3( _Pointer_adapter<_Relative_pointer_impl<const A> > a ) {
+    a->i++;
+}
+
+void test02( ) {
+    B b;
+    b.i = 2;
+    b.j = 2;
+
+    B_pointer Bptr( &b );
+    VERIFY( Bptr->i == 2 );
+    Bptr->i++;
+    VERIFY( b.i == 3 );
+    
+    const_B_pointer cBptr( &b );
+    b.i++;
+    VERIFY( cBptr->i == 4 );
+    
+    A_pointer Aptr( &b );
+    b.i++;
+    VERIFY(Aptr->i == 5);
+    Aptr->i++;
+    VERIFY( b.i == 6 );
+    
+    const_A_pointer cAptr( &b );
+    b.i++;
+    VERIFY( cAptr->i == 7 );
+
+    const_B_pointer cBptr2( Bptr );
+    b.i++;
+    VERIFY( cBptr2->i == 8 );
+    
+    A_pointer Aptr2( Bptr );
+    b.i++;
+    VERIFY(Aptr2->i == 9);
+    Aptr2->i++;
+    VERIFY( b.i == 10 );
+
+    const_A_pointer cAptr2( Bptr );
+    b.i++;
+    VERIFY( cAptr2->i == 11 );
+
+    // Implicit casting during invocation
+    inc( Bptr );
+    VERIFY( Bptr->i == 12 );
+    inc2( Bptr );
+    VERIFY( Bptr->i == 13 );
+    VERIFY( Bptr->j == 3 );
+    inc3( Bptr );
+    VERIFY( Bptr->i == 14 );
+}
+
+void test03( ) {
+
+    B b;
+    B *Bptr = &b;
+    A *aPtr = static_cast<A*>( Bptr );
+    const A *caPtr = static_cast<const A*>( Bptr /*implicit cast to const B * ? */ );
+    const B *cbPtr = static_cast<const B*>( Bptr );
+
+    B_pointer Bptr2 = &b;
+
+    const A* caPtr2 = static_pointer_cast<const A*>( Bptr2 );
+    A * aPtr2 = static_pointer_cast<A*>( Bptr2 );
+    const B* cbPtr2 = const_pointer_cast<const B*>( Bptr2 );
+
+    const_A_pointer caPtr3 = static_pointer_cast<const A*>( Bptr2 );
+    A_pointer aPtr3 = static_pointer_cast<A*>( Bptr2 );
+    const_B_pointer cbPtr3 = const_pointer_cast<const B*>( Bptr2 );
+}
+
+// Confirm the usability of the static_pointer_cast<> template function
+// to transform between _Pointer_adapter and standard versions.
+void test04() {
+    B b;
+    B_pointer bPtr = &b;
+
+    A_pointer aPtr = static_pointer_cast<A_pointer>( bPtr );
+    VERIFY( aPtr == bPtr );
+    B_pointer bPtr2 = static_pointer_cast<B_pointer>( aPtr );
+    VERIFY( bPtr2 == aPtr );
+
+    A* aPtr3 = static_pointer_cast<A*>( bPtr );
+    VERIFY( aPtr3 == bPtr );
+    B* bPtr3 = static_pointer_cast<B*>( aPtr );
+    VERIFY( bPtr3 == aPtr );
+}
+
+int main()
+{
+  test01();
+  test02();
+  test03();
+  test04();
+  return 0;
+}
Index: libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/modifiers/erase.cc
===================================================================
--- libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/modifiers/erase.cc	(revision 0)
+++ libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/modifiers/erase.cc	(revision 0)
@@ -0,0 +1,143 @@
+// 2005-11-02  Paolo Carlini  <pcarlini@suse.de>
+
+// Copyright (C) 2005 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, 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.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 23.2.4.3 vector modifiers
+
+#include <vector>
+#include <testsuite_hooks.h>
+#include <ext/nonstd_allocator.h>
+
+const int  A[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
+const int A1[] = {0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
+const int A2[] = {0, 2, 3, 4, 10, 11, 12, 13, 14, 15};
+const int A3[] = {0, 2, 3, 4, 10, 11};
+const int A4[] = {4, 10, 11};
+const int A5[] = {4, 10};
+const unsigned int  N = sizeof(A)  / sizeof(int);
+const unsigned int N1 = sizeof(A1) / sizeof(int);
+const unsigned int N2 = sizeof(A2) / sizeof(int);
+const unsigned int N3 = sizeof(A3) / sizeof(int);
+const unsigned int N4 = sizeof(A4) / sizeof(int);
+const unsigned int N5 = sizeof(A5) / sizeof(int);
+
+void
+test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  typedef std::vector<int,__gcc_cxx::_NonStd_allocator<int> >  vec_type;
+  typedef vec_type::iterator iterator_type;
+
+  vec_type v(A, A + N);
+  std::cout << v.size() << std::endl;
+  std::cout << v.capacity() << std::endl;
+  std::cout << v.max_size() << std::endl;
+
+  iterator_type it1 = v.erase(v.begin() + 1);
+  VERIFY( it1 == v.begin() + 1 );
+  std::cout << N << std::endl << v.size() << std::endl;
+  VERIFY( v.size() == N1 );
+  VERIFY( std::equal(v.begin(), v.end(), A1) );
+  
+  iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9);
+  VERIFY( it2 == v.begin() + 4 );
+  VERIFY( v.size() == N2 );
+  VERIFY( std::equal(v.begin(), v.end(), A2) );
+  
+  iterator_type it3 = v.erase(v.begin() + 6, v.end());
+  VERIFY( it3 == v.begin() + 6 );
+  VERIFY( v.size() == N3 );
+  VERIFY( std::equal(v.begin(), v.end(), A3) );
+
+  iterator_type it4 = v.erase(v.begin(), v.begin() + 3);
+  VERIFY( it4 == v.begin() );
+  VERIFY( v.size() == N4 );
+  VERIFY( std::equal(v.begin(), v.end(), A4) );
+
+  iterator_type it5 = v.erase(v.begin() + 2);
+  VERIFY( it5 == v.begin() + 2 );
+  VERIFY( v.size() == N5 );
+  VERIFY( std::equal(v.begin(), v.end(), A5) );
+
+  iterator_type it6 = v.erase(v.begin(), v.end());
+  VERIFY( it6 == v.begin() );
+  VERIFY( v.empty() );
+}
+
+void
+test02()
+{
+  bool test __attribute__((unused)) = true;
+
+  typedef __gcc_cxx::_NonStd_allocator<int> int_alloc_type;
+  typedef __gcc_cxx::_NonStd_allocator< std::vector<int, int_alloc_type> > vec_alloc_type;
+  typedef std::vector<std::vector<int, int_alloc_type >,vec_alloc_type>  vec_type; 
+  typedef vec_type::iterator          iterator_type;
+
+  vec_type v, v1, v2, v3, v4, v5;
+  for (unsigned int i = 0; i < N; ++i)
+    v.push_back(std::vector<int,int_alloc_type>(1, A[i]));
+  for (unsigned int i = 0; i < N1; ++i)
+    v1.push_back(std::vector<int,int_alloc_type>(1, A1[i]));
+  for (unsigned int i = 0; i < N2; ++i)
+    v2.push_back(std::vector<int,int_alloc_type>(1, A2[i]));
+  for (unsigned int i = 0; i < N3; ++i)
+    v3.push_back(std::vector<int,int_alloc_type>(1, A3[i]));
+  for (unsigned int i = 0; i < N4; ++i)
+    v4.push_back(std::vector<int,int_alloc_type>(1, A4[i]));
+  for (unsigned int i = 0; i < N5; ++i)
+    v5.push_back(std::vector<int,int_alloc_type>(1, A5[i]));
+  
+  iterator_type it1 = v.erase(v.begin() + 1);
+  VERIFY( it1 == v.begin() + 1 );
+  VERIFY( v.size() == N1 );
+  VERIFY( std::equal(v.begin(), v.end(), v1.begin()) );
+  
+  iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9);
+  VERIFY( it2 == v.begin() + 4 );
+  VERIFY( v.size() == N2 );
+  VERIFY( std::equal(v.begin(), v.end(), v2.begin()) );
+  
+  iterator_type it3 = v.erase(v.begin() + 6, v.end());
+  VERIFY( it3 == v.begin() + 6 );
+  VERIFY( v.size() == N3 );
+  VERIFY( std::equal(v.begin(), v.end(), v3.begin()) );
+
+  iterator_type it4 = v.erase(v.begin(), v.begin() + 3);
+  VERIFY( it4 == v.begin() );
+  VERIFY( v.size() == N4 );
+  VERIFY( std::equal(v.begin(), v.end(), v4.begin()) );
+
+  iterator_type it5 = v.erase(v.begin() + 2);
+  VERIFY( it5 == v.begin() + 2 );
+  VERIFY( v.size() == N5 );
+  VERIFY( std::equal(v.begin(), v.end(), v5.begin()) );
+
+  iterator_type it6 = v.erase(v.begin(), v.end());
+  VERIFY( it6 == v.begin() );
+  VERIFY( v.empty() );
+}
+
+int main()
+{
+  test01();
+  test02();
+  return 0;
+}
Index: libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/modifiers/insert.cc
===================================================================
--- libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/modifiers/insert.cc	(revision 0)
+++ libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/modifiers/insert.cc	(revision 0)
@@ -0,0 +1,49 @@
+
+#include <vector>
+#include <testsuite_hooks.h>
+#include <ext/nonstd_allocator.h>
+#include <stdexcept>
+
+// libstdc++/23578
+void test01() 
+{ 
+	bool test __attribute__((unused)) = true;
+
+	__gcc_cxx::_NonStd_allocator<int> alloc;
+	std::vector<int, __gcc_cxx::_NonStd_allocator<int> > iv(alloc);
+	VERIFY( iv.get_allocator() == alloc );
+	VERIFY( iv.size() == 0 );
+	
+	int A[] = { 0, 1, 2, 3, 4 };
+	int B[] = { 5, 5, 5, 5, 5 };
+	int C[] = { 6, 7 };
+	iv.insert(iv.end(), A, A+5 );
+	VERIFY( iv.size() == 5 );
+	iv.insert(iv.begin(), 5, 5 );
+	iv.insert(iv.begin()+5, 7);
+	iv.insert(iv.begin()+5, 6);
+	VERIFY( std::equal(iv.begin(), iv.begin()+5, B ));
+	VERIFY( std::equal(iv.begin()+5, iv.begin()+7, C));
+	VERIFY( std::equal(iv.begin()+7, iv.end(), A));
+	VERIFY( iv.size() == 12 );
+
+	try
+	  {
+	    iv.insert(iv.end(), iv.max_size() + 1, 1);
+	  }
+	catch(std::length_error&)
+	  {
+	    VERIFY( true );
+	  }
+	catch(...)
+	  {
+	    VERIFY( false );
+	  }
+
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
Index: libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/modifiers/element.cc
===================================================================
--- libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/modifiers/element.cc	(revision 0)
+++ libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/modifiers/element.cc	(revision 0)
@@ -0,0 +1,57 @@
+
+#include <vector>
+#include <testsuite_hooks.h>
+#include <ext/nonstd_allocator.h>
+
+// General tests element access and manipulation
+void test01() 
+{
+	bool test __attribute__((unused)) = true;
+
+	int A[] = { 0, 1, 2, 3, 4 };
+	__gcc_cxx::_NonStd_allocator<int> alloc;
+	std::vector<int,__gcc_cxx::_NonStd_allocator<int> > mv( A, A+5, alloc );
+
+	VERIFY( mv.size() == 5 );
+	VERIFY( mv.front() == 0 );
+	VERIFY( mv.back() == 4 );
+	VERIFY( mv.at(2) == 2 );
+	VERIFY( mv[3] == 3);
+	mv.front() = 5;
+	mv.back() = 6;
+	mv.at(2) = 7;
+	mv[3] = 8;
+	VERIFY( mv.size() == 5 );
+	VERIFY( mv.front() == 5 );
+	VERIFY( mv.back() == 6 );
+	VERIFY( mv.at(2) == 7 );
+	VERIFY( mv[3] == 8 );
+
+	try 
+	  {
+		mv.at(100) = 8;
+	  }
+	catch(std::out_of_range&)
+	  {
+	    VERIFY( true );
+	  }
+	catch(...)
+	  {
+	    VERIFY( false );
+	  }
+	
+	const std::vector<int,__gcc_cxx::_NonStd_allocator<int> > cmv( mv );
+	VERIFY( cmv.get_allocator() == mv.get_allocator() );
+	VERIFY( mv.size() == 5 );
+	VERIFY( mv.front() == 5 );
+	VERIFY( mv.back() == 6 );
+	VERIFY( mv.at(2) == 7 );
+	VERIFY( mv[3] == 8 );	
+}
+
+
+int main()
+{
+  test01();
+  return 0;
+}
Index: libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/citerators.cc
===================================================================
--- libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/citerators.cc	(revision 0)
+++ libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/citerators.cc	(revision 0)
@@ -0,0 +1,56 @@
+// { dg-options "-std=gnu++0x" }
+
+// 2007-10-15  Paolo Carlini  <pcarlini@suse.de>
+
+// Copyright (C) 2007 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 2, 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.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+#include <vector>
+#include <testsuite_hooks.h>
+#include <ext/nonstd_allocator.h>
+
+// Ensures equivalence of iterators based on low-level comparison
+// between const / non-const Pointer types.
+void
+test01()
+{
+  bool test __attribute__((unused)) = true;
+
+  std::vector<int, __gcc_cxx::_NonStd_allocator<int> > v(7);
+  VERIFY( v.cbegin() == v.begin() );
+  VERIFY( v.cend() == v.end() );
+  VERIFY( v.crbegin() == v.rbegin() );
+  VERIFY( v.crend() == v.rend() );
+  VERIFY( v.cbegin() != v.cend() );
+  VERIFY( v.crbegin() != v.crend() );  
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
Index: libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/types/1.cc
===================================================================
--- libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/types/1.cc	(revision 0)
+++ libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/types/1.cc	(revision 0)
@@ -0,0 +1,62 @@
+// 2005-12-01  Paolo Carlini  <pcarlini@suse.de>
+
+// Copyright (C) 2005 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, 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.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// { dg-do compile }
+
+// This is a copy of vector/types/1.cc with altered allocator.
+// The operator+()s in this test initially failed the test -
+// they stress the accurate recognition, by the compiler,
+// of _Pointer_adapter's own pointer arithmetic functions,
+// which have to match perfectly on the int type to get
+// chosen by the compiler when it sees: nonstd_pointer + int, etc.
+
+#include <vector>
+#include <ext/nonstd_allocator.h>
+
+namespace N
+{
+  struct X { };
+
+  template<typename T>
+    X operator+(T, std::size_t)
+    { return X(); }
+
+  template<typename T>
+    X operator-(T, T)
+    { return X(); }
+}
+
+int main()
+{
+  std::vector<N::X, __gcc_cxx::_NonStd_allocator<N::X> > v(5);
+  const std::vector<N::X, __gcc_cxx::_NonStd_allocator<N::X> > w(1);
+
+  v[0];
+  w[0];
+  v.size();
+  v.capacity();
+  v.resize(1);
+  v.insert(v.begin(), N::X());
+  v.insert(v.begin(), 1, N::X());
+  v.insert(v.begin(), w.begin(), w.end());
+  v = w;
+
+  return 0;
+}
Index: libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/explicit_instantiation/1.cc
===================================================================
--- libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/explicit_instantiation/1.cc	(revision 0)
+++ libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/explicit_instantiation/1.cc	(revision 0)
@@ -0,0 +1,35 @@
+// Copyright (C) 2004 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 2, 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.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+// This file tests explicit instantiation of library containers
+
+#include <vector>
+#include <ext/nonstd_allocator.h>
+
+// { dg-do compile }
+
+template class std::vector<int, __gcc_cxx::_NonStd_allocator<int> >;
Index: libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/explicit_instantiation/3.cc
===================================================================
--- libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/explicit_instantiation/3.cc	(revision 0)
+++ libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/explicit_instantiation/3.cc	(revision 0)
@@ -0,0 +1,36 @@
+// Copyright (C) 2005 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, 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.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+// This file tests explicit instantiation of library containers
+
+#include <vector>
+#include <ext/nonstd_allocator.h>
+
+// { dg-do compile }
+
+// libstdc++/21770
+template class std::vector<int, __gcc_cxx::_NonStd_allocator<char> >;
Index: libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/resize.cc
===================================================================
--- libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/resize.cc	(revision 0)
+++ libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/resize.cc	(revision 0)
@@ -0,0 +1,69 @@
+// 1999-05-07
+// bkoz 
+
+// Copyright (C) 1999, 2002, 2003, 2004, 2005
+// Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, 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.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 23.2.4.2 vector capacity
+
+#include <vector>
+#include <stdexcept>
+#include <testsuite_allocator.h>
+#include <testsuite_hooks.h>
+#include <ext/nonstd_allocator.h>
+
+
+void test01()
+{
+  // non POD types
+  bool test __attribute__((unused)) = true;
+  
+  std::vector<int, __gcc_cxx::_NonStd_allocator<int> > vec01;
+  typedef std::vector<int, __gcc_cxx::_NonStd_allocator<int> >::size_type size_type;
+
+  VERIFY ( vec01.empty() );
+
+  const int A[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };    
+
+  // Test resize of the vector based on reserve
+  size_type sz01 = vec01.capacity();
+  vec01.reserve(100);
+  size_type sz02 = vec01.capacity();
+  VERIFY( sz02 >= sz01 );
+
+  // grow/shrink
+  vec01.assign( A, A+10 );
+  sz01 = vec01.size() + 100;
+  vec01.resize(sz01);
+  sz02 = vec01.size();
+  VERIFY( sz01 == sz02 );
+  VERIFY(std::equal(vec01.begin(), vec01.begin()+10, A));
+  
+  sz01 = vec01.size() - 100;
+  vec01.resize(sz01);
+  sz02 = vec01.size();
+  VERIFY( sz01 == sz02 );
+  VERIFY(std::equal(vec01.begin(), vec01.end(), A));
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
Index: libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/data_access.cc
===================================================================
--- libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/data_access.cc	(revision 0)
+++ libstdc++-v3/testsuite/23_containers/vector/nonstd_pointer/data_access.cc	(revision 0)
@@ -0,0 +1,52 @@
+// 2005-08-29  Paolo Carlini  <pcarlini@suse.de>
+//
+// Copyright (C) 2005 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, 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.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+#include <vector>
+#include <testsuite_hooks.h>
+#include <ext/nonstd_allocator.h>
+
+// libstdc++/23578
+void test01() 
+{ 
+  bool test __attribute__((unused)) = true;
+  typedef std::vector<int, __gcc_cxx::_NonStd_allocator<int> > vector_type;
+
+  {
+    const int A[] = { 0, 1, 2, 3, 4 };    
+    vector_type v(A, A + 5);
+    VERIFY( v.data() == &v.front() );
+    int* pi = &* v.data();
+    VERIFY( *pi == 0 );
+  }
+
+  {
+    const int A[] = { 4, 3, 2, 1, 0 };    
+    const vector_type cv(A, A + 5);
+    VERIFY( cv.data() == &cv.front() );
+    const int* pci = &* cv.data();
+    VERIFY( *pci == 4 );
+  }
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
