Commit 8d8a4e9d by Paolo Carlini Committed by Paolo Carlini

extptr_allocator.h: Minor tweaks.

2008-11-11  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/ext/extptr_allocator.h: Minor tweaks.
	* include/ext/pointer.h: Likewise.
	* include/ext/cast.h: Likewise.

From-SVN: r141764
parent ddb47467
2008-11-11 Paolo Carlini <paolo.carlini@oracle.com>
* include/ext/extptr_allocator.h: Minor tweaks.
* include/ext/pointer.h: Likewise.
* include/ext/cast.h: Likewise.
2008-11-10 Paolo Carlini <paolo.carlini@oracle.com> 2008-11-10 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/38067 PR libstdc++/38067
......
...@@ -27,8 +27,8 @@ ...@@ -27,8 +27,8 @@
// invalidate any other reasons why the executable file might be covered by // invalidate any other reasons why the executable file might be covered by
// the GNU General Public License. // the GNU General Public License.
#ifndef _EXT_CAST_ #ifndef _CAST_H
#define _EXT_CAST_ 1 #define _CAST_H 1
_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx); _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx);
...@@ -48,14 +48,11 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx); ...@@ -48,14 +48,11 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx);
*/ */
template<typename _ToType> template<typename _ToType>
struct _Caster struct _Caster
{ { typedef typename _ToType::element_type* type; };
typedef typename _ToType::element_type* type;
};
template<typename _ToType> template<typename _ToType>
struct _Caster<_ToType*> struct _Caster<_ToType*>
{ { typedef _ToType* type; };
typedef _ToType* type;
};
/** /**
* Casting operations for cases where _FromType is not a standard pointer. * Casting operations for cases where _FromType is not a standard pointer.
...@@ -118,4 +115,4 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx); ...@@ -118,4 +115,4 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx);
_GLIBCXX_END_NAMESPACE _GLIBCXX_END_NAMESPACE
#endif #endif // _CAST_H
...@@ -43,51 +43,26 @@ ...@@ -43,51 +43,26 @@
#include <limits> #include <limits>
#include <ext/pointer.h> #include <ext/pointer.h>
using __gnu_cxx::_Pointer_adapter;
using __gnu_cxx::_Relative_pointer_impl;
_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
// forward declaration
template<typename _Tp>
class _ExtPtr_allocator;
// _ExtPtr_allocator<void> specialization.
template<>
class _ExtPtr_allocator<void>
{
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef void value_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;
template<typename _Up>
struct rebind
{ typedef _ExtPtr_allocator<_Up> other; };
};
/** /**
* @brief An example allocator which uses a non-standard pointer type. * @brief An example allocator which uses a non-standard pointer type.
* *
* This allocator specifies that containers use a 'relative pointer' as it's * This allocator specifies that containers use a 'relative pointer' as it's
* pointer type. (See bits/pointer.h) Memory allocation in this example * pointer type. (See ext/pointer.h) Memory allocation in this example
* is still performed using std::allocator. * is still performed using std::allocator.
*/ */
template<typename _Tp> template<typename _Tp>
class _ExtPtr_allocator class _ExtPtr_allocator
{ {
public: public:
typedef size_t size_type; typedef std::size_t size_type;
typedef ptrdiff_t difference_type; typedef std::ptrdiff_t difference_type;
// Note the non-standard pointer types. // Note the non-standard pointer types.
typedef _Pointer_adapter<_Relative_pointer_impl<_Tp> > pointer; typedef _Pointer_adapter<_Relative_pointer_impl<_Tp> > pointer;
typedef _Pointer_adapter<_Relative_pointer_impl<const _Tp> > const_pointer; typedef _Pointer_adapter<_Relative_pointer_impl<const _Tp> >
const_pointer;
typedef _Tp& reference; typedef _Tp& reference;
typedef const _Tp& const_reference; typedef const _Tp& const_reference;
...@@ -103,7 +78,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) ...@@ -103,7 +78,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
_ExtPtr_allocator(const _ExtPtr_allocator &__rarg) throw() _ExtPtr_allocator(const _ExtPtr_allocator &__rarg) throw()
: _M_real_alloc(__rarg._M_real_alloc) { } : _M_real_alloc(__rarg._M_real_alloc) { }
template<class _Up> template<typename _Up>
_ExtPtr_allocator(const _ExtPtr_allocator<_Up>& __rarg) throw() _ExtPtr_allocator(const _ExtPtr_allocator<_Up>& __rarg) throw()
: _M_real_alloc(__rarg._M_getUnderlyingImp()) { } : _M_real_alloc(__rarg._M_getUnderlyingImp()) { }
...@@ -158,7 +133,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) ...@@ -158,7 +133,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
template<typename _Up> template<typename _Up>
inline friend void inline friend void
swap(_ExtPtr_allocator<_Up>& __larg, _ExtPtr_allocator<_Up>& __rarg); swap(_ExtPtr_allocator<_Up>&, _ExtPtr_allocator<_Up>&);
// A method specific to this implementation. // A method specific to this implementation.
const std::allocator<_Tp>& const std::allocator<_Tp>&
...@@ -166,17 +141,38 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) ...@@ -166,17 +141,38 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
{ return _M_real_alloc; } { return _M_real_alloc; }
private: private:
// simlated state data.
std::allocator<_Tp> _M_real_alloc; std::allocator<_Tp> _M_real_alloc;
}; };
// _ExtPtr_allocator<void> specialization.
template<>
class _ExtPtr_allocator<void>
{
public:
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef void value_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;
template<typename _Up>
struct rebind
{ typedef _ExtPtr_allocator<_Up> other; };
private:
std::allocator<void> _M_real_alloc;
};
template<typename _Tp> template<typename _Tp>
inline void inline void
swap(_ExtPtr_allocator<_Tp>& __larg, _ExtPtr_allocator<_Tp>& __rarg) swap(_ExtPtr_allocator<_Tp>& __larg, _ExtPtr_allocator<_Tp>& __rarg)
{ {
std::allocator<_Tp> temp( __rarg._M_real_alloc ); std::allocator<_Tp> __tmp( __rarg._M_real_alloc );
__rarg._M_real_alloc = __larg._M_real_alloc; __rarg._M_real_alloc = __larg._M_real_alloc;
__larg._M_real_alloc = temp; __larg._M_real_alloc = __tmp;
} }
_GLIBCXX_END_NAMESPACE _GLIBCXX_END_NAMESPACE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment