mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
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:
parent
e7b16d961f
commit
0c0e16c61c
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user