[llvm] 4ca8f65 - [Support] Simplify setDefaultImpl (NFC) (#137528)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 27 14:08:42 PDT 2025
Author: Kazu Hirata
Date: 2025-04-27T14:08:38-07:00
New Revision: 4ca8f65b6c4fd554783848f77094622b9f9ea776
URL: https://github.com/llvm/llvm-project/commit/4ca8f65b6c4fd554783848f77094622b9f9ea776
DIFF: https://github.com/llvm/llvm-project/commit/4ca8f65b6c4fd554783848f77094622b9f9ea776.diff
LOG: [Support] Simplify setDefaultImpl (NFC) (#137528)
We can use "constexpr if" to combine the two variants of functions.
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 5d60bb64bbb20..531750572102c 100644
--- a/llvm/include/llvm/Support/CommandLine.h
+++ b/llvm/include/llvm/Support/CommandLine.h
@@ -1459,20 +1459,16 @@ class opt
}
}
- template <class T, class = std::enable_if_t<std::is_assignable_v<T &, T>>>
- void setDefaultImpl() {
- const OptionValue<DataType> &V = this->getDefault();
- if (V.hasValue())
- this->setValue(V.getValue());
- else
- this->setValue(T());
+ void setDefault() override {
+ if constexpr (std::is_assignable_v<DataType &, DataType>) {
+ const OptionValue<DataType> &V = this->getDefault();
+ if (V.hasValue())
+ this->setValue(V.getValue());
+ else
+ this->setValue(DataType());
+ }
}
- template <class T, class = std::enable_if_t<!std::is_assignable_v<T &, T>>>
- void setDefaultImpl(...) {}
-
- void setDefault() override { setDefaultImpl<DataType>(); }
-
void done() {
addArgument();
Parser.initialize();
More information about the llvm-commits
mailing list