Skip to content

Commit 4449d8a

Browse files
authored
LWG-3430, fstream should be constructible from string_view (#1968)
1 parent 46c040d commit 4449d8a

File tree

1 file changed

+20
-35
lines changed

1 file changed

+20
-35
lines changed

stl/inc/fstream

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ namespace experimental {
4848
} // namespace experimental
4949
#endif // _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
5050

51+
// clang-format off
52+
template <class _Ty>
53+
_INLINE_VAR constexpr bool _Is_any_path = _Is_any_of_v<_Ty
54+
#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
55+
, experimental::filesystem::path
56+
#endif // _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
57+
#if _HAS_CXX17
58+
, filesystem::path
59+
#endif // _HAS_CXX17
60+
>;
61+
// clang-format on
62+
5163
extern _CRTIMP2_PURE FILE* __CLRCALL_PURE_OR_CDECL _Fiopen(const char*, ios_base::openmode, int);
5264
extern _CRTIMP2_PURE FILE* __CLRCALL_PURE_OR_CDECL _Fiopen(const wchar_t*, ios_base::openmode, int);
5365

@@ -830,19 +842,10 @@ public:
830842
const wstring& _Str, ios_base::openmode _Mode = ios_base::in, int _Prot = ios_base::_Default_open_prot)
831843
: basic_ifstream(_Str.c_str(), _Mode, _Prot) {} // extension
832844

833-
#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
834-
template <class _Path_ish = experimental::filesystem::path>
835-
explicit basic_ifstream(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::in,
836-
int _Prot = ios_base::_Default_open_prot)
837-
: basic_ifstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension
838-
#endif // _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
839-
840-
#if _HAS_CXX17
841-
template <int = 0, class _Path_ish = filesystem::path>
842-
explicit basic_ifstream(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::in,
843-
int _Prot = ios_base::_Default_open_prot)
845+
template <class _Ty, enable_if_t<_Is_any_path<_Ty>, int> = 0>
846+
explicit basic_ifstream(
847+
const _Ty& _Path, ios_base::openmode _Mode = ios_base::in, int _Prot = ios_base::_Default_open_prot)
844848
: basic_ifstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension
845-
#endif // _HAS_CXX17
846849

847850
#ifdef _NATIVE_WCHAR_T_DEFINED
848851
explicit basic_ifstream(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::in,
@@ -1023,19 +1026,10 @@ public:
10231026
const wstring& _Str, ios_base::openmode _Mode = ios_base::out, int _Prot = ios_base::_Default_open_prot)
10241027
: basic_ofstream(_Str.c_str(), _Mode, _Prot) {} // extension
10251028

1026-
#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
1027-
template <class _Path_ish = experimental::filesystem::path>
1028-
explicit basic_ofstream(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::out,
1029-
int _Prot = ios_base::_Default_open_prot)
1030-
: basic_ofstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension
1031-
#endif // _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
1032-
1033-
#if _HAS_CXX17
1034-
template <int = 0, class _Path_ish = filesystem::path>
1035-
explicit basic_ofstream(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::out,
1036-
int _Prot = ios_base::_Default_open_prot)
1029+
template <class _Ty, enable_if_t<_Is_any_path<_Ty>, int> = 0>
1030+
explicit basic_ofstream(
1031+
const _Ty& _Path, ios_base::openmode _Mode = ios_base::out, int _Prot = ios_base::_Default_open_prot)
10371032
: basic_ofstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension
1038-
#endif // _HAS_CXX17
10391033

10401034
#ifdef _NATIVE_WCHAR_T_DEFINED
10411035
explicit basic_ofstream(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::out,
@@ -1221,19 +1215,10 @@ public:
12211215
int _Prot = ios_base::_Default_open_prot)
12221216
: basic_fstream(_Str.c_str(), _Mode, _Prot) {} // extension
12231217

1224-
#if _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
1225-
template <class _Path_ish = experimental::filesystem::path>
1226-
explicit basic_fstream(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::in | ios_base::out,
1218+
template <class _Ty, enable_if_t<_Is_any_path<_Ty>, int> = 0>
1219+
explicit basic_fstream(const _Ty& _Path, ios_base::openmode _Mode = ios_base::in | ios_base::out,
12271220
int _Prot = ios_base::_Default_open_prot)
12281221
: basic_fstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension
1229-
#endif // _FSTREAM_SUPPORTS_EXPERIMENTAL_FILESYSTEM
1230-
1231-
#if _HAS_CXX17
1232-
template <int = 0, class _Path_ish = filesystem::path>
1233-
explicit basic_fstream(const _Identity_t<_Path_ish>& _Path, ios_base::openmode _Mode = ios_base::in | ios_base::out,
1234-
int _Prot = ios_base::_Default_open_prot)
1235-
: basic_fstream(_Path.c_str(), _Mode, _Prot) {} // _Prot is an extension
1236-
#endif // _HAS_CXX17
12371222

12381223
#ifdef _NATIVE_WCHAR_T_DEFINED
12391224
explicit basic_fstream(const unsigned short* _Filename, ios_base::openmode _Mode = ios_base::in | ios_base::out,

0 commit comments

Comments
 (0)