-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[ADT] Fix specialization of ValueIsPresent for PointerUnion #121847
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
Changes from 1 commit
107a35d
f833dff
13a9098
8abd5cd
294c617
62157bf
0546ba3
f0140f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -589,10 +589,6 @@ template <typename To, typename From> | |
| // ValueIsPresent | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| template <typename T> | ||
| constexpr bool IsNullable = | ||
| std::is_pointer_v<T> || std::is_constructible_v<T, std::nullptr_t>; | ||
|
|
||
| /// ValueIsPresent provides a way to check if a value is, well, present. For | ||
| /// pointers, this is the equivalent of checking against nullptr, for Optionals | ||
| /// this is the equivalent of checking hasValue(). It also provides a method for | ||
|
|
@@ -614,9 +610,9 @@ 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 cast it to bool 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>>> { | ||
|
||
| using UnwrappedType = T; | ||
| static inline bool isPresent(const T &t) { return static_cast<bool>(t); } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're going down this route, it would probably make sense to also change the enable_if to check std::is_convertible<T, bool> instead? I think you could also drop the separate std::optional specialization because it also has operator bool.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think it will make much more sense, will try.
They are not quite the same, the specialization for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It appears |
||
| static inline decltype(auto) unwrapValue(T &t) { return t; } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.