What are the types of identifiers introduced by structured bindings in C++17?

前端 未结 2 594
小蘑菇
小蘑菇 2021-01-11 16:05

To my knowledge, identifiers introduced by structured bindings in C++17 are in fact references to some \"hidden\" variable. Such that

auto [ a, b ] = std::ma         


        
2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-11 17:03

    To my knowledge, identifiers introduced by structured bindings in C++17 are in fact references to some "hidden" variable.

    If by "reference" you mean the language construct reference, this isn't quite correct. The specifiers in the declaration appertain to the "hidden variable" you speak of. The reference qualifier is optional. The code you presented would be more like this:

    const auto& e = std::make_tuple(1, 2);
    using E = remove_reference_t;
    std::tuple_element<0, E>::type& a = get<0>(e);
    std::tuple_element<1, E>::type& b = get<1>(e);
    

提交回复
热议问题