lundi 26 septembre 2016

Do implicit move methods always preserve fundamental data?

It's my understanding that when a basic data type is moved from, it will always perform a copy.
For example, you can never move from an int, and have the original int value unspecified:

#include <iostream>

int main() {

    int x = 100;
    int y{std::move(x)};
    std::cout << x << " " << y; //always prints "100 100"

}

Does this mean that the same is true for basic data types inside user-defined types?

#include <iostream>
#include <vector>

struct Foo{
    int i = 100;
    std::vector<int> vec={1,2,3,4,5}; //something that probably will have an invariant
};

int main() {

    Foo x;
    Foo y{std::move(x)};
    std::cout << x.i << " " << y.i; //always print "100 100"?

}

What does the standard say about retaining these fundamental type values after a move?

Aucun commentaire:

Enregistrer un commentaire