This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
_ExtPtr_allocator
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Bob Walters <bob dot s dot walters at gmail dot com>
- Cc: "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Fri, 10 Jun 2011 22:06:21 +0100
- Subject: _ExtPtr_allocator
Hi Bob, hi list,
A couple of weeks ago I updated the various allocators in libstdc++ to
use the C++0x API, specifically construct and destroy are template
functions taking the type to construct/destroy as a template
parameter:
template<typename _Up, typename... _Args>
void
construct(_Up* __p, _Args&&... __args);
template<typename _Up>
void
destroy(_Up* __p);
(See http://gcc.gnu.org/ml/libstdc++-cvs/2011-q2/msg00190.html for
that change and
http://gcc.gnu.org/ml/libstdc++-cvs/2011-q2/msg00214.html for a later
change to specialize std::pointer_traits<_Pointer_adapter<T>>)
For most allocators where Alloc<T>::pointer is just T* that's a
backward-compatible change, but for ExtPtr_allocator it's not, the
allocator's pointer type is not convertible to a built-in pointer.
I'm not familiar enough with the use cases for relative pointers so I
don't know if this API change breaks the sort of code using the
allocator.
Does code using this allocator actually pass the 'pointer' type to
construct() and destroy()?
Or does it pass raw pointers, which with the old API would implicitly
convert to the allocator's 'pointer' type?
If my change breaks the allocator I see two simple fixes:
* revert the change, so ExtPtr_allocator only supports the C++03 API.
That will still work in C++0x code because allocators should be used
via allocator_traits which provides default implementations if the
allocator doesn't provide the new template signatures.
* 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.