I want to ensure that I properly understand this. I ask it here since it I have not fund it spelled out explicitly.
For example I have a triangle mesh class that is basically built like this:
class Mesh { public: struct Face { unsigned int a; unsigned int b; unsigned int c; }; //... private: std::string file; std::vector<glm::vec3> vertices; std::vector<glm::vec3> normals; std::vector<glm::vec2> texcoord; std::vector<Face> faces; } Since the data in the mesh can get quite large I want to implement proper move semantics. For pointer types I fully understand this, but to trigger the rvalue constructor I need to use move, right?
For example the rvalue constructor will be:
Mesh::Mesh(Mesh&& other) : file(std::move(other.file)), vertices(std::move(other.vertices)), normals(std::move(other.normals)), texcoord(std::move(other.texcoord)), faces(std::move(other.faces) {} Note: Before someone points out the obvious, the application uses in many places a share_ptr. But I don't want to artificially restrict the use of the class.
vectoritself is moved, this means that the elements are not copied or moved at all.std::vectorwill just transfer the internal buffer ownership. Sure, they would benefit from it for when the vectors are resized, but it's not necessary forMesh's own move ctor.