[llvm] 6c8c836 - Add an llvm::cl::opt::operator=(T &&Val) (#147502)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 8 05:26:19 PDT 2025
Author: Tom Natan
Date: 2025-07-08T13:26:15+01:00
New Revision: 6c8c836b4f5a0b519db6f97c4882c6c061edd004
URL: https://github.com/llvm/llvm-project/commit/6c8c836b4f5a0b519db6f97c4882c6c061edd004
DIFF: https://github.com/llvm/llvm-project/commit/6c8c836b4f5a0b519db6f97c4882c6c061edd004.diff
LOG: Add an llvm::cl::opt::operator=(T &&Val) (#147502)
Add an llvm::cl::opt::operator= that takes an rvalue reference of value,
to avoid an unecessary copy for types with memory allocation (string,
vector, etc).
Added:
Modified:
llvm/include/llvm/Support/CommandLine.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h
index 5489b3ff78f51..adaa75cc6c348 100644
--- a/llvm/include/llvm/Support/CommandLine.h
+++ b/llvm/include/llvm/Support/CommandLine.h
@@ -1496,6 +1496,12 @@ class opt
return this->getValue();
}
+ template <class T> DataType &operator=(T &&Val) {
+ this->getValue() = std::forward<T>(Val);
+ Callback(this->getValue());
+ return this->getValue();
+ }
+
template <class... Mods>
explicit opt(const Mods &... Ms)
: Option(llvm::cl::Optional, NotHidden), Parser(*this) {
More information about the llvm-commits
mailing list