title: Execution policy problem with lambda expression
body: <p>I have this class:</p>
  
  <pre><code>class EMX_Counter {
      private:
          std::vector&lt;std::unique_ptr&lt;WireBase&gt;&gt; WiresList;
      public:
          EMX_Counter(const std::vector&lt;std::unique_ptr&lt;WireBase&gt;&gt;&amp; w) : WiresList(w) {}
          EMX_Counter(std::vector&lt;std::unique_ptr&lt;WireBase&gt;&gt;&amp;&amp; w) : WiresList(std::move(w)) {}
          std::future&lt;std::vector&lt;double&gt;&gt; getEmxEfficiency();
      };
  </code></pre>
  
  <p>The <code>WireBase</code> is an abstract class (not important here how it works) and I need an unique ptr because I need polymorphism. That said, <code>getEmxEfficiency()</code> takes some time because the vector contains at least 28'000 / 30'000 items and one single call to the method is slow.</p>
  
  <p>I have decided to use a parallel approach to speed up and this is the result:</p>
  
  <pre><code>std::future&lt;std::vector&lt;double&gt;&gt; EMX_Counter::getEmxEfficiency()  {
          return std::async([*this]() {
              std::vector&lt;double&gt; temp;               
  
              std::for_each(std::execution::par, WiresList.begin(), WiresList.end(), [&amp;](auto&amp; PolyObject) {
                  double result = PolyObject-&gt;getPartialEfficiency();
                  //more time-expensive operations
                  temp.push_back( result );
              });
  
              return temp;
          });
      }
  </code></pre>
  
  <p>The call <code>PolyObject-&gt;getPartialEfficiency();</code> returns a double and does not throw exceptions, it is "safe".</p>
  
  <hr>
  
  <p>I am using the latest Visual Studio version (updated yesterday) and the flag <code>/std:c++17</code>. The problem is that I get this error:</p>
  
  <pre><code> std::unique_ptr&lt;WireBase,std::default_delete&lt;_Ty&gt;&gt;::unique_ptr(const
   std::unique_ptr&lt;_Ty,std::default_delete&lt;_Ty&gt;&gt; &amp;)': attempting to
   reference a deleted function (file: xmemory0).
  </code></pre>
  
  <ul>
  <li>What could this be?</li>
  <li>I have captured <code>[*this]</code> in the lambda so I have a copy of the object and I am sure (am I?) that there won't be problems with the async execution. Should I capture by value of reference instead?</li>
  </ul>
  
  <p>In the <code>for_each</code> lambda I have captured by reference because temp is in scope and I won't have problems with it being destroyed.</p>