I am sure there is a good reason for that, but why is the "optional reference" not simply a pointer? Is that not semantically the same thing, but way easier to deal with.
Yes, but Nullable semantics in C# are vastly nicer than std::optional in C++.
Including trivially using if with them:
if (Method() is {} value)
I should also point out that in C#, Foo? is identical to Foo if Foo is a reference-type. That would be the equivalent of std::optional<T&> being a type-alias for T*.
13
u/bartgrumbel 5d ago
I am sure there is a good reason for that, but why is the "optional reference" not simply a pointer? Is that not semantically the same thing, but way easier to deal with.
I.e. why
and not simply