-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[Support] Make shouldReverseIterate constexpr #156812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Support] Make shouldReverseIterate constexpr #156812
Conversation
This patch simplifies shouldReverseIterate with "if constexpr" while switching to "constexpr bool", allowing compile-time evaluation at call sites.
@llvm/pr-subscribers-llvm-support Author: Kazu Hirata (kazutakahirata) ChangesThis patch simplifies shouldReverseIterate with "if constexpr" while Full diff: https://github.com/llvm/llvm-project/pull/156812.diff 1 Files Affected:
diff --git a/llvm/include/llvm/Support/ReverseIteration.h b/llvm/include/llvm/Support/ReverseIteration.h
index 9e9411856369e..456d423600d6e 100644
--- a/llvm/include/llvm/Support/ReverseIteration.h
+++ b/llvm/include/llvm/Support/ReverseIteration.h
@@ -6,13 +6,11 @@
namespace llvm {
-template<class T = void *>
-bool shouldReverseIterate() {
-#if LLVM_ENABLE_REVERSE_ITERATION
- return detail::IsPointerLike<T>::value;
-#else
- return false;
-#endif
+template <class T = void *> constexpr bool shouldReverseIterate() {
+ if constexpr (LLVM_ENABLE_REVERSE_ITERATION)
+ return detail::IsPointerLike<T>::value;
+ else
+ return false;
}
} // namespace llvm
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really a simplification? This is a macro, so I'm not sure what the benefit is. Is it for better IDE/lsp support?
@kuhar Maybe simplification is a wrong word here. Making this function |
You can make it contexpr while still keeping the macro. I'm not saying the new implementation with |
@kuhar I now retain the macro and just make the return type |
This patch makes shouldReverseIterate constexpr, allowing compile-time
evaluation at call sites.