* [v3] Small tweaks to ext/cast.h & co
@ 2008-11-11 13:08 Paolo Carlini
0 siblings, 0 replies; only message in thread
From: Paolo Carlini @ 2008-11-11 13:08 UTC (permalink / raw)
To: Gcc Patch List; +Cc: libstdc++
[-- Attachment #1: Type: text/plain, Size: 77 bytes --]
Hi,
tested x86_64-linux, committed to mainline.
Paolo.
//////////////////
[-- Attachment #2: CL --]
[-- Type: text/plain, Size: 173 bytes --]
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.
[-- Attachment #3: patchlet --]
[-- Type: text/plain, Size: 28401 bytes --]
Index: include/ext/cast.h
===================================================================
*** include/ext/cast.h (revision 141739)
--- include/ext/cast.h (working copy)
***************
*** 27,34 ****
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
! #ifndef _EXT_CAST_
! #define _EXT_CAST_ 1
_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx);
--- 27,34 ----
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
! #ifndef _CAST_H
! #define _CAST_H 1
_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx);
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx);
*** 48,61 ****
*/
template<typename _ToType>
struct _Caster
! {
! typedef typename _ToType::element_type* type;
! };
template<typename _ToType>
struct _Caster<_ToType*>
! {
! typedef _ToType* type;
! };
/**
* Casting operations for cases where _FromType is not a standard pointer.
--- 48,58 ----
*/
template<typename _ToType>
struct _Caster
! { typedef typename _ToType::element_type* type; };
!
template<typename _ToType>
struct _Caster<_ToType*>
! { typedef _ToType* type; };
/**
* Casting operations for cases where _FromType is not a standard pointer.
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx);
*** 118,121 ****
_GLIBCXX_END_NAMESPACE
! #endif
--- 115,118 ----
_GLIBCXX_END_NAMESPACE
! #endif // _CAST_H
Index: include/ext/pointer.h
===================================================================
*** include/ext/pointer.h (revision 141739)
--- include/ext/pointer.h (working copy)
***************
*** 1,7 ****
// Custom pointer adapter and sample storage policies
! // 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
--- 1,6 ----
// Custom pointer adapter and sample storage policies
! // 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
***************
*** 33,55 ****
* @author Bob Walters
*
* Provides reusable _Pointer_adapter 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 _EXT_POINTER_ADAPTER
! #define _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(__gnu_cxx)
--- 32,47 ----
* @author Bob Walters
*
* Provides reusable _Pointer_adapter for assisting in the development of
! * custom pointer types that can be used with the standard containers via
* the allocator::pointer and allocator::const_pointer typedefs.
*/
! #ifndef _POINTER_H
! #define _POINTER_H 1
! #include <iosfwd>
! #include <bits/stl_iterator_base_types.h>
#include <ext/cast.h>
_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 64,78 ****
* 4) An operator<() to support pointer comparison.
* 5) An operator==() to support pointer comparison.
*/
! template<typename _Type>
class _Std_pointer_impl
{
public:
// the type this pointer points to.
! typedef _Type element_type;
// A method to fetch the pointer value as a standard T* value;
! inline _Type*
get() const
{ return _M_value; }
--- 56,70 ----
* 4) An operator<() to support pointer comparison.
* 5) An operator==() to support pointer comparison.
*/
! template<typename _Tp>
class _Std_pointer_impl
{
public:
// the type this pointer points to.
! typedef _Tp element_type;
// A method to fetch the pointer value as a standard T* value;
! inline _Tp*
get() const
{ return _M_value; }
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 94,100 ****
element_type* _M_value;
};
-
/**
* @brief A storage policy for use with _Pointer_adapter<> which stores
* the pointer's address as an offset value which is relative to
--- 86,91 ----
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 108,134 ****
* As there is no reason why any normal pointer would point 1 byte into
* its own pointer address.
*/
! template<typename _Type>
class _Relative_pointer_impl
{
public:
! typedef _Type element_type;
! _Type*
get() const
{
if (_M_diff == 1)
! return NULL;
else
! return reinterpret_cast<_Type*>(
const_cast<char*>(reinterpret_cast<const char*>(this))
+ _M_diff);
}
void
! set(_Type* __arg)
{
! if (__arg == NULL)
_M_diff = 1;
else
_M_diff = reinterpret_cast<char*>(__arg)
--- 99,125 ----
* As there is no reason why any normal pointer would point 1 byte into
* its own pointer address.
*/
! template<typename _Tp>
class _Relative_pointer_impl
{
public:
! typedef _Tp element_type;
! _Tp*
get() const
{
if (_M_diff == 1)
! return 0;
else
! return reinterpret_cast<_Tp*>(
const_cast<char*>(reinterpret_cast<const char*>(this))
+ _M_diff);
}
void
! set(_Tp* __arg)
{
! if (!__arg)
_M_diff = 1;
else
_M_diff = reinterpret_cast<char*>(__arg)
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 145,177 ****
{ return (this->get() == __rarg.get()); }
private:
! ptrdiff_t _M_diff;
};
/**
* Relative_pointer_impl needs a specialization for const T because of
* the casting done during pointer arithmetic.
*/
! template<typename _Type>
! class _Relative_pointer_impl<const _Type>
{
public:
! typedef const _Type element_type;
! const _Type*
get() const
{
if (_M_diff == 1)
! return NULL;
else
! return reinterpret_cast<const _Type*>(
(reinterpret_cast<const char*>(this)) + _M_diff);
}
void
! set(const _Type* __arg)
{
! if (__arg == NULL)
_M_diff = 1;
else
_M_diff = reinterpret_cast<const char*>(__arg)
--- 136,168 ----
{ return (this->get() == __rarg.get()); }
private:
! std::ptrdiff_t _M_diff;
};
/**
* Relative_pointer_impl needs a specialization for const T because of
* the casting done during pointer arithmetic.
*/
! template<typename _Tp>
! class _Relative_pointer_impl<const _Tp>
{
public:
! typedef const _Tp element_type;
! const _Tp*
get() const
{
if (_M_diff == 1)
! return 0;
else
! return reinterpret_cast<const _Tp*>(
(reinterpret_cast<const char*>(this)) + _M_diff);
}
void
! set(const _Tp* __arg)
{
! if (!__arg)
_M_diff = 1;
else
_M_diff = reinterpret_cast<const char*>(__arg)
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 188,197 ****
{ return (this->get() == __rarg.get()); }
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
--- 179,187 ----
{ return (this->get() == __rarg.get()); }
private:
! std::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
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 201,234 ****
template<typename _Tp>
struct _Reference_type
! {
! typedef _Tp& 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<>
--- 191,213 ----
template<typename _Tp>
struct _Reference_type
! { typedef _Tp& 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<>
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 236,270 ****
*/
template<typename _Tp>
struct _Unqualified_type
! {
! typedef _Tp type;
! };
template<typename _Tp>
struct _Unqualified_type<const _Tp>
! {
! typedef _Tp type;
! };
template<typename _Tp>
struct _Unqualified_type<volatile _Tp>
! {
! typedef volatile _Tp type;
! };
template<typename _Tp>
struct _Unqualified_type<volatile const _Tp>
! {
! typedef volatile _Tp type;
! };
!
!
/**
! * The following provides an 'alternative pointer' that works with
! * libstdc++-v3 containers when specified as the pointer typedef of the
! * allocator.
! *
* The pointer type used with the containers doesn't have to be this class,
* but it must support the implicit conversions, pointer arithmetic,
* comparison operators, etc. that are supported by this class, and avoid
--- 215,238 ----
*/
template<typename _Tp>
struct _Unqualified_type
! { typedef _Tp type; };
template<typename _Tp>
struct _Unqualified_type<const _Tp>
! { typedef _Tp type; };
template<typename _Tp>
struct _Unqualified_type<volatile _Tp>
! { typedef volatile _Tp type; };
template<typename _Tp>
struct _Unqualified_type<volatile const _Tp>
! { typedef volatile _Tp type; };
/**
! * The following provides an 'alternative pointer' that works with the
! * containers when specified as the pointer typedef of the allocator.
! *
* The pointer type used with the containers doesn't have to be this class,
* but it must support the implicit conversions, pointer arithmetic,
* comparison operators, etc. that are supported by this class, and avoid
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 290,339 ****
* _Tp* const == const _Pointer_adapter<_Std_pointer_impl<_Tp> >;
* const _Tp* const == const _Pointer_adapter<_Std_pointer_impl<const _Tp> >;
*/
!
! template<typename _Storage_policy >
class _Pointer_adapter : public _Storage_policy
{
public:
typedef typename _Storage_policy::element_type element_type;
!
// 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)
{ _Storage_policy::set(__arg); }
!
// Copy constructor from _Pointer_adapter of same type.
_Pointer_adapter(const _Pointer_adapter& __arg)
{ _Storage_policy::set(__arg.get()); }
!
// Convert from _Up* if conversion to element_type* is valid.
template<typename _Up>
! _Pointer_adapter(_Up*__arg)
! {
! __glibcxx_function_requires(_ConvertibleConcept<element_type*, _Up*>);
! _Storage_policy::set(__arg);
! }
!
// Conversion from another _Pointer_adapter if _Up if static cast is
// valid.
template<typename _Up>
_Pointer_adapter(const _Pointer_adapter<_Up>& __arg)
! {
! __glibcxx_function_requires(_ConvertibleConcept<element_type*,
! typename _Pointer_adapter<_Up>::element_type*>);
! _Storage_policy::set(__arg.get());
! }
!
// Destructor
~_Pointer_adapter() { }
--- 258,299 ----
* _Tp* const == const _Pointer_adapter<_Std_pointer_impl<_Tp> >;
* const _Tp* const == const _Pointer_adapter<_Std_pointer_impl<const _Tp> >;
*/
! template<typename _Storage_policy>
class _Pointer_adapter : public _Storage_policy
{
public:
typedef typename _Storage_policy::element_type element_type;
!
// These are needed for iterator_traits
typedef std::random_access_iterator_tag iterator_category;
typedef typename _Unqualified_type<element_type>::type value_type;
! typedef std::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 = 0)
{ _Storage_policy::set(__arg); }
!
// Copy constructor from _Pointer_adapter of same type.
_Pointer_adapter(const _Pointer_adapter& __arg)
{ _Storage_policy::set(__arg.get()); }
!
// Convert from _Up* if conversion to element_type* is valid.
template<typename _Up>
! _Pointer_adapter(_Up* __arg)
! { _Storage_policy::set(__arg); }
!
// Conversion from another _Pointer_adapter if _Up if static cast is
// valid.
template<typename _Up>
_Pointer_adapter(const _Pointer_adapter<_Up>& __arg)
! { _Storage_policy::set(__arg.get()); }
!
// Destructor
~_Pointer_adapter() { }
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 344,350 ****
_Storage_policy::set(__arg.get());
return *this;
}
!
template<typename _Up>
_Pointer_adapter&
operator=(const _Pointer_adapter<_Up>& __arg)
--- 304,310 ----
_Storage_policy::set(__arg.get());
return *this;
}
!
template<typename _Up>
_Pointer_adapter&
operator=(const _Pointer_adapter<_Up>& __arg)
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 365,381 ****
inline reference
operator*() const
{ return *(_Storage_policy::get()); }
!
// Operator->, returns element_type*
inline element_type*
operator->() const
{ return _Storage_policy::get(); }
!
// Operator[], returns a element_type& to the item at that loc.
! inline reference
! operator[](int __index) const
{ return _Storage_policy::get()[__index]; }
!
// To allow implicit conversion to "bool", for "if (ptr)..."
private:
typedef element_type*(_Pointer_adapter::*__unspecified_bool_type)() const;
--- 325,341 ----
inline reference
operator*() const
{ return *(_Storage_policy::get()); }
!
// Operator->, returns element_type*
inline element_type*
operator->() const
{ return _Storage_policy::get(); }
!
// Operator[], returns a element_type& to the item at that loc.
! inline reference
! operator[](std::ptrdiff_t __index) const
{ return _Storage_policy::get()[__index]; }
!
// To allow implicit conversion to "bool", for "if (ptr)..."
private:
typedef element_type*(_Pointer_adapter::*__unspecified_bool_type)() const;
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 388,396 ****
}
// ! operator (for: if (!ptr)...)
! inline bool
operator!() const
! { return (_Storage_policy::get()==NULL); }
// Pointer differences
inline friend std::ptrdiff_t
--- 348,356 ----
}
// ! operator (for: if (!ptr)...)
! inline bool
operator!() const
! { return (_Storage_policy::get() == 0); }
// Pointer differences
inline friend std::ptrdiff_t
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 401,412 ****
operator-(element_type* __lhs, const _Pointer_adapter& __rhs)
{ return (__lhs - __rhs.get()); }
! template<class _Up>
inline friend std::ptrdiff_t
operator-(const _Pointer_adapter& __lhs, _Up* __rhs)
{ return (__lhs.get() - __rhs); }
! template<class _Up>
inline friend std::ptrdiff_t
operator-(_Up* __lhs, const _Pointer_adapter& __rhs)
{ return (__lhs - __rhs.get()); }
--- 361,372 ----
operator-(element_type* __lhs, const _Pointer_adapter& __rhs)
{ return (__lhs - __rhs.get()); }
! template<typename _Up>
inline friend std::ptrdiff_t
operator-(const _Pointer_adapter& __lhs, _Up* __rhs)
{ return (__lhs.get() - __rhs); }
! template<typename _Up>
inline friend std::ptrdiff_t
operator-(_Up* __lhs, const _Pointer_adapter& __rhs)
{ return (__lhs - __rhs.get()); }
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 483,489 ****
}
inline _Pointer_adapter
! operator--(int __unused)
{
_Pointer_adapter tmp(*this);
_Storage_policy::set(_Storage_policy::get() - 1);
--- 443,449 ----
}
inline _Pointer_adapter
! operator--(int)
{
_Pointer_adapter tmp(*this);
_Storage_policy::set(_Storage_policy::get() - 1);
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 520,526 ****
_GCC_CXX_POINTER_COMPARISON_OPERATION_SET(>,);
_GCC_CXX_POINTER_COMPARISON_OPERATION_SET(>=,);
-
// These are here for expressions like "ptr == 0", "ptr != 0"
template<typename _Tp>
inline bool
--- 480,485 ----
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 551,592 ****
operator==(const _Pointer_adapter<_Tp>& __lhs,
const _Pointer_adapter<_Tp>& __rhs)
{ return __lhs._Tp::operator==(__rhs); }
!
template<typename _Tp>
inline bool
operator<=(const _Pointer_adapter<_Tp>& __lhs,
const _Pointer_adapter<_Tp>& __rhs)
{ return __lhs._Tp::operator<(__rhs) || __lhs._Tp::operator==(__rhs); }
!
template<typename _Tp>
inline bool
operator!=(const _Pointer_adapter<_Tp>& __lhs,
const _Pointer_adapter<_Tp>& __rhs)
{ return !(__lhs._Tp::operator==(__rhs)); }
!
template<typename _Tp>
inline bool
operator>(const _Pointer_adapter<_Tp>& __lhs,
const _Pointer_adapter<_Tp>& __rhs)
{ return !(__lhs._Tp::operator<(__rhs) || __lhs._Tp::operator==(__rhs)); }
!
template<typename _Tp>
inline bool
operator>=(const _Pointer_adapter<_Tp>& __lhs,
const _Pointer_adapter<_Tp>& __rhs)
{ return !(__lhs._Tp::operator<(__rhs)); }
!
!
! template<class _CharT, class _Traits, class _StoreT>
! std::basic_ostream<_CharT, _Traits>&
! operator<<(std::basic_ostream<_CharT, _Traits> &os,
const _Pointer_adapter<_StoreT>& __p)
! {
! os << __p.get();
! return os;
! }
-
_GLIBCXX_END_NAMESPACE
! #endif /* _GCC_EXT_POINTER_ADAPTER */
--- 510,546 ----
operator==(const _Pointer_adapter<_Tp>& __lhs,
const _Pointer_adapter<_Tp>& __rhs)
{ return __lhs._Tp::operator==(__rhs); }
!
template<typename _Tp>
inline bool
operator<=(const _Pointer_adapter<_Tp>& __lhs,
const _Pointer_adapter<_Tp>& __rhs)
{ return __lhs._Tp::operator<(__rhs) || __lhs._Tp::operator==(__rhs); }
!
template<typename _Tp>
inline bool
operator!=(const _Pointer_adapter<_Tp>& __lhs,
const _Pointer_adapter<_Tp>& __rhs)
{ return !(__lhs._Tp::operator==(__rhs)); }
!
template<typename _Tp>
inline bool
operator>(const _Pointer_adapter<_Tp>& __lhs,
const _Pointer_adapter<_Tp>& __rhs)
{ return !(__lhs._Tp::operator<(__rhs) || __lhs._Tp::operator==(__rhs)); }
!
template<typename _Tp>
inline bool
operator>=(const _Pointer_adapter<_Tp>& __lhs,
const _Pointer_adapter<_Tp>& __rhs)
{ return !(__lhs._Tp::operator<(__rhs)); }
!
! template<typename _CharT, typename _Traits, typename _StoreT>
! inline std::basic_ostream<_CharT, _Traits>&
! operator<<(std::basic_ostream<_CharT, _Traits>& __os,
const _Pointer_adapter<_StoreT>& __p)
! { return (__os << __p.get()); }
_GLIBCXX_END_NAMESPACE
! #endif // _POINTER_H
Index: include/ext/extptr_allocator.h
===================================================================
*** include/ext/extptr_allocator.h (revision 141739)
--- include/ext/extptr_allocator.h (working copy)
***************
*** 43,93 ****
#include <limits>
#include <ext/pointer.h>
- using __gnu_cxx::_Pointer_adapter;
- using __gnu_cxx::_Relative_pointer_impl;
-
_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.
*
* This allocator specifies that containers use a 'relative pointer' as it's
! * pointer type. (See bits/pointer.h) Memory allocation in this example
* is still performed using std::allocator.
*/
template<typename _Tp>
class _ExtPtr_allocator
{
public:
! typedef size_t size_type;
! typedef ptrdiff_t difference_type;
// Note the non-standard pointer types.
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;
--- 43,68 ----
#include <limits>
#include <ext/pointer.h>
_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
/**
* @brief An example allocator which uses a non-standard pointer type.
*
* This allocator specifies that containers use a 'relative pointer' as it's
! * pointer type. (See ext/pointer.h) Memory allocation in this example
* is still performed using std::allocator.
*/
template<typename _Tp>
class _ExtPtr_allocator
{
public:
! typedef std::size_t size_type;
! typedef std::ptrdiff_t difference_type;
// Note the non-standard pointer types.
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;
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 103,109 ****
_ExtPtr_allocator(const _ExtPtr_allocator &__rarg) throw()
: _M_real_alloc(__rarg._M_real_alloc) { }
! template<class _Up>
_ExtPtr_allocator(const _ExtPtr_allocator<_Up>& __rarg) throw()
: _M_real_alloc(__rarg._M_getUnderlyingImp()) { }
--- 78,84 ----
_ExtPtr_allocator(const _ExtPtr_allocator &__rarg) throw()
: _M_real_alloc(__rarg._M_real_alloc) { }
! template<typename _Up>
_ExtPtr_allocator(const _ExtPtr_allocator<_Up>& __rarg) throw()
: _M_real_alloc(__rarg._M_getUnderlyingImp()) { }
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 158,164 ****
template<typename _Up>
inline friend void
! swap(_ExtPtr_allocator<_Up>& __larg, _ExtPtr_allocator<_Up>& __rarg);
// A method specific to this implementation.
const std::allocator<_Tp>&
--- 133,139 ----
template<typename _Up>
inline friend void
! swap(_ExtPtr_allocator<_Up>&, _ExtPtr_allocator<_Up>&);
// A method specific to this implementation.
const std::allocator<_Tp>&
*************** _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
*** 166,182 ****
{ return _M_real_alloc; }
private:
- // simlated state data.
std::allocator<_Tp> _M_real_alloc;
};
template<typename _Tp>
inline void
swap(_ExtPtr_allocator<_Tp>& __larg, _ExtPtr_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
--- 141,178 ----
{ return _M_real_alloc; }
private:
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>
inline void
swap(_ExtPtr_allocator<_Tp>& __larg, _ExtPtr_allocator<_Tp>& __rarg)
{
! std::allocator<_Tp> __tmp( __rarg._M_real_alloc );
__rarg._M_real_alloc = __larg._M_real_alloc;
! __larg._M_real_alloc = __tmp;
}
_GLIBCXX_END_NAMESPACE
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-11-11 12:19 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-11 13:08 [v3] Small tweaks to ext/cast.h & co Paolo Carlini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).