Date: Sat, 15 Feb 2025 22:42:48 +0000
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_hpkfft.com>
Sent: Saturday, February 15, 2025 11:27 PM
To: std-proposals_at_[hidden]rg
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;
}();
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_hpkfft.com>
Sent: Saturday, February 15, 2025 11:27 PM
To: std-proposals_at_[hidden]rg
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;
}();
Received on 2025-02-15 22:42:51