Skip to content

Instantly share code, notes, and snippets.

@SHyx0rmZ
Created January 11, 2015 19:40
Show Gist options
  • Select an option

  • Save SHyx0rmZ/0d6744bf7278ea8ba4de to your computer and use it in GitHub Desktop.

Select an option

Save SHyx0rmZ/0d6744bf7278ea8ba4de to your computer and use it in GitHub Desktop.
namespace std {
template <>
struct default_delete<fstream> {
void operator()(fstream *ptr) {
if (ptr != nullptr && ptr->is_open()) {
ptr->close();
}
delete ptr;
}
};
template <>
struct default_delete<ifstream> {
void operator()(ifstream *ptr) {
if (ptr != nullptr && ptr->is_open()) {
ptr->close();
}
delete ptr;
}
};
template <>
struct default_delete<ofstream> {
void operator()(ofstream *ptr) {
if (ptr != nullptr && ptr->is_open()) {
ptr->close();
}
delete ptr;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment