This question is made while I answer this another question.
N3337 23.3.6.3 "vector capacity" says (it's in 770 page):
void resize(size_type sz);
Effects: If
sz <= size()
, equivalent toerase(begin() + sz, end());
. Ifsize() < sz
, appendssz - size()
value-initialized elements to the sequence.Requires: T shall be CopyInsertable into *this.
However, clang++ says it's okay though T is not copyable. And I think it makes sense that resize(size_type)
requires only destroyable/moveable/default constructable. It destroys if sz <= size
, appends (which uses default constructing, and destroying and moving if the capacity is not enough) if size() < sz
.
What is truth? Is it a standard defect? Or is it a mistake of both clang++ and me?
You are correct. It was a defect in C++11 that was fixed for C++14 by http://cplusplus.github.io/LWG/lwg-defects.html#2033
The current wording says:
The requirement on
Destructible
is in Table 95 and applies to all operations on all containers, not justresize()
.