This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: _ExtPtr_allocator
- From: Bob Walters <bob dot s dot walters at gmail dot com>
- To: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- Cc: "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Mon, 20 Jun 2011 23:25:51 -0400
- Subject: Re: _ExtPtr_allocator
- References: <BANLkTikX2DtQ=vyd9uqh6dMm+9SLY0djFA@mail.gmail.com>
Jonathan,
Sorry for this very delayed response.
On Fri, Jun 10, 2011 at 5:06 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> Does code using this allocator actually pass the 'pointer' type to
> construct() and destroy()?
Yes. When a container supports non-standard pointer types, it would
infer the internal pointer types from Alloc<T>::pointer, and
associated rebinds. Thus it would expect to be able to pass
Alloc<T>::pointer to the allocator.
> If my change breaks the allocator I see two simple fixes:
>
> * overload construct and destroy so both the old- and new-style
> signatures are present.
>
> ? ? ?template<typename... _Args>
> ? ? ? ?void
> ? ? ? ?construct(pointer __p, _Args&&... __args)
> ? ? ? ?{ construct(__p.get(), std::forward<_Args>(__args)...); }
>
> ? ? ?void destroy(pointer __p)
> ? ? ?{ destroy(__p.get()); }
>
> I'd appreciate some advice from people familiar with this code as I
> don't know it well enough or have time to study it properly right now.
I wonder if the following might help: The __Pointer_Adapter has
associated code and macros in ext/cast.h which are meant to allow code
to be written without concern for whether the pointer typedef is a
standard pointer or some class. This would allow methods like:
template<typename _Uptr, typename... _Args>
void
construct( _Uptr __p, _Args&&... __args) {
::new( __gnu_cxx::__static_pointer_cast<void*>(__p)) typename
pointer_traits<_Uptr>::element_type( forward<Args>(args)... );
}
That works (I think) for _Uptr being a standard or non-standard
pointer type, so long as any pointer class provides a working override
for the ext/cast.h functions, which was proposed as one of the
'requirements' of any non-standard pointer that is used with libstdc++
containers. i.e. The cast functions provided a way for the containers
to be written without concern for pointer types. The convention was
that the container just had to use the pointer typedef for storage and
the __pointer_cast methods in place of standard casts. This avoids
that __p.get() in the code, and the need for overrides.
- Bob