Proposal for std::vector.

Dhruv Matani dhruvbird@gmx.net
Sat Feb 7 04:17:00 GMT 2004


On Sat, 2004-02-07 at 00:26, Matt Austern wrote:
> On Feb 6, 2004, at 4:51 AM, Dhruv Matani wrote:
> 
> > The relevant discussion can be found by searching google for:
> > About std::vector and standard containers in general.
> >
> >
> > Wierd as it may seem, are standard containers such as std::vector
> > allowed
> > to derive from std::allocator, or more generally from an allocator
> > class?
> >
> > Mainly used to make use of EBO in case of an empty allocator such as
> > new_allocator and malloc_allocator.
> >
> >
> >
> > I liked a solution that one poster mentioned about having an IMPL class
> > within vector. So something like this:
> >
> >
> > template <T, A>
> > class vector {
> >    template <_A>
> >    struct IMPL : public _A {
> >       _M_start, _M_finish, etc...
> >    };
> > };
> >
> >
> > What do you think about it? Can it be merged with the library?
> 
> Right now, in our implementation, the standard containers *do*
> inherit from allocators.  I can't think of any reason why it would
> be prohibited.  It's only prohibited if it would cause some
> conforming program to fail, and I can't think of any.
> 
> Your IMPL technique would work too, but it's more complicated
> and I don't really see much benefit to justify the extra work.
> What do you see as the advantages?

I have here these 2 test programs. One of them tries to emulate the
vector (vtest.cpp), and the other one actually uses the vector. Now, the
emulation produces (IMHO) correct output, but the one that uses the
vector does not. I may be missing something somewhere, but I don't know
where! I've basically tried to introduce a virtual clear() in the
allocator and then call it in the deallocate function, but somehow the
Allocator's clear() is being called instead of the vector's clear?




-- 
	-Dhruv Matani.
http://www.geocities.com/dhruvbird/


-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtest.cpp
Type: text/x-c++
Size: 403 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20040207/b86e266c/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: alloc_opt.cpp
Type: text/x-c++
Size: 1231 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20040207/b86e266c/attachment-0001.bin>


More information about the Libstdc++ mailing list