[ADT] Add streaming operators for llvm::Optional
authorPavel Labath <pavel@labath.sk>
Fri, 18 Jan 2019 12:52:03 +0000 (12:52 +0000)
committerPavel Labath <pavel@labath.sk>
Fri, 18 Jan 2019 12:52:03 +0000 (12:52 +0000)
commit47e9a21d34849b52bbde557f3aacca2941f34092
treeacf5460e9a8b9c0a2f8cce87790d7880efeb3bd2
parent5e36433189ba3297af33a9088ee17abde10c7871
[ADT] Add streaming operators for llvm::Optional

Summary:
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>.

Reviewers: sammccall, dblaikie

Reviewed By: sammccall

Subscribers: mgorny, dexonsmith, kristina, llvm-commits

Differential Revision: https://reviews.llvm.org/D56795

llvm-svn: 351548
llvm/include/llvm/ADT/Optional.h
llvm/lib/Support/CMakeLists.txt
llvm/lib/Support/Optional.cpp [new file with mode: 0644]
llvm/unittests/ADT/OptionalTest.cpp
llvm/utils/unittest/googletest/include/gtest/internal/custom/raw-ostream.h