Created
December 16, 2015 08:44
-
-
Save LihuaWu/db741a1a4db31c75c901 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
#include <iostream> | |
#include <utility> | |
#include <memory> | |
using namespace std; | |
int main() { | |
std::unique_ptr<int> upi(new int(5)); | |
cout << *upi << "\n"; | |
// won't compile | |
// auto func = [](std::unique_ptr<int> u) { cout << "*upi is: " << *u << "\n"; }; | |
// func(upi); | |
auto func = bind([](const std::unique_ptr<int>& u) { | |
cout << "*upi is: " << *u << "\n"; | |
}, | |
move(upi) | |
); | |
func(upi); | |
cout << (upi ? "Valid pointer. " : "null pointer.") << "\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment