Discussion:
[LyX/master] Make iparserdocstream more like std::istream
Vincent van Ravesteijn
2014-04-29 14:54:05 UTC
Permalink
commit 0c0e16c61cb01555277c8605e970ace1f4fdce1b
Date: Tue Apr 22 22:03:31 2014 +0200
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.
diff --git a/src/tex2lyx/Parser.h b/src/tex2lyx/Parser.h
index 67dd0b2..57a5cb1 100644
--- a/src/tex2lyx/Parser.h
+++ b/src/tex2lyx/Parser.h
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);
This issues a warning for me: __cplusplus is defined as 199711L.

Vincent
Georg Baum
2014-04-29 19:04:16 UTC
Permalink
Post by Vincent van Ravesteijn
This issues a warning for me: __cplusplus is defined as 199711L.
Oops. I stole this test from src/support/strfwd.h, and I also read a bit on
the web which values can be assumed for __cplusplus, but what I did not
notice was that the number in strfwd.h was not correct. I fixed now both
places.


Georg

Loading...