You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The comparison of std::optional<not_null<T>> and not_null<T> is ambiguous. This is possibly because they both have overloads of the equality operator on their "nullable" types, which are of equal precedence.
I have yet to come up with a convincing approach to solve this problem; suggestions are welcome. We might be tempted to follow MS-GSL and only define comparison operators for two not_null<> arguments (link) rather than the set of mixed-argument overloads we have now (link); but the simpler approach is fraught with other problems: for example, comparing std::shared_ptr<T> and not_null<std::shared_ptr<T>> then fails, whereas it works fine with gsl-lite. (Repro for MS-GSL, gsl-lite.)
As an aside, isn't optional<not_null<T>> just a contrived semantic equivalent of T?
As an aside, isn't optional<not_null> just a contrived semantic equivalent of T?
Yeah, kinda. But when designing generic types / interfaces with value semantics, this issue adds some mental overhead. The pattern is used frequently in Rust, with Option<Box<T>> which is equivalently optional<not_null<T*>>.
The comparison of
std::optional<not_null<T>>
andnot_null<T>
is ambiguous. This is possibly because they both have overloads of the equality operator on their "nullable" types, which are of equal precedence.Here's a minimal example to repro: https://godbolt.org/z/xnEfP1acb
It should be noted that
Microsoft/GSL
doesn't have this issue: https://godbolt.org/z/Ed7qG5EE8The text was updated successfully, but these errors were encountered: