Note that there are some explanatory texts on larger screens.

plurals
  1. POstd::packaged_task compile error w/ gcc 4.6
    primarykey
    data
    text
    <p>I'm trying to launch a function in a thread using <code>std::packaged_task</code> </p> <pre><code>Query query; /* protobuf object */ /* fill Query object */ std::packaged_task&lt;SearchResults(Query&amp;)&gt; task([](Query&amp; q) -&gt;SearchResults { index::core::Merger merger; return merger.search(q); }); std::future&lt;SearchResults&gt; ftr = task.get_future(); std::thread(std::move(task),query).detach(); </code></pre> <p>Edit2: Updated the code again to fix errors and included the full error message.</p> <p>g++-4.6 (on Ubuntu 10.04) is unable to compile the code: </p> <pre><code>In file included from /usr/include/c++/4.6/memory:80:0, from ../src/net/QueryConnection.cpp:8: /usr/include/c++/4.6/functional: In instantiation of ‘std::_Bind_result&lt;void, std::packaged_task&lt;SearchResults(Query&amp;)&gt;(Query)&gt;’: /usr/include/c++/4.6/thread:135:9: instantiated from ‘std::thread::thread(_Callable&amp;&amp;, _Args&amp;&amp; ...) [with _Callable = std::packaged_task&lt;SearchResults(Query&amp;)&gt;, _Args = {Query&amp;}]’ ../src/net/QueryConnection.cpp:77:36: instantiated from here /usr/include/c++/4.6/functional:1365:7: error: ‘std::_Bind_result&lt;_Result, _Functor(_Bound_args ...)&gt;::_Bind_result(const std::_Bind_result&lt;_Result, _Functor(_Bound_args ...)&gt;&amp;) [with _Result = void, _Functor = std::packaged_task&lt;SearchResults(Query&amp;)&gt;, _Bound_args = {Query}, std::_Bind_result&lt;_Result, _Functor(_Bound_args ...)&gt; = std::_Bind_result&lt;void, std::packaged_task&lt;SearchResults(Query&amp;)&gt;(Query)&gt;]’ declared to take const reference, but implicit declaration would take non-const Build error occurred, build is stopped </code></pre> <p>I've read that this is maybe due to a bug: <a href="http://www.mailinglistarchive.com/html/gcc-help@gcc.gnu.org/2011-11/msg00090.html" rel="nofollow">gcc-mailinglist</a></p> <p>I'm new to C++ / C++11 - What would be a good working alternative? I just need to launch a thread that gives me a future, whom <code>get()</code>-method is called later in an <code>boost::asio</code> async loop. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload