Hi.
```
The motivation of this proposal is to make this language more logically consistent and complete. As stated in the PDF, programmers can start the lifetime of a variable wherever they wish within a function, but cannot terminate it at the point they desire. This
constitutes a form of incompleteness. And in practice, I use the work arround method a lot to use temporily variables in my own code. But I think they are ugly.
|
发件人:Jeremy Rifkin via Std-Proposals
<std-proposals@lists.isocpp.org>
发件时间:2025年12月11日 00:01
收件人:std-proposals
<std-proposals@lists.isocpp.org>
抄送:Jeremy Rifkin
<jeremy@rifkin.dev>
主题:Re: [std-proposals] [PXXXXR0] Add a New Keyword `undecl`
|
Hi,
It is extremely unlikely something like this would ever be added to C++. Such a change would require a lot of motivation, and this paper doesn't currently provide much motivation.
If the motivation is reusing the name, consider what rust has done with shadowing:
let x = foo();
let x = x.transform(); // new x shadows old x, can be a new type
There is precedent for this mechanism in C++ now with P2169.
If the motivation is compiler optimization, this is a micro-optimization and would be harmful as a language feature. Compilers can very easily identify when objects in a function are dead and reclaim storage and registers.
If the motivation is ending an object's lifetime as far as the C++ abstract machine is concerned and calling destructors, just use std::optional:
std::optional<T> thing;
...
thing.reset(); // destroy the object, call the destructor
This is much more simple and straightforward to reason about than the language feature you're proposing. If you are concerned about the overhead from the flag std::optional stores to indicate if a value is contained or not, this is
something compilers should be able to optimize with relative ease, though the overhead would be completely negligible in almost all cases even if it didn't.
Cheers,
Jeremy
see attachment
--
Std-Proposals mailing list
Std-Proposals@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals