Date: Sun, 16 Feb 2025 09:50:40 +0100
Perhaps being a bit more explicit in the syntax:
mutable const int x = 0;
if(cond) {
x = 1;
} else {
x = 2;
}
const x;
‘mutable const’ could indicate to both the compiler and the programmer that the const declaration is not finished in a way…
That it will encounter the line in which it stops further modifications of the variable.
Cheers, Filip
> Wiadomość napisana przez Tiago Freire via Std-Proposals <std-proposals_at_[hidden]> w dniu 15 lut 2025, o godz. 23:42:
>
> Ok, granted my example was a bit simple.
> But immediate lambdas are not a solution here.
>
> 1. Think of more complex types, and situations where it is not guaranteed NRVO.
>
> Or
>
> 2. Situations where the interface is closed (or things like third party libraries with object oriented C type interfaces) (example given initialized by passing reference to a function), but you still want to do error handling. Putting that into a lambda may make your error handling more complicated because your return path is now occupied for the purpose of initializing the object you want to make const.
>
>
>
> -----Original Message-----
> From: Paul Caprioli <paul_at_[hidden]>
> Sent: Saturday, February 15, 2025 11:27 PM
> To: std-proposals_at_[hidden]
> Cc: Tiago Freire <tmiguelf_at_[hidden]>
> Subject: RE: [std-proposals] Delayed const declaration
>
>> So a delayed const declaration can only last for the duration of the scope in which they were declared const.
>
> That's a disadvantage compared to using a lambda:
>
> const uint32_t var = [] {
> if (something)
> return 1;
> else
> return 2;
> }();
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
mutable const int x = 0;
if(cond) {
x = 1;
} else {
x = 2;
}
const x;
‘mutable const’ could indicate to both the compiler and the programmer that the const declaration is not finished in a way…
That it will encounter the line in which it stops further modifications of the variable.
Cheers, Filip
> Wiadomość napisana przez Tiago Freire via Std-Proposals <std-proposals_at_[hidden]> w dniu 15 lut 2025, o godz. 23:42:
>
> Ok, granted my example was a bit simple.
> But immediate lambdas are not a solution here.
>
> 1. Think of more complex types, and situations where it is not guaranteed NRVO.
>
> Or
>
> 2. Situations where the interface is closed (or things like third party libraries with object oriented C type interfaces) (example given initialized by passing reference to a function), but you still want to do error handling. Putting that into a lambda may make your error handling more complicated because your return path is now occupied for the purpose of initializing the object you want to make const.
>
>
>
> -----Original Message-----
> From: Paul Caprioli <paul_at_[hidden]>
> Sent: Saturday, February 15, 2025 11:27 PM
> To: std-proposals_at_[hidden]
> Cc: Tiago Freire <tmiguelf_at_[hidden]>
> Subject: RE: [std-proposals] Delayed const declaration
>
>> So a delayed const declaration can only last for the duration of the scope in which they were declared const.
>
> That's a disadvantage compared to using a lambda:
>
> const uint32_t var = [] {
> if (something)
> return 1;
> else
> return 2;
> }();
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2025-02-16 08:50:57