Skip to content

Instantly share code, notes, and snippets.

@parsa
Created February 20, 2018 16:36
Show Gist options
  • Select an option

  • Save parsa/b5d4c6ba3884180805c0770208eeae15 to your computer and use it in GitHub Desktop.

Select an option

Save parsa/b5d4c6ba3884180805c0770208eeae15 to your computer and use it in GitHub Desktop.
Move Semantics Demo
#include <utility>
struct A {};
struct B {};
void f(B&& b) {} // rvalue ref
void f(B const& b) {} // const lvalue ref
void f1(B b) {}
template <typename T>
void f2(T&& t) { }
template <typename T>
void f3(T&& t)
{
f2(std::forward<T>(t));
}
int main()
{
{
B b;
f(b);
f(std::move(b));
}
{
B b;
f1(b);
f1(std::move(b));
}
{
B b;
f3(b);
f3(std::move(b));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment