[PATCH] D132747: [llvm][ADT] Overload output stream operator `<<` for `StringMapEntry` and `StringMap`.
weiyi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 29 05:08:34 PDT 2022
wyt added inline comments.
================
Comment at: llvm/include/llvm/ADT/StringMapEntry.h:166
+ return OS << "}";
+}
+
----------------
gribozavr2 wrote:
> I wonder if we should put these operators into llvm/Testing/ADT, since these operators are only supposed to be used from tests. For production code, LLVM strongly prefers llvm::raw_ostream, a much more light-weight type than std::ostream.
>
> In fact, this is the first `operator<<(std::ostream&, <anything>)` overload in llvm/ADT. Printable types (like APInt) are printable into raw_ostream.
>
> Another option is to provide `operator<<(llvm::raw_ostream&)` in llvm/ADT, and wrap them in `operator<<(std::ostream&)` in llvm/Testing/ADT. The llvm/ADT version won't have the SFINAE magic, but the llvm/Testing/ADT one will.
>
> WDYT?
Moved the printing into Testing/ADT.
I also attempted the second approach but it wasn't very successful. Using <<(llvm::raw_ostream) from <<(std::ostream) meant that <<(llvm::raw_ostream) needed to be implemented for any structure we wanted to print. However for use cases related to google test, it is more likely that users implement the <<(std::ostream) operator and not the <<(llvm::raw_ostream).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132747/new/
https://reviews.llvm.org/D132747
More information about the llvm-commits
mailing list