c++c++17language-lawyerstructured-bindings

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


Solution

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