Skip to content

Commit 10c7120

Browse files
authored
Merge 2023-06 LWG Motion 23
P1759R6 Native handles and file streams
2 parents 4fba140 + 05e617b commit 10c7120

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

source/iostreams.tex

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10837,6 +10837,26 @@
1083710837
These functions enable class \tcode{path} support for systems with a wide native path character type, such as \keyword{wchar_t}.
1083810838
\end{note}
1083910839

10840+
\rSec2[file.native]{Native handles}
10841+
10842+
\indexlibraryglobal{native_handle_type}%
10843+
10844+
\pnum
10845+
Several classes described in \ref{file.streams}
10846+
have a member \tcode{native_handle_type}.
10847+
10848+
\pnum
10849+
The type \tcode{native_handle_type} represents a platform-specific
10850+
\defnadj{native}{handle} to a file.
10851+
It is trivially copyable and models \libconcept{semiregular}.
10852+
10853+
\begin{note}
10854+
For operating systems based on POSIX,
10855+
\tcode{native_handle_type} is \keyword{int}.
10856+
For Windows-based operating systems,
10857+
\tcode{native_handle_type} is \tcode{HANDLE}.
10858+
\end{note}
10859+
1084010860
\rSec2[filebuf]{Class template \tcode{basic_filebuf}}
1084110861

1084210862
\rSec3[filebuf.general]{General}
@@ -10852,6 +10872,7 @@
1085210872
using pos_type = typename traits::pos_type;
1085310873
using off_type = typename traits::off_type;
1085410874
using traits_type = traits;
10875+
using native_handle_type = @\impdefx{type of \tcode{native_handle_type}}@; // see \ref{file.native}
1085510876

1085610877
// \ref{filebuf.cons}, constructors/destructor
1085710878
basic_filebuf();
@@ -10874,6 +10895,7 @@
1087410895
basic_filebuf* open(const filesystem::path& s,
1087510896
ios_base::openmode mode);
1087610897
basic_filebuf* close();
10898+
native_handle_type native_handle() const noexcept;
1087710899

1087810900
protected:
1087910901
// \ref{filebuf.virtuals}, overridden virtual functions
@@ -10933,6 +10955,18 @@
1093310955
\tcode{fpos<traits::\brk{}state_type>}.
1093410956
Otherwise the behavior is undefined.
1093510957

10958+
\pnum
10959+
The file associated with a \tcode{basic_filebuf} has
10960+
an associated value of type \tcode{native_handle_type},
10961+
called the native handle\iref{file.native} of that file.
10962+
This native handle can be obtained by calling
10963+
the member function \tcode{native_handle}.
10964+
10965+
\pnum
10966+
For any opened \tcode{basic_filebuf f},
10967+
the native handle returned by \tcode{f.native_handle()} is
10968+
invalidated when \tcode{f.close()} is called, or \tcode{f} is destroyed.
10969+
1093610970
\pnum
1093710971
In order to support file I/O and multibyte/wide character conversion,
1093810972
conversions are performed using members of a facet, referred to as
@@ -11226,6 +11260,21 @@
1122611260
on success, a null pointer otherwise.
1122711261
\end{itemdescr}
1122811262

11263+
\indexlibrarymember{native_handle}{basic_filebuf}%
11264+
\begin{itemdecl}
11265+
native_handle_type native_handle() const noexcept;
11266+
\end{itemdecl}
11267+
11268+
\begin{itemdescr}
11269+
\pnum
11270+
\expects
11271+
\tcode{is_open()} is \tcode{true}.
11272+
11273+
\pnum
11274+
\returns
11275+
The native handle associated with \tcode{*this}.
11276+
\end{itemdescr}
11277+
1122911278
\rSec3[filebuf.virtuals]{Overridden virtual functions}
1123011279

1123111280
\indexlibrarymember{showmanyc}{basic_filebuf}%
@@ -11624,6 +11673,7 @@
1162411673
using pos_type = typename traits::pos_type;
1162511674
using off_type = typename traits::off_type;
1162611675
using traits_type = traits;
11676+
using native_handle_type = typename basic_filebuf<charT, traits>::native_handle_type;
1162711677

1162811678
// \ref{ifstream.cons}, constructors
1162911679
basic_ifstream();
@@ -11646,6 +11696,7 @@
1164611696

1164711697
// \ref{ifstream.members}, members
1164811698
basic_filebuf<charT, traits>* rdbuf() const;
11699+
native_handle_type native_handle() const noexcept;
1164911700

1165011701
bool is_open() const;
1165111702
void open(const char* s, ios_base::openmode mode = ios_base::in);
@@ -11794,6 +11845,17 @@
1179411845
\tcode{const_cast<basic_filebuf<charT, traits>*>(addressof(sb))}.
1179511846
\end{itemdescr}
1179611847

11848+
\indexlibrarymember{native_handle}{basic_ifstream}%
11849+
\begin{itemdecl}
11850+
native_handle_type native_handle() const noexcept;
11851+
\end{itemdecl}
11852+
11853+
\begin{itemdescr}
11854+
\pnum
11855+
\effects
11856+
Equivalent to: \tcode{return rdbuf()->native_handle();}
11857+
\end{itemdescr}
11858+
1179711859
\indexlibrarymember{is_open}{basic_ifstream}%
1179811860
\begin{itemdecl}
1179911861
bool is_open() const;
@@ -11870,6 +11932,7 @@
1187011932
using pos_type = typename traits::pos_type;
1187111933
using off_type = typename traits::off_type;
1187211934
using traits_type = traits;
11935+
using native_handle_type = typename basic_filebuf<charT, traits>::native_handle_type;
1187311936

1187411937
// \ref{ofstream.cons}, constructors
1187511938
basic_ofstream();
@@ -11892,6 +11955,7 @@
1189211955

1189311956
// \ref{ofstream.members}, members
1189411957
basic_filebuf<charT, traits>* rdbuf() const;
11958+
native_handle_type native_handle() const noexcept;
1189511959

1189611960
bool is_open() const;
1189711961
void open(const char* s, ios_base::openmode mode = ios_base::out);
@@ -12040,6 +12104,17 @@
1204012104
\tcode{const_cast<basic_filebuf<charT, traits>*>(addressof(sb))}.
1204112105
\end{itemdescr}
1204212106

12107+
\indexlibrarymember{native_handle}{basic_ofstream}%
12108+
\begin{itemdecl}
12109+
native_handle_type native_handle() const noexcept;
12110+
\end{itemdecl}
12111+
12112+
\begin{itemdescr}
12113+
\pnum
12114+
\effects
12115+
Equivalent to: \tcode{return rdbuf()->native_handle();}
12116+
\end{itemdescr}
12117+
1204312118
\indexlibrarymember{is_open}{basic_ofstream}%
1204412119
\begin{itemdecl}
1204512120
bool is_open() const;
@@ -12114,6 +12189,7 @@
1211412189
using pos_type = typename traits::pos_type;
1211512190
using off_type = typename traits::off_type;
1211612191
using traits_type = traits;
12192+
using native_handle_type = typename basic_filebuf<charT, traits>::native_handle_type;
1211712193

1211812194
// \ref{fstream.cons}, constructors
1211912195
basic_fstream();
@@ -12139,6 +12215,8 @@
1213912215

1214012216
// \ref{fstream.members}, members
1214112217
basic_filebuf<charT, traits>* rdbuf() const;
12218+
native_handle_type native_handle() const noexcept;
12219+
1214212220
bool is_open() const;
1214312221
void open(
1214412222
const char* s,
@@ -12297,6 +12375,17 @@
1229712375
\tcode{const_cast<basic_filebuf<charT, traits>*>(addressof(sb))}.
1229812376
\end{itemdescr}
1229912377

12378+
\indexlibrarymember{native_handle}{basic_fstream}%
12379+
\begin{itemdecl}
12380+
native_handle_type native_handle() const noexcept;
12381+
\end{itemdecl}
12382+
12383+
\begin{itemdescr}
12384+
\pnum
12385+
\effects
12386+
Equivalent to: \tcode{return rdbuf()->native_handle();}
12387+
\end{itemdescr}
12388+
1230012389
\indexlibrarymember{is_open}{basic_fstream}%
1230112390
\begin{itemdecl}
1230212391
bool is_open() const;

source/support.tex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@
648648
#define @\defnlibxname{cpp_lib_freestanding_ratio}@ 202306L // freestanding, also in \libheader{ratio}
649649
#define @\defnlibxname{cpp_lib_freestanding_tuple}@ 202306L // freestanding, also in \libheader{tuple}
650650
#define @\defnlibxname{cpp_lib_freestanding_utility}@ 202306L // freestanding, also in \libheader{utility}
651+
#define @\defnlibxname{cpp_lib_fstream_native_handle}@ 202306L // also in \libheader{fstream}
651652
#define @\defnlibxname{cpp_lib_function_ref}@ 202306L // also in \libheader{functional}
652653
#define @\defnlibxname{cpp_lib_gcd_lcm}@ 201606L // also in \libheader{numeric}
653654
#define @\defnlibxname{cpp_lib_generator}@ 202207L // also in \libheader{generator}

0 commit comments

Comments
 (0)