C++ Logo

std-proposals

Advanced search

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

From: David wang <wangjufan_at_[hidden]>
Date: Sun, 12 May 2024 16:06:41 +0800
Tiago Freire <tmiguelf_at_[hidden]> 于2024年5月12日周日 15:14写道:

>
> > The automatic type deduction reduces the verbosity of code which makes
> it easier to work with structured data. If you really like it, you can make
> use of std::tie.
>
> It's not the same thing. You cannot const initialize with a tie.
> auto reduces verbosity but also clarity, reason why it's right out banned
> in many coding standards, and depending on who you ask it is considered bad
> practice.
>

The semantics of structured binding in C++ are to simplify access to
structured data components, so properties should be determined by the
structure itself via type inference to keep the semantics simple.
In other words, bind variables are just aliases for structured data
components, which facilitates compiler optimizations.
The real problem with structured binding is that C++ allows reference-free
binding which breaks the rule which is beneficial to isolate the
bound variables from the original components.

Received on 2024-05-12 08:06:53