C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Forget forget let's redact

From: Jonathan Grant <jgrantonline_at_[hidden]>
Date: Sat, 22 Aug 2026 17:50:58 +0100
On 22/08/2026 08:18, Ted Lyngmo via Std-Proposals wrote:
> 2026-08-17 02:12, Henry Skoglund:
>> Hi, I reread all replies to my previous "forget" post, I think I'm smarter now :-)
>> Here's my new take: let's introduce a std::redact() primarily for safety reasons:
>> void f()
>> {
>> int a = 42;
>> int b = 41;
>> b = std::move(a);
>> std::redact(a);
>> int c = a; // <--- error: a is redacted, cannot be used
>> }
> If we get std::redact, wouldn't we also want std::unredact to be able to still clear() variables in a valid but unspecified state?
>
> for(std::string line; std::getline(std::cin, line);) {
> vec.push_back(std::move(line));
> std::redact(line);
>
> // ... line unusable here ...
>
> std::unredact(line);
> line.clear();
> }

Yes, this feels suitable.

And it can be compile-time, preventing any access until it is std::unredact()
I did this in my Forget example.

Regards
Jonathan



>
> For ergonomics, I'd prefer an inferface where redact returns std::remove_reference_t<T>&& like std::move and unredact returns T& so that one could do:
>
> for(std::string line; std::getline(std::cin, line);) {
> vec.push_back(std::redact(line));
>
> // ... line unusable here ...
>
> std::unredact(line).clear();
> }
>
> Br,
> Ted

Received on 2026-08-22 16:51:07