C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Multiple init in if-statements

From: Jan Schultke <janschultke_at_[hidden]>
Date: Tue, 29 Apr 2025 13:35:12 +0200
Once you need to initialize multiple variables in an if statement, it's
really hard to justify cramming them into the statement itself. Remember
that you could simply write

{
    auto it = vec.begin();
    auto itt = vec.begin();
    if (it != vec.end()) { }
}

... and there's nothing particularly wrong with this. I find this much more
readable than the alternative you've suggested.

Received on 2025-04-29 11:35:30