Skip to content

Instantly share code, notes, and snippets.

@Grumbel
Created January 9, 2019 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Grumbel/0b633d3c86d82270779d5458ed2c8785 to your computer and use it in GitHub Desktop.
Save Grumbel/0b633d3c86d82270779d5458ed2c8785 to your computer and use it in GitHub Desktop.
#include <vector>
#include <iostream>
class Foo
{
public:
std::vector<int> m_value;
Foo() : m_value(10) {}
std::vector<int> get_value() { return std::move(m_value); }
std::vector<int>&& move_value() { return std::move(m_value); }
};
int main()
{
Foo foo;
std::vector<int> value = foo.get_value();
Foo foo2;
foo2.move_value().resize(5); // Bad
std::vector<int> value2 = foo2.move_value();
std::cout << value.size() << std::endl;
std::cout << value2.size() << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment