C++ Logo

std-proposals

Advanced search

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

From: Tom Honermann <tom_at_[hidden]>
Date: Sun, 12 May 2024 16:14:24 -0400
On 5/12/24 5:16 AM, Lénárd Szolnoki via Std-Proposals wrote:
>
> On 12 May 2024 08:34:01 BST, Jan Schultke via Std-Proposals<std-proposals_at_[hidden]> wrote:
>> 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.
> Maybe you could specify a concept per element.
>
> auto [same_as<int> x, same_as<double> y] = ...

Discussions in the past have suggested using the
/return-type-requirement
<http://eel.is/c++draft/expr.prim.req.compound#nt:return-type-requirement>/
syntax from compound requires expressions for this.

auto [x -> same_as<int>, y -> same_as<double>] = ...

Tom.

>
>> On Sat, May 11, 2024, 08:59 Oliver Schädlich via Std-Proposals <
>> 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]
>>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>>

Received on 2024-05-12 20:14:31