Boost C++ Libraries: Ticket #11192: boost::future<>::then() with an executor doesn't compile when the callback returns a future https://svn.boost.org/trac10/ticket/11192 <p> As noted in the title, when the scheduler overload of <code>boost::future&lt;&gt;::then()</code> is used, and the callback given returns a future, the code doesn't compile. </p> <p> I'm observing this behavior using Boost 1.58 beta 1. </p> <p> The minimal code to reproduce: </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#define BOOST_THREAD_VERSION 4</span> <span class="cp">#define BOOST_THREAD_PROVIDES_EXECUTORS</span> <span class="cp">#include</span> <span class="cpf">&lt;boost/thread.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/thread/executor.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/thread/thread_pool.hpp&gt;</span><span class="cp"></span> <span class="n">boost</span><span class="o">::</span><span class="n">future</span><span class="o">&lt;</span><span class="kt">void</span><span class="o">&gt;</span> <span class="n">p</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">future</span><span class="o">&lt;</span><span class="kt">void</span><span class="o">&gt;</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="n">boost</span><span class="o">::</span><span class="n">make_ready_future</span><span class="p">();</span> <span class="p">}</span> <span class="kt">int</span> <span class="n">main</span><span class="p">()</span> <span class="p">{</span> <span class="c1">// compiles</span> <span class="n">boost</span><span class="o">::</span><span class="n">make_ready_future</span><span class="p">().</span><span class="n">then</span><span class="p">(</span><span class="o">&amp;</span><span class="n">p</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">basic_thread_pool</span> <span class="n">executor</span><span class="p">;</span> <span class="c1">// doesn&#39;t compile</span> <span class="n">boost</span><span class="o">::</span><span class="n">make_ready_future</span><span class="p">().</span><span class="n">then</span><span class="p">(</span><span class="n">executor</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">p</span><span class="p">);</span> <span class="p">}</span> </pre></div></div><p> I'm getting the following error messages when compiling with GCC 4.9.2: </p> <pre class="wiki">In file included from /usr/include/boost/thread.hpp:24:0, from example.cpp:4: /usr/include/boost/thread/future.hpp: In instantiation of 'boost::future&lt;Rp&gt; boost::detail::make_future_executor_continuation_shared_state(Ex&amp;, boost::unique_lock&lt;boost::mutex&gt;&amp;, F&amp;&amp;, Fp&amp;&amp;) [with Ex = boost::executors::basic_thread_pool; F = boost::future&lt;void&gt;; Rp = boost::future&lt;void&gt;; Fp = boost::future&lt;void&gt; (*)(boost::future&lt;void&gt;)]': /usr/include/boost/thread/future.hpp:4628:12: required from 'boost::future&lt;typename boost::result_of&lt;F(boost::future&lt;R&gt;)&gt;::type&gt; boost::future&lt;R&gt;::then(Ex&amp;, F&amp;&amp;) [with Ex = boost::executors::basic_thread_pool; F = boost::future&lt;void&gt; (*)(boost::future&lt;void&gt;); R = void; typename boost::result_of&lt;F(boost::future&lt;R&gt;)&gt;::type = boost::future&lt;void&gt;]' example.cpp:18:49: required from here /usr/include/boost/thread/future.hpp:1629:13: error: 'boost::future&lt;boost::future&lt;R&gt; &gt;::future(boost::future&lt;boost::future&lt;R&gt; &gt;::future_ptr) [with R2 = void; boost::future&lt;boost::future&lt;R&gt; &gt;::future_ptr = boost::shared_ptr&lt;boost::detail::shared_state&lt;boost::future&lt;void&gt; &gt; &gt;]' is private BOOST_THREAD_FUTURE(future_ptr a_future): ^ In file included from /usr/include/boost/thread.hpp:24:0, from example.cpp:4: /usr/include/boost/thread/future.hpp:4531:37: error: within this context return BOOST_THREAD_FUTURE&lt;Rp&gt;(h); </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11192 Trac 1.4.3 viboes Fri, 17 Apr 2015 06:13:36 GMT <link>https://svn.boost.org/trac10/ticket/11192#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11192#comment:1</guid> <description> <p> Hrr, I suspect that a friend declaration has been forgotten. </p> </description> <category>Ticket</category> </item> <item> <author>konrad.zemek@…</author> <pubDate>Fri, 17 Apr 2015 15:41:59 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11192#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11192#comment:2</guid> <description> <p> I believe this commit fixes the issue in a proper manner: <a class="ext-link" href="https://github.com/kzemek/thread/commit/60bebc5e8325bf1fcdb3b0ecc586ecccd4200208"><span class="icon">​</span>https://github.com/kzemek/thread/commit/60bebc5e8325bf1fcdb3b0ecc586ecccd4200208</a> </p> <p> It also befriends the nested future specialization with <code>make_shared_future_async_continuation_shared_state</code> and <code>make_shared_future_deferred_continuation_shared_state</code>, as I found that returning a future from <code>shared_future&lt;&gt;::then()</code> also resulted in similar compilation errors. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 17 Apr 2015 16:36:51 GMT</pubDate> <title>owner, status, milestone changed https://svn.boost.org/trac10/ticket/11192#comment:3 https://svn.boost.org/trac10/ticket/11192#comment:3 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">viboes</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.59.0</span> </li> </ul> <p> Thanks for the patch. I've committed a less ambitious change :( <a class="ext-link" href="https://github.com/boostorg/thread/commit/45c9a1d7fd16ab828fe9b6aa48e0ac0670e53b02"><span class="icon">​</span>https://github.com/boostorg/thread/commit/45c9a1d7fd16ab828fe9b6aa48e0ac0670e53b02</a> </p> <p> I will take your changes into account. </p> Ticket viboes Sat, 18 Apr 2015 05:19:20 GMT <link>https://svn.boost.org/trac10/ticket/11192#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11192#comment:4</guid> <description> <p> I have adapted your patch with more missing friend functions </p> <p> <a class="ext-link" href="https://github.com/boostorg/thread/commit/0bed674233a3c94b7254037dc4903961b54eb141"><span class="icon">​</span>https://github.com/boostorg/thread/commit/0bed674233a3c94b7254037dc4903961b54eb141</a> </p> </description> <category>Ticket</category> </item> <item> <author>Konrad Zemek <konrad.zemek@…></author> <pubDate>Tue, 21 Apr 2015 15:57:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11192#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11192#comment:5</guid> <description> <p> Thanks, that worked for me. :) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Thu, 13 Aug 2015 06:58:28 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/11192#comment:6 https://svn.boost.org/trac10/ticket/11192#comment:6 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.59.0</span> → <span class="trac-field-new">Boost 1.60.0</span> </li> </ul> Ticket viboes Wed, 02 Sep 2015 18:08:39 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/11192#comment:7 https://svn.boost.org/trac10/ticket/11192#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> <a class="ext-link" href="https://github.com/boostorg/thread/commit/a3497e1ffceb14318ff09e339a53293926351057"><span class="icon">​</span>https://github.com/boostorg/thread/commit/a3497e1ffceb14318ff09e339a53293926351057</a> </p> Ticket