Skip to content

Instantly share code, notes, and snippets.

@npalko
Last active October 11, 2015 12:57
Show Gist options
  • Select an option

  • Save npalko/3862224 to your computer and use it in GitHub Desktop.

Select an option

Save npalko/3862224 to your computer and use it in GitHub Desktop.
file handles should dispose themselves
typedef std::unique_ptr<std::FILE, int (*)(std::FILE *)> unique_fp;
unique_fp(std::fopen(filename, flags), std::fclose);
unique_ptr<std::FILE, decltype(&std::fclose)> p_file (
std::fopen("easy.binary", "wb"), std::fclose);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment