[llvm] [Support] Simplify setDefaultImpl (NFC) (PR #137528)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 27 10:00:38 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/137528
We can use "constexpr if" to combine the two variants of functions.
>From ea2d0bec1f8a2ea05e22b3227d6e28672a24d966 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 27 Apr 2025 09:08:44 -0700
Subject: [PATCH] [Support] Simplify setDefaultImpl (NFC)
We can use "constexpr if" to combine the two variants of functions.
---
llvm/include/llvm/Support/CommandLine.h | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h
index 5d60bb64bbb20..4c9f5bae87759 100644
--- a/llvm/include/llvm/Support/CommandLine.h
+++ b/llvm/include/llvm/Support/CommandLine.h
@@ -1459,18 +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());
+ template <class T> void setDefaultImpl() {
+ if constexpr (std::is_assignable_v<T &, T>) {
+ const OptionValue<DataType> &V = this->getDefault();
+ if (V.hasValue())
+ this->setValue(V.getValue());
+ else
+ this->setValue(T());
+ }
}
- template <class T, class = std::enable_if_t<!std::is_assignable_v<T &, T>>>
- void setDefaultImpl(...) {}
-
void setDefault() override { setDefaultImpl<DataType>(); }
void done() {
More information about the llvm-commits
mailing list