boostorg / core

Boost Core Utilities
133 stars 83 forks source link

Add fclose_deleter #128

Closed Lastique closed 2 years ago

Lastique commented 2 years ago

fclose_deleter can be used as a deleter function object for std::FILE pointers returned by std::fopen.

pdimov commented 2 years ago

I'm not quite sure this belongs here, even though we do have null_deleter. Which probably doesn't belong here either.

Lastique commented 2 years ago

Should I revert?

pdimov commented 2 years ago

Utility seems a better place for fclose_deleter, but having null_deleter here and fclose_deleter there wouldn't be particularly consistent. So maybe not.

You have to check p for NULL though. unique_ptr skips the deleter on NULL, but shared_ptr does not. And you should probably have a test where fopen returns NULL. Maybe test with boost::shared_ptr too.

Lastique commented 2 years ago

You have to check p for NULL though. unique_ptr skips the deleter on NULL, but shared_ptr does not.

Hmm, I thought shared_ptr also didn't call the deleter on NULL. Will fix, thanks.