Skip to content

Instantly share code, notes, and snippets.

@yhliaoluan
Created August 24, 2014 12:39
Show Gist options
  • Save yhliaoluan/7d938282127abbf560a9 to your computer and use it in GitHub Desktop.
Save yhliaoluan/7d938282127abbf560a9 to your computer and use it in GitHub Desktop.
Auto clean resource using unique_ptr
int auto_clean() {
SOCKET socket = socket(AF_INET, SOCK_STREAM, 0);
unique_ptr<SOCKET, void (*)(SOCKET *)> ac(&socket,
[](SOCKET *s) { closesocket(*s); });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment