From 634d73eb9a84e27cecf0cc39cf371f5d16556514 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 21 Nov 2017 14:06:21 +0200 Subject: Move eof() utility to libbutl --- libbutl/utility.mxx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'libbutl/utility.mxx') diff --git a/libbutl/utility.mxx b/libbutl/utility.mxx index 8ef0d08..410dae8 100644 --- a/libbutl/utility.mxx +++ b/libbutl/utility.mxx @@ -15,6 +15,7 @@ #ifndef __cpp_lib_modules #include #include // ostream +#include #include // size_t #include // move(), forward() #include // strcmp(), strlen() @@ -37,7 +38,6 @@ import std.io; #include - LIBBUTL_MODEXPORT namespace butl { // Throw std::system_error with generic_category or system_category, @@ -56,6 +56,21 @@ LIBBUTL_MODEXPORT namespace butl [[noreturn]] LIBBUTL_SYMEXPORT void throw_system_error (int system_code, int fallback_errno_code = 0); + // If an input stream is in a failed state, then return true if this is + // because of the eof and throw istream::failure otherwise. If the stream + // is not in a failed state, return false. This helper function is normally + // used like this: + // + // is.exceptions (istream::badbit); + // + // for (string l; !eof (getline (is, l)); ) + // { + // ... + // } + // + bool + eof (std::istream&); + // Convert ASCII character/string case. If there is no upper/lower case // counterpart, leave the character unchanged. The POSIX locale (also known // as C locale) must be the current application locale. Otherwise the -- cgit v1.1