Category: C++

Move semantics vs Copy semantics; And when to use them.

#include <vector> #include <iostream> class Semantics { public: // Pass by value to store a new copy using std::move // (rvalue is moved, lvalue is copied) Semantics(std::vector<int> in) : m_v(std::move(in)) { } std::vector<int> get() const { return m_v; } // Pass by reference to modify an `out` parameter: lvalue only void append(std::vector<int> &out) { out.insert(out.end(),…

Read the full article