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*.
48
u/stilgarpl 5d ago
Optional is monadic, so it's much safer to deal with. You can call it like
inplace_vector.try_push_back(x).or_else(...);