This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Nonstandard allocator::pointer in containers


First, I believe that we already have stateful allocator support in
libstdc++, so that shouldn't be a problem.  That is: if you create a
container using a particular allocator instance then the container
will use a copy of that instance, not a default-constructed allocator,
for all allocations.  You can't necessarily mix two containers that
have the same allocator types but different allocator instances (you
can't splice from one list to another that has an incompatible
allocator instance, for example), but that's a different level of
support and I'm not convinced that it's necessary.
 
 But that's a digression from the question of using a a
my_allocator<T>::pointer that's something other than T*.
 
 My opinion on that question: I think a change along those lines would
probably be useful but difficult.  Just replacing T* by
_Alloc::pointer is almost certainly not enough. If _Alloc::pointer is
anything other than T*, things will probably break. I would be very
reluctant to see this change without some real design and
documentation work, which probably should include a paper written for
the C++ standards committee.
  
 The sticking point, and the reason why nobody has done this yet for
libstdc++, is that nobody has spelled out precisely what requirements
my_allocator<T>::pointer must satisfy. Is my_allocator::pointer
allowed to have a nontrivial copy constructor? Does it have to be a
POD?  Can you use const_cast to convert my_allocator::const_pointer to
my_allocator::pointer? Can you use static_cast to convert
my_allocator<void>::pointer to my_allocator<T>::pointer? If there's an
implicit conversion from D* to B*, does it necessarily follow that
there's an implicit conversion from my_allocator<D>::pointer to
my_allocator<B>::pointer?
  
  The existing containers make all sorts of assumptions about pointers
that are true for T* but that aren't likely to be true for arbitrary
user-defined types.  So the real work here is spelling out what
requirements a user-defined pointer-like type has to satisfy, and then
making sure that our container implementations work correctly for
every user-defined type that satisfies those requirements.  That's
hard.
 
                               --Matt


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]