C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Structured binding without type inference

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Sun, 12 May 2024 10:05:48 +0200
That is the question for that proposal:   Would the stated types just be for compile-time checking the return types? (And for better explicit source code annotation.)   Or could the types (also) 'override' the returned types and enable to process implicit conversions and individually store in a const?   Currently structured bindings define aliases similar to references to the elements of the returned type. Changing the type with implicit conversions, which generally could change the bit representation and size of the type, would introduce additional copies or constructor calls, whereas currently the original object can be used or RVO, if a function is called.   How about specifying the types on the RHS of the equation? Something like   auto [a, b] = std::pair<float, int>(f());   With f() returning std::pair<int, int> or std::pair<float, int>? Leading to implicit conversions in one case and not in the other?   -----Ursprüngliche Nachricht----- Von:Jan Schultke via Std-Proposals <std-proposals_at_[hidden]> Gesendet:So 12.05.2024 09:34 Betreff:Re: [std-proposals] Structured binding without type inference An:C++ Proposals <std-proposals_at_[hidden]>; CC:Jan Schultke <janschultke_at_[hidden]>; The proposed syntax is a bit misleading because the type is still a std::pair, not an int. Something like what Tiago wrote would make sense, where you can specify a type per bound name.  However, I don't think implicit conversions would be appropriate here, so the rules would be different from a variable in the sense that you would always need to specify the type exactly. That also makes this whole thing a bit less powerful and useful though. On Sat, May 11, 2024, 08:59 Oliver Schädlich via Std-Proposals <std-proposals_at_[hidden] <mailto:std-proposals_at_[hidden]> > wrote: If all variables of a structured binding are the same I think structured binding without type inference would improve the readability.     pair<int, int> pii;     int &[a, b] = pii; Or:     pair<int, char> pic;     int [a, b] = pic;     -- Std-Proposals mailing list Std-Proposals_at_[hidden] <mailto:Std-Proposals_at_[hidden]> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2024-05-12 08:05:52