Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Однократный вызов кода (как создание static переменных) #579

Open
IvanK-work opened this issue Sep 15, 2023 · 1 comment

Comments

@IvanK-work
Copy link

Если мы можем сказать компилятору - "создай эту переменную только один раз, как только мы дошли до этого места", почему бы на не сказать ему - "выполни этот код один раз, как только мы дошли до этого места".

До:

bool is_call_first_time=true;
void foo()
{
   if(is_call_first_time)
   {
       // code...
      is_call_first_time = false;
   }
....
....

}

После:

void foo()
{
  static{
       // code...
   };
....
....
}

```
@sergii-rybin-tfs
Copy link

std::call_once ?
https://en.cppreference.com/w/cpp/thread/call_once

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants