From cd2511afa674f917cbfe39fc8ea4cc7838184720 Mon Sep 17 00:00:00 2001 From: Andrew Krieger Date: Fri, 28 Jul 2017 08:20:06 -0700 Subject: [PATCH] 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 --- folly/Range.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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; } -- 2.34.1