C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Tue, 29 Apr 2025 08:18:58 -0700
On Tuesday, 29 April 2025 04:35:12 Pacific Daylight Time Jan Schultke via Std-
Proposals wrote:
> {
> 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.

Coding-style-wise, I would ask anyone in a code review to move the
initialisation to before the if statement if the complexity of the
initialisation would make the if statement too long. That means two
initialisations in the if would need to be very short and simple to be
allowable in the context in the first place. Is that worth a core language
change?

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering

Received on 2025-04-29 15:19:01