5 ms·
To clarify a question raised in this write-up: "auto [a , b , c] = getvalues(); "The braces are needed, getvalues returns a tuple. std::pair is not mentioned
by squidbidness 10y ago
To clarify a question raised in this write-up:
"auto [a , b , c] = getvalues();
"The braces are needed, getvalues returns a tuple. std::pair is not mentioned in the proposal, so its unclear if this works with pair, which is returned by the STL in some insert methods."
Destructured bindings will work with arrays; plain aggregate structs; and any class that offers a specialization of std::get<>(), so both std::tuple and std::pair are supported as a consequence. (C++11 added std::get<>() for std::pair).
- ant6n 10y agoWhat if the number of lhs values don't match the number of rhs values?
- Kristine1975 10y agoCompile-time error: Otherwise, if the expression std::tuple_size<E>::value is a well-formed integral constant expression, the number of elements in the identifier-list shall be equal to the value of that expression (E is the return type of "getvalues" in squidbidness's example, the initializer-list is "a, b, c".)