Created
March 3, 2015 12:04
-
-
Save cjxgm/1a5aa60328efee00102c to your computer and use it in GitHub Desktop.
overload "+" for std::move
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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