[Support] Add llvm::transformOptional
llvm::Optional<T> has transform, which is equivalent to std::optional<T>::transform. The problem is that std::optional<T>::transform won't be available until C++23, implying that we probably cannot use it in our codebase untli 2028 or so. We certainly don't want to keep llvm::Optional just for transform. This patch adds llvm::transformOptional to STLForwardCompat.h so that we can use transform during the migration to std::optional and beyond. I've shamelessly borrowed the implementation and test from llvm/include/llvm/ADT/Optional.h and llvm/unittests/ADT/OptionalTest.cpp respectively. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716 Differential Revision: https://reviews.llvm.org/D139779
Loading
Please sign in to comment