summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/std/fstream
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@linaro.org>2017-11-05 17:19:35 +0000
committerRichard Sandiford <richard.sandiford@linaro.org>2017-11-05 17:19:35 +0000
commit648f8fc59b2cc39abd24f4c22388b346cdebcc31 (patch)
tree3a07eccc4c22b265261edd75c9ec3910d9c626f5 /libstdc++-v3/include/std/fstream
parent7bef5b82e4109778a0988d20e19e1ed29dadd835 (diff)
parent8c089b5c15a7b35644750ca393f1e66071ad9aa9 (diff)
downloadgcc-648f8fc59b2cc39abd24f4c22388b346cdebcc31.tar.gz
Merge trunk into sve
Diffstat (limited to 'libstdc++-v3/include/std/fstream')
-rw-r--r--libstdc++-v3/include/std/fstream162
1 files changed, 127 insertions, 35 deletions
diff --git a/libstdc++-v3/include/std/fstream b/libstdc++-v3/include/std/fstream
index 52830945fe2..a3324c004d7 100644
--- a/libstdc++-v3/include/std/fstream
+++ b/libstdc++-v3/include/std/fstream
@@ -216,6 +216,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
}
+#if __cplusplus >= 201703L
+ template<typename _Path, typename _Result = _Path, typename _Path2
+ = decltype(std::declval<_Path&>().make_preferred().native())>
+ using _If_path = enable_if_t<is_same_v<_Path, _Path2>, _Result>;
+#endif // C++17
+
public:
// Constructors/destructor:
/**
@@ -306,7 +312,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__filebuf_type*
open(const std::string& __s, ios_base::openmode __mode)
{ return open(__s.c_str(), __mode); }
-#endif
+
+#if __cplusplus >= 201703L
+ /**
+ * @brief Opens an external file.
+ * @param __s The name of the file, as a filesystem::path.
+ * @param __mode The open mode flags.
+ * @return @c this on success, NULL on failure
+ */
+ template<typename _Path>
+ _If_path<_Path, __filebuf_type*>
+ open(const _Path& __s, ios_base::openmode __mode)
+ { return open(__s.c_str(), __mode); }
+#endif // C++17
+#endif // C++11
/**
* @brief Closes the currently associated file.
@@ -487,9 +506,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __mode Open file in specified mode (see std::ios_base).
*
* @c ios_base::in is automatically included in @a __mode.
- *
- * Tip: When using std::string to hold the filename, you must use
- * .c_str() before passing it to this constructor.
*/
explicit
basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in)
@@ -516,13 +532,29 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
this->open(__s, __mode);
}
+#if __cplusplus >= 201703L
+ /**
+ * @param Create an input file stream.
+ * @param __s filesystem::path specifying the filename.
+ * @param __mode Open file in specified mode (see std::ios_base).
+ *
+ * @c ios_base::in is automatically included in @a __mode.
+ */
+ template<typename _Path, typename = _Require<
+ is_constructible<__filebuf_type, const _Path&, ios_base::openmode>>>
+ basic_ifstream(const _Path& __s,
+ ios_base::openmode __mode = ios_base::in)
+ : basic_ifstream(__s.c_str(), __mode)
+ { }
+#endif // C++17
+
basic_ifstream(const basic_ifstream&) = delete;
basic_ifstream(basic_ifstream&& __rhs)
: __istream_type(std::move(__rhs)),
_M_filebuf(std::move(__rhs._M_filebuf))
{ __istream_type::set_rdbuf(&_M_filebuf); }
-#endif
+#endif // C++11
/**
* @brief The destructor does nothing.
@@ -587,9 +619,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*
* Calls @c std::basic_filebuf::open(s,__mode|in). If that function
* fails, @c failbit is set in the stream's error state.
- *
- * Tip: When using std::string to hold the filename, you must use
- * .c_str() before passing it to this constructor.
*/
void
open(const char* __s, ios_base::openmode __mode = ios_base::in)
@@ -621,7 +650,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// 409. Closing an fstream should clear error state
this->clear();
}
-#endif
+
+#if __cplusplus >= 201703L
+ /**
+ * @brief Opens an external file.
+ * @param __s The name of the file, as a filesystem::path.
+ * @param __mode The open mode flags.
+ *
+ * Calls @c std::basic_filebuf::open(__s,__mode|in). If that function
+ * fails, @c failbit is set in the stream's error state.
+ */
+ template<typename _Path>
+ auto
+ open(const _Path& __s, ios_base::openmode __mode = ios_base::in)
+ -> decltype(_M_filebuf.open(__s, __mode))
+ { open(__s.c_str(), __mode); }
+#endif // C++17
+#endif // C++11
/**
* @brief Close the file.
@@ -687,15 +732,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __s Null terminated string specifying the filename.
* @param __mode Open file in specified mode (see std::ios_base).
*
- * @c ios_base::out | @c ios_base::trunc is automatically included in
- * @a __mode.
- *
- * Tip: When using std::string to hold the filename, you must use
- * .c_str() before passing it to this constructor.
+ * @c ios_base::out is automatically included in @a __mode.
*/
explicit
basic_ofstream(const char* __s,
- ios_base::openmode __mode = ios_base::out|ios_base::trunc)
+ ios_base::openmode __mode = ios_base::out)
: __ostream_type(), _M_filebuf()
{
this->init(&_M_filebuf);
@@ -708,18 +749,33 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __s std::string specifying the filename.
* @param __mode Open file in specified mode (see std::ios_base).
*
- * @c ios_base::out | @c ios_base::trunc is automatically included in
- * @a __mode.
+ * @c ios_base::out is automatically included in @a __mode.
*/
explicit
basic_ofstream(const std::string& __s,
- ios_base::openmode __mode = ios_base::out|ios_base::trunc)
+ ios_base::openmode __mode = ios_base::out)
: __ostream_type(), _M_filebuf()
{
this->init(&_M_filebuf);
this->open(__s, __mode);
}
+#if __cplusplus >= 201703L
+ /**
+ * @param Create an output file stream.
+ * @param __s filesystem::path specifying the filename.
+ * @param __mode Open file in specified mode (see std::ios_base).
+ *
+ * @c ios_base::out is automatically included in @a __mode.
+ */
+ template<typename _Path, typename = _Require<
+ is_constructible<__filebuf_type, const _Path&, ios_base::openmode>>>
+ basic_ofstream(const _Path& __s,
+ ios_base::openmode __mode = ios_base::out)
+ : basic_ofstream(__s.c_str(), __mode)
+ { }
+#endif // C++17
+
basic_ofstream(const basic_ofstream&) = delete;
basic_ofstream(basic_ofstream&& __rhs)
@@ -789,15 +845,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __s The name of the file.
* @param __mode The open mode flags.
*
- * Calls @c std::basic_filebuf::open(__s,__mode|out|trunc). If that
+ * Calls @c std::basic_filebuf::open(__s,__mode|out). If that
* function fails, @c failbit is set in the stream's error state.
- *
- * Tip: When using std::string to hold the filename, you must use
- * .c_str() before passing it to this constructor.
*/
void
- open(const char* __s,
- ios_base::openmode __mode = ios_base::out | ios_base::trunc)
+ open(const char* __s, ios_base::openmode __mode = ios_base::out)
{
if (!_M_filebuf.open(__s, __mode | ios_base::out))
this->setstate(ios_base::failbit);
@@ -813,12 +865,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @param __s The name of the file.
* @param __mode The open mode flags.
*
- * Calls @c std::basic_filebuf::open(s,mode|out|trunc). If that
+ * Calls @c std::basic_filebuf::open(s,mode|out). If that
* function fails, @c failbit is set in the stream's error state.
*/
void
- open(const std::string& __s,
- ios_base::openmode __mode = ios_base::out | ios_base::trunc)
+ open(const std::string& __s, ios_base::openmode __mode = ios_base::out)
{
if (!_M_filebuf.open(__s, __mode | ios_base::out))
this->setstate(ios_base::failbit);
@@ -827,7 +878,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// 409. Closing an fstream should clear error state
this->clear();
}
-#endif
+
+#if __cplusplus >= 201703L
+ /**
+ * @brief Opens an external file.
+ * @param __s The name of the file, as a filesystem::path.
+ * @param __mode The open mode flags.
+ *
+ * Calls @c std::basic_filebuf::open(__s,__mode|out). If that
+ * function fails, @c failbit is set in the stream's error state.
+ */
+ template<typename _Path>
+ auto
+ open(const _Path& __s, ios_base::openmode __mode = ios_base::out)
+ -> decltype(_M_filebuf.open(__s, __mode))
+ { open(__s.c_str(), __mode); }
+#endif // C++17
+#endif // C++11
/**
* @brief Close the file.
@@ -894,9 +961,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @brief Create an input/output file stream.
* @param __s Null terminated string specifying the filename.
* @param __mode Open file in specified mode (see std::ios_base).
- *
- * Tip: When using std::string to hold the filename, you must use
- * .c_str() before passing it to this constructor.
*/
explicit
basic_fstream(const char* __s,
@@ -922,6 +986,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
this->open(__s, __mode);
}
+#if __cplusplus >= 201703L
+ /**
+ * @param Create an input/output file stream.
+ * @param __s filesystem::path specifying the filename.
+ * @param __mode Open file in specified mode (see std::ios_base).
+ */
+ template<typename _Path, typename = _Require<
+ is_constructible<__filebuf_type, const _Path&, ios_base::openmode>>>
+ basic_fstream(const _Path& __s,
+ ios_base::openmode __mode = ios_base::in | ios_base::out)
+ : basic_fstream(__s.c_str(), __mode)
+ { }
+#endif // C++17
+
basic_fstream(const basic_fstream&) = delete;
basic_fstream(basic_fstream&& __rhs)
@@ -993,9 +1071,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*
* Calls @c std::basic_filebuf::open(__s,__mode). If that
* function fails, @c failbit is set in the stream's error state.
- *
- * Tip: When using std::string to hold the filename, you must use
- * .c_str() before passing it to this constructor.
*/
void
open(const char* __s,
@@ -1029,7 +1104,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// 409. Closing an fstream should clear error state
this->clear();
}
-#endif
+
+#if __cplusplus >= 201703L
+ /**
+ * @brief Opens an external file.
+ * @param __s The name of the file, as a filesystem::path.
+ * @param __mode The open mode flags.
+ *
+ * Calls @c std::basic_filebuf::open(__s,__mode). If that
+ * function fails, @c failbit is set in the stream's error state.
+ */
+ template<typename _Path>
+ auto
+ open(const _Path& __s,
+ ios_base::openmode __mode = ios_base::in | ios_base::out)
+ -> decltype(_M_filebuf.open(__s, __mode))
+ { open(__s.c_str(), __mode); }
+#endif // C++17
+#endif // C++11
/**
* @brief Close the file.