1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| #include <iostream> #include <memory>
using namespace std;
template<typename T> using deleted_unique_ptr = std::unique_ptr<T, std::function<void(T *)>>;
int main(int argc, char *argv[]) { deleted_unique_ptr<FILE> file(fopen("test", "w"), [](FILE * f) { cout << __PRETTY_FUNCTION__ << endl; fclose(f); }); fputs("Hello world", file.get());
return 0; }
|