structured bindings: when something looks like a reference and behaves similarly to a reference, but it's not a reference

后端 未结 2 799
情话喂你
情话喂你 2020-11-30 10:13

Yesterday I\'ve seen an interesting question here on SO about structured binding.
We can sum up it as it follows. Consider the example code below:

#inclu         


        
2条回答
  •  情书的邮戳
    2020-11-30 10:17

    I wrote this yesterday:

    decltype(x), where x is a structured binding, names the referenced type of that structured binding. In the tuple-like case, this is the type returned by std::tuple_element, which may not be a reference even though the structured binding itself is in fact always a reference in this case. This effectively emulates the behavior of binding to a struct whose non-static data members have the types returned by tuple_element, with the referenceness of the binding itself being a mere implementation detail.

提交回复
热议问题