I need to avoid the additional cost of copying and destructing the object contained by a std::vector caused by this answer.
Right now I'm using it as a std::vector of pointers, but I can't call std::vector::clear() without deleting each object before nor I can use std::auto_ptr with std containers.
I wanted to do something like this:
vector<MyClass> MyVec;
MyVec.push_back();
MyClass &item = MyVec.back();
This would create a new object with the default constructor and then I could get a reference and work with it.
Any ideas on this direction?
RESOLVED: I used @MSalters answer with @Moo-Juices suggestion to use C++0x rvalue references to take vantage of std::move semantics. Based on this article.