Skip to content

Instantly share code, notes, and snippets.

@cjxgm
Created March 3, 2015 12:04
Show Gist options
  • Save cjxgm/1a5aa60328efee00102c to your computer and use it in GitHub Desktop.
Save cjxgm/1a5aa60328efee00102c to your computer and use it in GitHub Desktop.
overload "+" for std::move
#include <utility>
#include <iostream>
using std::cout;
using std::endl;
// move-identity
template <class T> T&& operator+(T& x) { return std::move(x); }
struct foo
{
foo() = default;
foo(foo const&) { cout << "copy" << endl; }
foo(foo &&) { cout << "move" << endl; }
};
int main()
{
foo bar;
foo bay = bar;
foo baz = +bar;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment