From: Andrew Krieger Date: Fri, 28 Jul 2017 15:20:05 +0000 (-0700) Subject: std::basic_ostream operator<< overload for FixedString X-Git-Tag: v2017.07.31.00~17 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=8dde913d5369b884adc95dac86f825facc8d5244;p=folly.git std::basic_ostream operator<< overload for FixedString Summary: When attempting to output a FixedString into eg. glog or some other ostream, it is first being implicitly converted to StringPiece and then that is printed using the overloaded operator<<. If another suitable implicit conversion is provided, eg. to `dynamic`, compilers cannot choose between either one. Instead, overload operator<< directly on FixedString to resolve the ambiguity. Reviewed By: yfeldblum, ericniebler Differential Revision: D5492779 fbshipit-source-id: 92d661e5471a91057d7a0d010420709c5d59232f --- diff --git a/folly/FixedString.h b/folly/FixedString.h index 935cd821..bf0d52e3 100644 --- a/folly/FixedString.h +++ b/folly/FixedString.h @@ -2938,6 +2938,15 @@ class BasicFixedString : private detail::fixedstring::FixedStringBase { } }; +template +inline std::basic_ostream& operator<<( + std::basic_ostream& os, + const BasicFixedString& string) { + using StreamSize = decltype(os.width()); + os.write(string.begin(), static_cast(string.size())); + return os; +} + /** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** * Symmetric relational operators */