C++ Logo

std-proposals

Advanced search

Re: [std-proposals] AI (was: : Re: [PXXXXR0] Add a New Keyword ‘undecl’)

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Thu, 18 Dec 2025 09:00:40 +0000
On Thu, 18 Dec 2025 at 08:20, Kim Eloy <eloy.kim_at_[hidden]> wrote:

> And, I reply to your topic undeclare key word. It's useless, and
> unnecessary. Just as I said, use scope.
> if(true){
> scope variables.
> }
> std:: funtional<void()> task = []()->{
> scope variables.
> };
>


This is useless for the problem that was presented, where the 'data'
variable needs to outlive the 'i' variable:

    auto i = somemap.find(key);
    auto data = i->second.main_info;
    somemap.erase(i);
    undecl i; // this would be really nice
    // go on to use `data`


If you use a new scope, then you can't use 'data' either. So your
suggestion is not helpful. Everybody understands how to use a new scope,
that's not what's being discussed.

Anyway, if you want a new scope, using 'if (true)' or a lambda body is
ridiculous, just create a new block scope:

{ // this creates a new scope
  auto i = somemap.find(key);
  auto data = i->second.main_info;
  somemap.erase(i);
}
// oops, can't use data.

Received on 2025-12-18 09:00:57