Masquue
Masquue

Reputation: 322

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

Upvotes: 8

Views: 266

Answers (1)

cpplearner
cpplearner

Reputation: 15813

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

Upvotes: 5

Related Questions