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 22:16:59 +0100
Honestly we could have both ? and ! as operators and_then and or_else respectively, they match pretty well.

In my cases using something akin to try catch would lower the amount of code by a significant number.
Hence I think for others it would do as well, an opt in version.

Initially I wanted to have try else as opposed to try catch to differentiate between them, throwing an exception might be the simplest way.
Maybe it should only throw if try is using appropriate catch, although that might be difficult for the compiler.

I’m open to other syntax, try just seems to be the most meaningful and do is already taken for do while and as far as I know do expressions.

Cheers, Filip

> Wiadomość napisana przez Thiago Macieira <thiago_at_[hidden]> w dniu 18 lut 2025, o godz. 22:07:
>
> On Tuesday, 18 February 2025 17:56:01 Brasilia Standard Time Filip wrote:
>> @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.
>
> A monadic and_then with a terse, core language syntax may be accepted. Lambdas
> are, after all, just a special syntax for declaring a functor. You just need
> to show that this would be useful in a large number of use-cases, simplify
> both reading and writing code, etc.
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Principal Engineer - Intel DCAI Platform & System Engineering
>
>
>

Received on 2025-02-18 21:17:16