C++11 - a good example of RAII by using unique_ptr

less than 1 minute read

1
2
3
4
5
6
class FileDeleter {
void operator()(FILE* fp) { fclose(fp); }
};
unique_ptr<FILE, FileDeleter> fp = fopen("blah");
or even
unique_ptr<FILE, int(*)(FILE*)> fp( fopen("blah"), fclose)