C++ Logo

std-proposals

Advanced search

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

From: Breno Guimarães <brenorg_at_[hidden]>
Date: Tue, 29 Apr 2025 08:06:03 -0300
When they are of the same type you can do:

auto it = vec.begin(), itt = std::next(vec.begin()); it != vec.end() ...

Em ter., 29 de abr. de 2025, 07:44, Aurelien Cassagnes via Std-Proposals <
std-proposals_at_[hidden]> escreveu:

> There is a fairly arbitrary (unless I missed an important argument)
> limitation on initialization clause for if statements.
>
> - I have that
> if (auto it = vec.begin(); it != vec.end()) {
>
> - I want this
> if (auto it = vec.begin() /*and*/ auto itt = ++vec.begin(); it !=
> vec.end() && it != itt) {
>
> So you end up using one of the workarounds, which are somewhat hacky imo :/
>
> I'd like to release that restriction and have for example
> if ({
> auto it = vec.begin();
> auto itt = ++vec.begin();
> }; it != vec.end() && it != itt) {
>
> which can be desugared (desugarified ?) to e.g.
> {
> auto it = vec.begin();
> auto itt = vec.begin();
> if (it != vec.end()) {
> }
> }
>
> Colleague pointed me to a GCC expression statements extension which
> ?maybe? makes `if ({` ambiguous to parse, so I would have to look into that
> too…
>
> Is there any current proposal that aims to lift that restriction ?
> Cheers.
>
> Sent from Gmail Mobile
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2025-04-29 11:06:16