I checked a lot of constructor / vector / movements without extra threads, but I'm still not sure what actually happens when something should go wrong. I cannot make a mistake when I expect, so either my little test is wrong or my understanding of the problem is wrong.
I use the BufferTrio object vector, which defines the noexcept (false) move constructor and removes every other constructor / assignment statement, so there is nothing to return to:
BufferTrio(const BufferTrio&) = delete; BufferTrio& operator=(const BufferTrio&) = delete; BufferTrio& operator=(BufferTrio&& other) = delete; BufferTrio(BufferTrio&& other) noexcept(false) : vaoID(other.vaoID) , vboID(other.vboID) , eboID(other.eboID) { other.vaoID = 0; other.vboID = 0; other.eboID = 0; }
Things are compiled and executed, but from https://xinhuang.imtqy.com/posts/2013-12-31-when-to-use-noexcept-and-when-to-not.html :
std :: vector will use relocation when it needs to increase (or decrease) capacity if the relocation operation is no exception.
Or from Optimized C ++: Proven Performance Improvement Techniques by Kurt Gunterot:
If the move constructor and move destination operator are not declared noexcept, std :: vector uses less efficient copy operations.
Since I deleted them, I understand that something must be broken here. But with this vector everything works fine. Therefore, I also created a base loop that push_backs half a million times a dummy vector, and then replaced this vector with another singleton dummy vector. For example:
vector<BufferTrio> thing; int n = 500000; while (n--) { thing.push_back(BufferTrio()); } vector<BufferTrio> thing2; thing2.push_back(BufferTrio()); thing.swap(thing2); cout << "Sizes are " << thing.size() << " and " << thing2.size() << endl; cout << "Capacities are " << thing.capacity() << " and " << thing2.capacity() << endl;
Output:
Sizes are 1 and 500000 Capacities are 1 and 699913
Still no problem, therefore:
Should I see something wrong, and if so, how can I demonstrate it?
c ++ constructor vector c ++ 11 move
Xenial
source share