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)
Paolo Carlini wrote:
> 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).
>
To wit, this kind of patch appear to work well for std::list.
Paolo.
///////////////
Index: include/bits/stl_list.h
===================================================================
*** include/bits/stl_list.h (revision 141104)
--- include/bits/stl_list.h (working copy)
*************** _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GL
*** 101,106 ****
--- 101,112 ----
{
///< User's data.
_Tp _M_data;
+
+ #ifdef __GXX_EXPERIMENTAL_CXX0X__
+ template<typename... _Args>
+ _List_node(_Args&&... __args)
+ : _List_node_base(), _M_data(std::forward<_Args>(__args)...) { }
+ #endif
};
/**
*************** _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GL
*** 478,485 ****
_Node* __p = this->_M_get_node();
try
{
! _M_get_Tp_allocator().construct(&__p->_M_data,
! std::forward<_Args>(__args)...);
}
catch(...)
{
--- 484,491 ----
_Node* __p = this->_M_get_node();
try
{
! _M_get_Node_allocator().construct(__p,
! std::forward<_Args>(__args)...);
}
catch(...)
{
*************** _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GL
*** 1423,1429 ****
{
__position._M_node->unhook();
_Node* __n = static_cast<_Node*>(__position._M_node);
! _M_get_Tp_allocator().destroy(&__n->_M_data);
_M_put_node(__n);
}
--- 1429,1439 ----
{
__position._M_node->unhook();
_Node* __n = static_cast<_Node*>(__position._M_node);
! #ifdef __GXX_EXPERIMENTAL_CXX0X__
! _M_get_Node_allocator().destroy(__n);
! #else
! _M_get_Tp_allocator().destroy(&__n->_M_data);
! #endif
_M_put_node(__n);
}
Index: include/bits/list.tcc
===================================================================
*** include/bits/list.tcc (revision 141104)
--- include/bits/list.tcc (working copy)
*************** _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GL
*** 75,81 ****
--- 75,85 ----
{
_Node* __tmp = __cur;
__cur = static_cast<_Node*>(__cur->_M_next);
+ #ifdef __GXX_EXPERIMENTAL_CXX0X__
+ _M_get_Node_allocator().destroy(__tmp);
+ #else
_M_get_Tp_allocator().destroy(&__tmp->_M_data);
+ #endif
_M_put_node(__tmp);
}
}