mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 11:02:59 +02:00
fbbe67869c
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 |
||
---|---|---|
.. | ||
ADT | ||
Analysis | ||
AsmParser | ||
Bitcode | ||
CodeGen | ||
DebugInfo | ||
ExecutionEngine | ||
IR | ||
LineEditor | ||
Linker | ||
MC | ||
MI | ||
Object | ||
ObjectYAML | ||
Option | ||
ProfileData | ||
Support | ||
Target | ||
Transforms | ||
XRay | ||
CMakeLists.txt |