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.
This commit is contained in:
Georg Baum 2014-04-22 22:03:31 +02:00
parent e7b16d961f
commit 0c0e16c61c

View File

@ -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<iparserdocstream *>(this); }
#endif
/// change the encoding of the input stream to \p e (iconv name)
void setEncoding(std::string const & e);