Redefinition of vector<T, Alloc> ::erase(iterator).

Supporting Design by Contract in C++
by David Maley and Ivor Spence
Listing 7. Redefinition of vector<T, Alloc> ::erase(iterator).


iterator stdpp::vector<T>::erase(iterator pos)
{
  if (!size() || pos<begin() || pos>=end() ||
!pre_erase(pos))
    throw vector<T>();
  vector<T> old(*this);
  iterator newPos = std::vector<T>::erase(pos);
  if (!post_erase(old, newPos) || !inv())
    throw vector<T>();
  return newPos;
}

About the Authors

David Maley is with St. Mary's University College, Belfast. He can be contacted at [email protected].

Ivor Spence is with Queen's University of Belfast. He can be contacted at [email protected].