<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[std::packaged_task mit Move-only-Typen]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe mit einem aktuellen gcc4.7 -Snapshot das Problem, dass std::packaged_task keine Move-Only-Typen akzeptiert. Ist das ein Bug oder ein &quot;works as designed&quot;?<br />
Im Standard und Netz konnte ich jetzt keine eindeutige, passende Antwort finden.</p>
<p>Danke.</p>
<pre><code class="language-cpp">#include &lt;future&gt;
#include &lt;iostream&gt; 
#include &lt;thread&gt; 

struct Foo
{
 Foo()=default;
 Foo(Foo&amp;&amp;)=default;
 Foo&amp; operator=(Foo &amp;&amp;)=default;
 void operator() () { std::cout &lt;&lt; &quot;Foo called\n&quot;;}
};

int main()
{

 std::thread t{Foo()};  //klappt
 t.join();
 auto fut =std::async(Foo()); //klappt
 fut.wait();
 std::packaged_task&lt;void()&gt; task{Foo()}; //geht nicht
 task();
 return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/299653/std-packaged_task-mit-move-only-typen</link><generator>RSS for Node</generator><lastBuildDate>Thu, 13 Aug 2026 03:19:32 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/299653.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 15 Feb 2012 16:46:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to std::packaged_task mit Move-only-Typen on Wed, 15 Feb 2012 16:46:49 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe mit einem aktuellen gcc4.7 -Snapshot das Problem, dass std::packaged_task keine Move-Only-Typen akzeptiert. Ist das ein Bug oder ein &quot;works as designed&quot;?<br />
Im Standard und Netz konnte ich jetzt keine eindeutige, passende Antwort finden.</p>
<p>Danke.</p>
<pre><code class="language-cpp">#include &lt;future&gt;
#include &lt;iostream&gt; 
#include &lt;thread&gt; 

struct Foo
{
 Foo()=default;
 Foo(Foo&amp;&amp;)=default;
 Foo&amp; operator=(Foo &amp;&amp;)=default;
 void operator() () { std::cout &lt;&lt; &quot;Foo called\n&quot;;}
};

int main()
{

 std::thread t{Foo()};  //klappt
 t.join();
 auto fut =std::async(Foo()); //klappt
 fut.wait();
 std::packaged_task&lt;void()&gt; task{Foo()}; //geht nicht
 task();
 return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2181567</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2181567</guid><dc:creator><![CDATA[einwurf]]></dc:creator><pubDate>Wed, 15 Feb 2012 16:46:49 GMT</pubDate></item><item><title><![CDATA[Reply to std::packaged_task mit Move-only-Typen on Wed, 15 Feb 2012 18:13:15 GMT]]></title><description><![CDATA[<p>Das scheint mir ein Bug im Standard zu sein. In den ursprünglichen Vorschlägen wurde immer eine Kopie des Funktionsobjektes gespeichert, das ist erst relativ <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2027" rel="nofollow">spät</a> geändert worden. Dabei scheint aber zumindest</p>
<blockquote>
<p>30.6.9.1 packaged_task member functions [futures.task.members]<br />
packaged_task() noexcept;<br />
1 Effects: constructs a packaged_task object with no shared state and no stored task.<br />
template &lt;class F&gt;<br />
packaged_task(F&amp;&amp; f);<br />
template &lt;class F, class Allocator&gt;<br />
explicit packaged_task(allocator_arg_t, const Allocator&amp; a, F&amp;&amp; f);<br />
2 Requires: INVOKE(f, t1, t2, ..., tN, R), where t1, t2, ..., tN are values of the corresponding types in ArgTypes..., shall be a valid expression. <strong>Invoking a copy of f shall behave the same as invoking f.</strong></p>
</blockquote>
<p>übersehen worden zu sein. Jedenfalls liest sich das, als ob f CopyConstructible sein müsste, obwohl dafür ansonsten keine Notwendigkeit zu bestehen scheint.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2181601</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2181601</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 15 Feb 2012 18:13:15 GMT</pubDate></item><item><title><![CDATA[Reply to std::packaged_task mit Move-only-Typen on Wed, 15 Feb 2012 19:58:57 GMT]]></title><description><![CDATA[<p>Danke camper.<br />
Muss sich sich dann der Bibliothek-Programmierer strikt an den Standard halten oder kann er auch offensichtliche Bugs im Standard (wenn es denn wirklich einer ist) in der Implementierung geradebiegen?<br />
In jedem Fall muss ich mir für den Augenblick eigene &quot;packaged_task&quot;-Klasse schreiben, welche mir die promise-future-Konstruktion kapselt und auch für Move-Only Typen gilt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2181660</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2181660</guid><dc:creator><![CDATA[einwurf]]></dc:creator><pubDate>Wed, 15 Feb 2012 19:58:57 GMT</pubDate></item></channel></rss>