C++ Logo

std-proposals

Advanced search

Re: [std-proposals] try else syntax for validity check

From: Filip <fph2137_at_[hidden]>
Date: Tue, 18 Feb 2025 21:56:01 +0100
@Thiago
You’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_at_[hidden]> 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 list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2025-02-18 20:56:15