newprogrammer newprogrammer - 3 months ago 48
C++ Question

Default move constructor Visual Studio 2015

There seems to be conflicting documentation as to whether Visual Studio 2015 supports generation of default move constructors.

This link and this link seem say to no, whereas this link says yes.

I tried something simple:

class Test {
Test(int data) : data(data) {}
Test(Test&& other) = default;
Test(Test& other) = delete;
int data;

int main() {
Test c(3);
std::cout << << std::endl;
Test b(std::move(c));
std::cout << << std::endl;

It prints out 3 and 3 as expected. Am I making some mistake or is the default move constructor actually being generated?

Edit: Removed "implicit" wording


The move constructor is being generated. It just happens that moving an int is achieved by copying (setting the "moved" object to some other value would be more expensive than just leaving it as is.)

You could test this by using a verbose movable type as data member instead of an int.