Commit cd2511af authored by Andrew Krieger's avatar Andrew Krieger Committed by Facebook Github Bot

Fix StringPiece ostream overloads to properly not rely on <ostream>

Summary:
std::ostream may be incomplete because Range.h doesn't use <ostream>,
only <iosfwd>. Changing the operator<< overloads to be templated on the char
type defers typechecking until callsites, which will avoid the potential problem.

Reviewed By: yfeldblum, ericniebler

Differential Revision: D5494648

fbshipit-source-id: e59b6fdfba6c08ec70ebb1e10c14a43307a1119f
parent 8dde913d
......@@ -970,15 +970,19 @@ typedef Range<char*> MutableStringPiece;
typedef Range<const unsigned char*> ByteRange;
typedef Range<unsigned char*> MutableByteRange;
inline std::ostream& operator<<(std::ostream& os,
const StringPiece piece) {
os.write(piece.start(), std::streamsize(piece.size()));
template <class C>
std::basic_ostream<C>& operator<<(
std::basic_ostream<C>& os,
Range<C const*> piece) {
using StreamSize = decltype(os.width());
os.write(piece.start(), static_cast<StreamSize>(piece.size()));
return os;
}
inline std::ostream& operator<<(std::ostream& os,
const MutableStringPiece piece) {
os.write(piece.start(), std::streamsize(piece.size()));
template <class C>
std::basic_ostream<C>& operator<<(std::basic_ostream<C>& os, Range<C*> piece) {
using StreamSize = decltype(os.width());
os.write(piece.start(), static_cast<StreamSize>(piece.size()));
return os;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment