C++ Logo

std-proposals

Advanced search

Re: [std-proposals] A new C++ keyword: forget

From: Simon Schröder <dr.simon.schroeder_at_[hidden]>
Date: Wed, 12 Aug 2026 06:48:55 +0200
> On Aug 12, 2026, at 12:41 AM, Henry Skoglund via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> On 2026-08-12 00:33, Ville Voutilainen wrote:
>>> On Wed, 12 Aug 2026 at 01:29, Henry Skoglund <henry_at_[hidden]> wrote:
>>>
>>> Good idea with a std:: prefix, avoids breaking someone's code that has a
>>> type called "forget".
>> Bingo. :)
>>
>>> What about std::redact()?
>> I quite like it. After you redact a name, code that follows it
>> considers the declaration of the name
>> as having been redacted, and can't name or redeclare the thing. The
>> name's earlier declaration
>> is there for cleanup purposes, but for post-redaction naming purposes,
>> it's just sharpied all over.
>>
>> Maybe even better names exist, but that's a very explicable analogy,
>> if you ask me.
>
> Perhaps I should make a new post with std::redact() as the new suggestion.
>
> What do you think about redacting types, namespaces and functions? Is that something to leave for a future exercise, i.e. for now you will only be able to redact variables?

If we want to redact functions as well, I think it should be possible to provide a reason (i.e. a string like in static_assert). This would give better compiler errors. However, in the case of local variables I usually don’t see a need for that.

For variables this brings me to another idea: Currently, even a redacted variable would be destroyed at the end of scope. Mojo decided to destroy variables once they are not used anymore and claims early destruction gives better performance. I’m not suggesting in this context to add the same feature in C++. However, it could be advantageous to explicitly destroy (and forget) a variable early. Rust has ‘drop’ for this. So, maybe alongside ‘redact’ we could also have ‘drop’ where drop will destroy the variable and at the same time redact it.
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2026-08-12 04:49:14