Implementation of forward_list (and compressed_pair)
Ion Gaztañaga
igaztanaga@gmail.com
Mon Oct 13 20:56:00 GMT 2008
Ed Smith-Rowland wrote:
> Greetings,
>
> Here is an implementation of forward_list and a supporting utility,
> compressed_pair, that might be used in other containers.
>
> The compressed pair is used to implement a pairs of allocators - one
> outer for the list node and one inner one for the type object. This
> mirrors proposals on scoped allocator. Otherwise, the implementation is
> similar to ext/slist and std::list in many respects.
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)...){}
//...
};
Regards,
Ion
More information about the Libstdc++
mailing list