Boost C++ Libraries: Ticket #7988: [Coroutine] Support for C++11 range-for is missing https://svn.boost.org/trac10/ticket/7988 <p> Using a snapshot of the upcoming GCC 4.8 release and Boost 1.53, the following does not compile: </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;boost/coroutine/all.hpp&gt;</span><span class="cp"></span> <span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> <span class="k">using</span> <span class="n">coro</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">coroutines</span><span class="o">::</span><span class="n">coroutine</span><span class="o">&lt;</span><span class="kt">int</span><span class="p">()</span><span class="o">&gt;</span><span class="p">;</span> <span class="k">for</span><span class="p">(</span><span class="kt">int</span> <span class="nl">i</span><span class="p">:</span> <span class="n">coro</span> <span class="p">{</span> <span class="p">[](</span><span class="n">coro</span><span class="o">::</span><span class="n">caller_type</span><span class="o">&amp;</span> <span class="n">yield</span><span class="p">)</span> <span class="p">{</span> <span class="n">yield</span><span class="p">(</span><span class="mi">42</span><span class="p">);</span> <span class="p">}</span> <span class="p">})</span> <span class="p">{</span> <span class="c1">// unused</span> <span class="k">static_cast</span><span class="o">&lt;</span><span class="kt">void</span><span class="o">&gt;</span><span class="p">(</span><span class="n">i</span><span class="p">);</span> <span class="p">}</span> <span class="p">}</span> </pre></div></div><p> As far as I can tell, this is because while Boost.Coroutine does provide functionality for e.g. boost::begin(c) and boost::end(c), it does not provide for the similar, ADL-enabled uses like begin(c) and end(c), where begin and end are in scope. </p> <p> As it so happens, boost::begin and boost::end do ADL on behalf of the users -- their Standard counterparts do not, and a range-for statement is specified to make use of unqualified calls to begin and end. </p> <p> To substantiate my hypothesis, adding begin and end function templates in e.g. namespace boost::coroutines does appear to make the previous snippet compile, and more involved examples behave as expected. </p> <div class="wiki-code"><div class="code"><pre><span class="c1">// Try adding this:</span> <span class="k">namespace</span> <span class="n">boost</span> <span class="p">{</span> <span class="k">namespace</span> <span class="n">coroutines</span> <span class="p">{</span> <span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">Sig</span><span class="o">&gt;</span> <span class="k">auto</span> <span class="n">begin</span><span class="p">(</span><span class="n">coroutine</span><span class="o">&lt;</span><span class="n">Sig</span><span class="o">&gt;&amp;</span> <span class="n">c</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="k">decltype</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">begin</span><span class="p">(</span><span class="n">c</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">begin</span><span class="p">(</span><span class="n">c</span><span class="p">);</span> <span class="p">}</span> <span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">Sig</span><span class="o">&gt;</span> <span class="k">auto</span> <span class="n">end</span><span class="p">(</span><span class="n">coroutine</span><span class="o">&lt;</span><span class="n">Sig</span><span class="o">&gt;&amp;</span> <span class="n">c</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="k">decltype</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">end</span><span class="p">(</span><span class="n">c</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">end</span><span class="p">(</span><span class="n">c</span><span class="p">);</span> <span class="p">}</span> <span class="p">}</span> <span class="p">}</span> </pre></div></div> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7988 Trac 1.4.3 Michel Morin Wed, 06 Feb 2013 14:53:02 GMT component changed; owner set https://svn.boost.org/trac10/ticket/7988#comment:1 https://svn.boost.org/trac10/ticket/7988#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">olli</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">coroutine</span> </li> </ul> Ticket olli Wed, 06 Feb 2013 17:02:11 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/7988#comment:2 https://svn.boost.org/trac10/ticket/7988#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket anonymous Thu, 03 Apr 2014 08:47:38 GMT <link>https://svn.boost.org/trac10/ticket/7988#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7988#comment:3</guid> <description> <p> The range-for does not work with Clang 3.4, boost 1.55.0. The unidirectional coroutine example fails to compile, with the following message. </p> <blockquote> <p> error: invalid range expression of type 'boost::coroutines::pull_coroutine&lt;int&gt;'; no viable 'begin' function available </p> </blockquote> <p> For now wrapping with boost::make_iterator_range(my_coro) will solve the problem, but a cleaner solution would be well appreciated. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>olli</dc:creator> <pubDate>Thu, 03 Apr 2014 18:54:58 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7988#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7988#comment:4</guid> <description> <p> fix for clang-c++11 added </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 27 Aug 2014 13:02:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7988#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7988#comment:5</guid> <description> <p> The problem is in fact *not* fixed, see <a class="ext-link" href="http://lists.boost.org/boost-users/2014/08/82815.php"><span class="icon">​</span>http://lists.boost.org/boost-users/2014/08/82815.php</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>olli</dc:creator> <pubDate>Wed, 27 Aug 2014 15:18:12 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7988#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7988#comment:6</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7988#comment:5" title="Comment 5">anonymous</a>: </p> <blockquote class="citation"> <p> The problem is in fact *not* fixed, see <a class="ext-link" href="http://lists.boost.org/boost-users/2014/08/82815.php"><span class="icon">​</span>http://lists.boost.org/boost-users/2014/08/82815.php</a> </p> </blockquote> <p> example/cpp11/asymmetric/fibonacci compiles with gcc-4.8.1, clang-3.4.1, msvc-11 without problems </p> <pre class="wiki">b2 toolset=gcc cxxflags="-std=c++11" b2 toolset=clang cxxflags="-std=c++11" b2 toolset=msvc-11 </pre> </description> <category>Ticket</category> </item> </channel> </rss>