forked from OSchip/llvm-project
2bb94cd0dd
Often you have a unique_ptr<T> where T supports LLVM's casting methods, and you wish to cast it to a unique_ptr<U>. Prior to this patch, this requires doing hacky things like: unique_ptr<U> Casted; if (isa<U>(Orig.get())) Casted.reset(cast<U>(Orig.release())); This is overly verbose, and it would be nice to just be able to use unique_ptr directly with cast and dyn_cast. To this end, this patch updates cast<> to work directly with unique_ptr<T>, so you can now write: auto Casted = cast<U>(std::move(Orig)); Since it's possible for dyn_cast<> to fail, however, we choose to use a slightly different API here, because it's awkward to write if (auto Casted = dyn_cast<U>(std::move(Orig))) {} when Orig may end up not having been moved at all. So the interface for dyn_cast is if (auto Casted = unique_dyn_cast<U>(Orig)) {} Where the inclusion of `unique` in the name of the cast operator re-affirms that regardless of success of or fail of the casting, exactly one of the input value and the return value will contain a non-null result. Differential Revision: https://reviews.llvm.org/D31890 llvm-svn: 300098 |
||
---|---|---|
.. | ||
ARMAttributeParser.cpp | ||
AlignOfTest.cpp | ||
AllocatorTest.cpp | ||
ArrayRecyclerTest.cpp | ||
BinaryStreamTest.cpp | ||
BlockFrequencyTest.cpp | ||
BranchProbabilityTest.cpp | ||
CMakeLists.txt | ||
CachePruningTest.cpp | ||
Casting.cpp | ||
Chrono.cpp | ||
CommandLineTest.cpp | ||
CompressionTest.cpp | ||
ConvertUTFTest.cpp | ||
DataExtractorTest.cpp | ||
DebugTest.cpp | ||
DwarfTest.cpp | ||
EndianStreamTest.cpp | ||
EndianTest.cpp | ||
ErrorOrTest.cpp | ||
ErrorTest.cpp | ||
FileOutputBufferTest.cpp | ||
FormatVariadicTest.cpp | ||
GlobPatternTest.cpp | ||
Host.cpp | ||
LEB128Test.cpp | ||
LineIteratorTest.cpp | ||
LockFileManagerTest.cpp | ||
MD5Test.cpp | ||
ManagedStatic.cpp | ||
MathExtrasTest.cpp | ||
MemoryBufferTest.cpp | ||
MemoryTest.cpp | ||
NativeFormatTests.cpp | ||
Path.cpp | ||
ProcessTest.cpp | ||
ProgramTest.cpp | ||
RegexTest.cpp | ||
ReplaceFileTest.cpp | ||
ScaledNumberTest.cpp | ||
SourceMgrTest.cpp | ||
SpecialCaseListTest.cpp | ||
StringPool.cpp | ||
SwapByteOrderTest.cpp | ||
TarWriterTest.cpp | ||
TargetParserTest.cpp | ||
ThreadLocalTest.cpp | ||
ThreadPool.cpp | ||
Threading.cpp | ||
TimerTest.cpp | ||
TrailingObjectsTest.cpp | ||
TrigramIndexTest.cpp | ||
TypeNameTest.cpp | ||
UnicodeTest.cpp | ||
YAMLIOTest.cpp | ||
YAMLParserTest.cpp | ||
formatted_raw_ostream_test.cpp | ||
raw_ostream_test.cpp | ||
raw_pwrite_stream_test.cpp | ||
raw_sha1_ostream_test.cpp | ||
xxhashTest.cpp |