summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2017-04-12 19:59:37 +0000
committerZachary Turner <zturner@google.com>2017-04-12 19:59:37 +0000
commit2bb94cd0ddfc75b883192845a986ce228d7cd31d (patch)
treee623a410efef227a255b477de27765e77d96d73e /llvm/lib/Bitcode/Reader/BitcodeReader.cpp
parent538b3f419835de3147c529c8214a41ad089af777 (diff)
downloadbcm5719-llvm-2bb94cd0ddfc75b883192845a986ce228d7cd31d.tar.gz
bcm5719-llvm-2bb94cd0ddfc75b883192845a986ce228d7cd31d.zip
[Support] Add support for unique_ptr<> to Casting.h.
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
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
0 files changed, 0 insertions, 0 deletions
OpenPOWER on IntegriCloud