#include<memory>#include<cstdio>int fopen_s(std::FILE** f, constchar* name, constchar* mode);
struct fclose_deleter {voidoperator()(std::FILE* f)constnoexcept{
std::fclose(f);
}};
int main(int, char*[]){constexprconstchar* file_name ="ow.o";
std::unique_ptr<std::FILE, fclose_deleter> file_ptr;
int err = fopen_s(std::out_ptr<std::FILE*>(file_ptr), file_name, "r+b");
if(err !=0)return1;
// *file_ptr is validreturn0;
}unique_ptr can be used with out_ptr
to be passed into an output pointer-style function,
without needing to hold onto an intermediate pointer value and
manually delete it on error or failure.
It is typically a user error to reset a shared_ptr
without specifying a deleter,
as shared_ptr will replace a custom deleter upon usage of reset,
as specified in [util.smartptr.shared.mod].
any modification of *v
that is not followed by a subsequent modification of *this
affects the value of p during the destruction of *this,
such that static_cast<void*>(p)==*v.