mardi 6 janvier 2015

Exception guarrantees vs 2013 push_back

Is there bug in VS2013 STL implementation because in following code when vector reallocate object it use move constructor instead copy constructor? I try on gcc 4.8 and it works as I expected. When I add noexpect to move constructor program produce the same output(use move constructor when reallocation make place).



#include <iostream>
#include <vector>

using namespace std;

class Movable {
private:
std::string name;
public:
Movable() {

}

Movable(const Movable& other) {
name = other.name;
std::cout << "Copy constructor Movable" << std::endl;
}

Movable(Movable&& other) /*noexcept*/ {
std::cout << "Move constructor Movable" << std::endl;
name = std::move(other.name);
}
};

int main() {
std::vector<Movable> vec;
Movable moved;
for (int i = 0; i < 10; i++) {
vec.push_back(moved);
}
}

Aucun commentaire:

Enregistrer un commentaire