Connecting Tech Pros Worldwide Help | Site Map

implementing remove in std::allocator

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 22nd, 2005, 09:52 PM
ScOe
Guest
 
Posts: n/a
Default implementing remove in std::allocator

I've made a container class over std::allocator. Also implement create,
clear, push_back
but i need some assistance on removing item from container.

do i need to create empty container and than use push_back on all items
except item i want to delete or is there
any smoother way to do that ?

would this do the job ?
template <typename T> void TVecArray<T>::remove (iterator i)
{
alloc.destroy (i);
alloc.deallocate (i, 1);
}

implemented code (from accelerated c++):
std::allocator<T> alloc;
void push_back(const T& t){
if (avail == limit)
grow ();
unchecked_append (t);
}
template <typename T> void TVecArray<T>::grow ()
{
size_type new_size = max (2 * (limit - data), ptrdiff_t(1));
iterator new_data = alloc.allocate (new_size);
iterator new_avail = std::uninitialized_copy (data, avail, new_data);
uncreate ();
data = new_data;
avail = new_avail;
limit = data + new_size;
}
template <typename T> void TVecArray<T>::unchecked_append (const T& val)
{
alloc.construct (avail++, val);
}





 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.