mirror of
https://github.com/boostorg/core.git
synced 2025-11-28 13:29:19 +01:00
Added fclose_deleter.
fclose_deleter can be used as a deleter function object for std::FILE pointers returned by std::fopen.
This commit is contained in:
@@ -60,6 +60,7 @@ criteria for inclusion is that the utility component be:
|
||||
[include noinit_adaptor.qbk]
|
||||
[include noncopyable.qbk]
|
||||
[include null_deleter.qbk]
|
||||
[include fclose_deleter.qbk]
|
||||
[include nvp.qbk]
|
||||
[include pointer_traits.qbk]
|
||||
[include quick_exit.qbk]
|
||||
|
||||
34
doc/fclose_deleter.qbk
Normal file
34
doc/fclose_deleter.qbk
Normal file
@@ -0,0 +1,34 @@
|
||||
[/
|
||||
/ Copyright (c) 2022 Andrey Semashev
|
||||
/
|
||||
/ Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
/ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
/]
|
||||
|
||||
[section:fclose_deleter fclose_deleter]
|
||||
|
||||
[simplesect Authors]
|
||||
|
||||
* Andrey Semashev
|
||||
|
||||
[endsimplesect]
|
||||
|
||||
[section Header <boost/core/fclose_deleter.hpp>]
|
||||
|
||||
The header `<boost/core/fclose_deleter.hpp>` defines the `boost::fclose_deleter` function object,
|
||||
which can be used as a deleter with smart pointers such as `unique_ptr` or `shared_ptr` pointing to `std::FILE`.
|
||||
structures returned by `std::fopen` calls. The deleter calls `std::fclose` on the passed pointer, causing
|
||||
the file stream to be flushed and closed.
|
||||
|
||||
[section Example]
|
||||
``
|
||||
std::unique_ptr< std::FILE, boost::fclose_deleter > make_file(const char* filename, const char* open_mode)
|
||||
{
|
||||
return { std::fopen(filename, open_mode) };
|
||||
}
|
||||
``
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
Reference in New Issue
Block a user