title: How to pass struct elements to asynchronous threads?
body: <p>I am trying to launch a function threaded using <code>launch::async</code>. However, I noticed that this doesn't work when passing struct elements as parameter:<br>
  The code</p>
  
  <pre><code>#include &lt;future&gt;
  #include &lt;vector&gt;
  #include &lt;thread&gt;
  
  struct example { int ten; };
  
  void threadFunction(int number, std::string hi) { 
     printf("%s Your number is %d\n", hi.c_str(), number + 1);
  }
  
  int main() {
     example ex;
     ex.ten = 9;
     std::string someString = "Hi there!";
     std::vector&lt; std::future&lt; void &gt; &gt; threads(5);
     for (uint16_t s = 0; s &lt; 5; s += 1) {
        threads[s] = async(std::launch::async,
                                     [ex.ten,
                                     someString] {
           threadFunction(ex.ten, someString);
        });
     }
  }
  </code></pre>
  
  <p>gives the following errors:</p>
  
  <pre><code>file.cpp: In function ‘int main()’:
  file.cpp:25:39: error: expected ‘,’ before ‘.’ token
                                      [ex.ten,
                                         ^
  file.cpp:25:39: error: expected identifier before ‘.’ token
  file.cpp:25:43: error: expected ‘]’ before ‘,’ token
                                      [ex.ten,
                                             ^
  file.cpp: In lambda function:
  file.cpp:25:43: error: expected ‘{’ before ‘,’ token
  file.cpp: In function ‘int main()’:
  file.cpp:26:46: error: expected ‘)’ before ‘]’ token
                                      someString] {
                                                ^
  file.cpp:28:8: error: expected primary-expression before ‘)’ token
         });
  </code></pre>
  
  <p>When replacing <code>ex.ten</code> with some other variable <code>ten</code> it does work.  </p>
  
  <p>So my questions are:<br>
     1. Why does launch::async not work with struct elements?<br>
     2. Is there a way to do it in a more elegant way than to make a variable for each element in the struct and pass those variables instead? (such as <code>int ten = ex.ten;</code> etc)</p>