Created
February 5, 2013 19:57
-
-
Save acmorrow/4717129 to your computer and use it in GitHub Desktop.
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
// C++11 offers a built-in "owning" pointer which allows transfer of ownership | |
// and manages lifetime but disallows copying. There is no runtime overhead for its use: | |
std::unique_ptr<socket> connect_to(const std::string& host, int port) { | |
/// ... | |
return new socket(fd); | |
} | |
{ | |
auto connected = connect_to("www.10gen.com", 80); | |
connected->send("GET HTTP/1.1 index.html"); | |
} // socket is automatically destroyed here. | |
auto connected = connect_to("www.mongodb.org", 80); | |
auto copy_of_connected = connected; // NOPE, won't compile, would alias | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment