[PATCH] D56795: [ADT] Add streaming operators for llvm::Optional

Pavel Labath via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 16 09:46:32 PST 2019


labath created this revision.
labath added reviewers: sammccall, dblaikie.
Herald added subscribers: kristina, dexonsmith, mgorny.

The operators simply print the underlying value or "None".

The trickier part of this patch is making sure the streaming operators
work even in unit tests (which was my primary motivation, though I can
also see them being useful elsewhere). Since the stream operator was a
template, implicit conversions did not kick in, and our gtest glue code
was explicitly introducing an implicit conversion to make sure other
implicit conversions do not kick in :P. I resolve that by specializing
llvm_gtest::StreamSwitch for llvm:Optional<T>.


Repository:
  rL LLVM

https://reviews.llvm.org/D56795

Files:
  include/llvm/ADT/Optional.h
  lib/Support/CMakeLists.txt
  lib/Support/Optional.cpp
  unittests/ADT/OptionalTest.cpp
  utils/unittest/googletest/include/gtest/internal/custom/raw-ostream.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56795.182081.patch
Type: text/x-patch
Size: 4860 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190116/eb7810c1/attachment.bin>


More information about the llvm-commits mailing list