From: Andrew Krieger Date: Fri, 28 Jul 2017 15:20:06 +0000 (-0700) Subject: Fix StringPiece ostream overloads to properly not rely on X-Git-Tag: v2017.07.31.00~16 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=cd2511afa674f917cbfe39fc8ea4cc7838184720;p=folly.git Fix StringPiece ostream overloads to properly not rely on Summary: std::ostream may be incomplete because Range.h doesn't use , only . 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 --- diff --git a/folly/Range.h b/folly/Range.h index efe34908..a2c1d96c 100644 --- a/folly/Range.h +++ b/folly/Range.h @@ -970,15 +970,19 @@ typedef Range MutableStringPiece; typedef Range ByteRange; typedef Range MutableByteRange; -inline std::ostream& operator<<(std::ostream& os, - const StringPiece piece) { - os.write(piece.start(), std::streamsize(piece.size())); +template +std::basic_ostream& operator<<( + std::basic_ostream& os, + Range piece) { + using StreamSize = decltype(os.width()); + os.write(piece.start(), static_cast(piece.size())); return os; } -inline std::ostream& operator<<(std::ostream& os, - const MutableStringPiece piece) { - os.write(piece.start(), std::streamsize(piece.size())); +template +std::basic_ostream& operator<<(std::basic_ostream& os, Range piece) { + using StreamSize = decltype(os.width()); + os.write(piece.start(), static_cast(piece.size())); return os; }