This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Implementation of forward_list (and compressed_pair)
- From: Paolo Carlini <paolo dot carlini at oracle dot com>
- To: Ion Gaztañaga <igaztanaga at gmail dot com>
- Cc: libstdc++ at gcc dot gnu dot org, Ed Smith-Rowland <3dw4rd at verizon dot net>
- Date: Tue, 14 Oct 2008 10:08:25 +0200
- Subject: Re: Implementation of forward_list (and compressed_pair)
- References: <48F0EE6E.3000409@verizon.net> <48F3B5DF.3030309@gmail.com>
Ion Gaztañaga wrote:
> Just a comment. Why do you need to store two allocators? This will
> increase the size of the list for stateful allocators (after all
> forward list has no size() to save space) and now that we have
> variadic construct() in allocators, we can just store the node
> allocator and construct the node using a new constructor for the node:
>
> struct _Fwd_list_node : public _Fwd_list_node_base
> {
> template<class ...Args>
> _Fwd_list_node(Args && args)
> : _Fwd_list_node_base(), _M_value(std::forward<Args>(args)...){}
> //...
> };
Ah! I think this is right! And, I must say, I'm "guilty" of having
sidetracked Ed to the issue of having a pair of allocators stored for
efficiency. Now I see that indeed thanks to the new variadic
allocator::construct one can construct in place using the same node
allocator (provided one adds an appropriate constructor for the node as
you are doing above).
So... We are learning something: after all, the experimental C++0x mode
is here also for that reason! Ed, do you want to play with the above?
Paolo.