File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
llvm/include/llvm/Support Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -589,6 +589,10 @@ template <typename To, typename From>
589589// ValueIsPresent
590590// ===----------------------------------------------------------------------===//
591591
592+ template <typename T>
593+ constexpr bool IsNullable =
594+ std::is_pointer_v<T> || std::is_constructible_v<T, std::nullptr_t >;
595+
592596// / ValueIsPresent provides a way to check if a value is, well, present. For
593597// / pointers, this is the equivalent of checking against nullptr, for Optionals
594598// / this is the equivalent of checking hasValue(). It also provides a method for
@@ -610,9 +614,10 @@ template <typename T> struct ValueIsPresent<std::optional<T>> {
610614 static inline decltype (auto ) unwrapValue(std::optional<T> &t) { return *t; }
611615};
612616
613- // Specialization for types convertible to bool.
617+ // If something is "nullable" then we just cast it to bool to see if it exists .
614618template <typename T>
615- struct ValueIsPresent <T, std::enable_if_t <std::is_constructible_v<bool , T>>> {
619+ struct ValueIsPresent <
620+ T, std::enable_if_t <IsNullable<T> && std::is_constructible_v<bool , T>>> {
616621 using UnwrappedType = T;
617622 static inline bool isPresent (const T &t) { return static_cast <bool >(t); }
618623 static inline decltype (auto ) unwrapValue(T &t) { return t; }
You can’t perform that action at this time.
0 commit comments