Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Introduced intermediate variable in structured binding definition?

In [dcl.struct.bind] 9.6.4, there is definition of structured binding when initializer is a class type with std​::​tuple_­size<E>​::​value properly defined:

... variables are introduced with unique names ri as follows:
S Ui ri = initializer ;
Each vi is the name of an lvalue of type Ti that refers to the object bound to ri; the referenced type is Ti.

My question is why is it necessary to introduce ri, can't we define the identifier vi directly as reference to the result of get<i>(e)?

like image 370
Masquue Avatar asked Jun 29 '26 22:06

Masquue


1 Answers

The intent is to disallow redeclaring structured bindings as references. See CWG 2313.

like image 132
cpplearner Avatar answered Jul 01 '26 13:07

cpplearner