Home > Net >  Introduced intermediate variable in structured binding definition?
Introduced intermediate variable in structured binding definition?

Time:03-20

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)?

CodePudding user response:

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

  • Related