Created
March 9, 2014 21:58
-
-
Save kalman5/9455397 to your computer and use it in GitHub Desktop.
Avoid the Copy
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
| class JumboFactory { | |
| ... | |
| Jumbo getJumboByCopy() const & { | |
| //Deep copy | |
| return theJumboObject; | |
| } | |
| Jumbo getJumboByCopy() && { // *this is an r-value | |
| //Move | |
| return std::move(theJumboObject); | |
| } | |
| ... | |
| private: | |
| Jumbo theJumboObject; | |
| }; | |
| JumboFactory myJF; | |
| Jumbo myJumboA = myJF.getJumboByCopy(); // Deep copy | |
| Jumbo myJumboB = JumboFactory().getJumboByCopy(); // Move |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment