[llvm] [ADT] Specialize ValueIsPresent for PointerUnion (PR #121847)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 8 17:16:32 PST 2025
================
@@ -614,12 +610,11 @@ template <typename T> struct ValueIsPresent<std::optional<T>> {
static inline decltype(auto) unwrapValue(std::optional<T> &t) { return *t; }
};
-// If something is "nullable" then we just compare it to nullptr to see if it
-// exists.
+// Specialization for types convertible to bool.
template <typename T>
-struct ValueIsPresent<T, std::enable_if_t<IsNullable<T>>> {
+struct ValueIsPresent<T, std::enable_if_t<std::is_constructible_v<bool, T>>> {
----------------
s-barannikov wrote:
> But this enable_if guards both `isPresent` and `unwrapValue` -- don't we need extra care for the latter?
Maybe, although constructibility from nullptr_t doesn't guarantee that the default implementation of unwrapValue would fit.
As I noted in the other comment, I think it would be best if we provided explicit specializations for each type like we do with `simplify_type`, for example. Possibly provide a generic one for `T *`, too. I would't commit myself to implementing this though, I've already shown my expertise in metaprogramming.
https://github.com/llvm/llvm-project/pull/121847
More information about the llvm-commits
mailing list