-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unusual shared_ptr use in copy_file #66
Comments
You are right, this isn't the best place to use this pattern because of the When reworking that code base into a So yeah, it works, but I should clean that up. And a PR for that will be gladly integrated, as I'm currently quite busy at my job. In any way, thanks for looking through it! I'm always thankful for input to make this library a better piece of helpful software. |
Thanks for the explanation! I understand, libraries like this often have colourful histories. I'll gladly have a look into this and draft a PR when I have some free time. |
Rework released with v1.3.4 |
The
copy_file
function usesshared_ptr
as a RAII wrapper aroundclose
through a custom deleter.filesystem/include/ghc/filesystem.hpp
Line 3510 in 3f1c185
filesystem/include/ghc/filesystem.hpp
Line 3519 in 3f1c185
It seems like this code is using
shared_ptr
as a mechanism for RAII.shared_ptr
isn't necessarily free: it will likely allocate storage for the lamdas and their captures because it has to type erase the custom deleter internally. I find it confusing to seeshared_ptr
used this way. This is not really its intended use, so the intent of the code wasn't really clear on my first read.I don't see why RAII is advantageous here: it would make sense if any of the functions called in
copy_file
could throw, because the destructor would ensureclose
is called. However, the function isnoexcept
. If anything throws in here, the application will be terminated anyway.This is just something I noticed while I was digging around the source. I could submit a PR addressing these comments if you agree with them. Otherwise, I'd be really interested to hear why the code is written like this.
Cheers!
The text was updated successfully, but these errors were encountered: