From 0c0e16c61cb01555277c8605e970ace1f4fdce1b Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Tue, 22 Apr 2014 22:03:31 +0200 Subject: [PATCH] Make iparserdocstream more like std::istream In C++98 std::istream does not use an operator bool(), but an operator void*() instead, which prevents some unwanted conversions (this is one possible implementation of the safe bool idiom). In C++11 std::istream uses explicit operator bool, which prevents the unwanted conversions using a new language feature. This change does not have any effect on correct code, but prevents some mistakes. --- src/tex2lyx/Parser.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/tex2lyx/Parser.h b/src/tex2lyx/Parser.h index 67dd0b2457..57a5cb1bf8 100644 --- a/src/tex2lyx/Parser.h +++ b/src/tex2lyx/Parser.h @@ -125,10 +125,15 @@ public: iparserdocstream(idocstream & is) : is_(is) {} - /// Like std::istream::operator void*() +#if (__cplusplus > 19971L) + /// Like std::istream::operator bool() /// Do not convert is_ implicitly to bool, since that is forbidden in C++11. - /// FIXME: Convert to operator void*() in LyX 2.2 - operator bool() const { return s_.empty() ? !is_.fail() : true; } + explicit operator bool() const { return s_.empty() ? !is_.fail() : true; } +#else + /// Like std::istream::operator void*() + operator void*() const { return (s_.empty() && is_.fail()) ? + 0 : const_cast(this); } +#endif /// change the encoding of the input stream to \p e (iconv name) void setEncoding(std::string const & e);