title: What are use cases for structured bindings?
body: <p>C++17 standard introduces a new <a href="http://en.cppreference.com/w/cpp/language/structured_binding" rel="noreferrer">structured bindings</a> feature, which was initially <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0144r0.pdf" rel="noreferrer">proposed</a> in 2015 and whose syntactic appearance was widely <a href="https://stackoverflow.com/questions/40333000/why-do-c17-structured-bindings-not-use">discussed</a> later.</p>
  
  <p>Some uses for them come to mind as soon as you look through documentation.</p>
  
  <p><strong>Aggregates decomposition</strong></p>
  
  <p>Let's declare a tuple:</p>
  
  <pre><code>std::tuple&lt;int, std::string&gt; t(42, "foo");
  </code></pre>
  
  <p>Named elementwise copies may be easily obtained with structured bindings in one line:</p>
  
  <pre><code>auto [i, s] = t;
  </code></pre>
  
  <p>which is equivalent to:</p>
  
  <pre><code>auto i = std::get&lt;0&gt;(t);
  auto s = std::get&lt;1&gt;(t);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>int i;
  std::string s;
  std::tie(i, s) = t;
  </code></pre>
  
  <p>References to tuple elements can also be obtained painlessly:</p>
  
  <pre><code>auto&amp; [ir, sr] = t;
  const auto&amp; [icr, scr] = t;
  </code></pre>
  
  <p>So we can do with arrays or structs/classes whose all members are public.</p>
  
  <p><strong>Multiple return values</strong></p>
  
  <p>A convenient way to get multiple return values from a function immediately follows from the above.</p>
  
  <p><strong>What else?</strong></p>
  
  <p>Can you provide some other, possibly less obvious use cases for structured bindings? How else can they improve readability or even performance of C++ code?</p>
  
  <p><strong>Notes</strong></p>
  
  <p>As it were mentioned in comments, current implementation of structured bindings lacks some features. They are non-variadic and their syntax does not allow to skip aggregate members explicitly. <a href="https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/CcOGSKEoQa0" rel="noreferrer">Here</a> one can find a discussion about variadicity.</p>