Re: [allocator.concept] smart pointer clarifications
"Phil Bouchard" <phil@fornux.com> wrote in message
news:g8jofb$ust$1@aioe.org...
[...]
Where:
template <typename T>
virtual allocator_type list_base<T>::get_allocator() const = 0;
And, for example:
template <typename T, typename Alloc>
virtual allocator_type list<T, Alloc>::get_allocator() const
{
return allocator_type(*static_cast<const
_Node_Alloc_type*>(&this->_M_impl));
}
Sorry here I meant protected functions should be virtual, not
get_allocator():
template <typename T>
class list_base : public ...
{
virtual _List_node<_Tp>* _M_get_node() = 0;
virtual void _M_put_node(_List_node<_Tp>* __p) = 0;
};
template <typename T, typename Alloc>
class list : public list_base<T>
{
protected:
_List_impl _M_impl;
virtual _List_node<_Tp>* _M_get_node()
{
return _M_impl._Node_Alloc_type::allocate(1);
}
virtual void _M_put_node(_List_node<_Tp>* __p)
{
_M_impl._Node_Alloc_type::deallocate(__p, 1);
}
public:
_Alloc get_allocator() const
{
return _Alloc(*static_cast<const
_Node_Alloc_type*>(&this->_M_impl));
}
...
};
-Phil
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]