structured-bindings

structured binding with [[maybe_unused]]

喜欢而已 提交于 2019-11-26 17:46:47
问题 Functional languages with pattern matching (sometimes?) have the possibility to ignore some bound values, but with C++17 structured bindings there seem to be no way to do that (std::ignore with structured bindings?). The advice is to use a dummy name, but then we'll get warnings about unused variables. With the latest heads of both clang and gcc, this does the expected thing, which is nice and useful, [[maybe_unused]] auto x =4 ; // fine, no warning [[maybe_unused]] auto [a,dummyb,dummyc] =

Lambda implicit capture fails with variable declared from structured binding

怎甘沉沦 提交于 2019-11-26 14:26:43
问题 With the following code, I get a compile error C2065 'a': undeclared identifier (using visual studio 2017): [] { auto [a, b] = [] {return std::make_tuple(1, 2); }(); auto r = [&] {return a; }(); //error C2065 }(); However, the following code compiles: [] { int a, b; std::tie(a, b) = [] {return std::make_tuple(1, 2); }(); auto r = [&] {return a; }(); }(); I thought that the two samples were equivalent. Is it a compiler bug or am I missing something ? 回答1: Core issue 2313 changed the standard

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

陌路散爱 提交于 2019-11-26 11:25:35
问题 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: #include <tuple> #include <type_traits> int main() { auto tup = std::make_tuple(1, 2); auto & [ a, b ] = tup; // the following line won\'t compile for a isn\'t a reference // static_assert(std::is_reference_v<decltype(a)>); } In this case decltype(a) is int (probably) because of this bullet (working draft): if e is an unparenthesized id-expression