@ThiagoYou’re right about my types using -> with possible throw, I have this problem with foreign API that needs to be checked.
Over time I’ve grown to dislike operator overloading, operator ? might be a good solution here, safe dereference, essentially monadic and_then.
I would like some hard and unchangeable solution only for safety.
Cheers, Filip
Wiadomość napisana przez Thiago Macieira via Std-Proposals <std-proposals@lists.isocpp.org> w dniu 18 lut 2025, o godz. 21:47:
On Tuesday, 18 February 2025 17:43:57 Brasilia Standard Time Thiago Macieira via Std-Proposals wrote:On Tuesday, 18 February 2025 17:42:01 Brasilia Standard Time Filip wrote:
I know that I can throw meaningful exceptions and check every pointer
before dereference. What I want is to help me and others avoid mistaking
one or more dereferences. I believe that this is about safety and
usability, it is easier to write:
try p1->p2->get(0);
catch (nullptr) …
The problem is that this syntax is already permitted and you're asking for
everyone's try blocks to be slower at every pointer that gets dereferenced.
Wouldn't it be better to have a ?-> operator instead?
Actually, this doesn't need a language change. All you need is a library type whose operator-> throws if it is null. Likewise, it would be possible to create a monadic expression that becomes a nullable (or disengaged optional) at the end of the expression.-- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org Principal Engineer - Intel DCAI Platform & System Engineering-- Std-Proposals mailing listStd-Proposals@lists.isocpp.orghttps://lists.isocpp.org/mailman/listinfo.cgi/std-proposals