Boost C++ Libraries: Ticket #8024: Unable to create const_iterator for coroutine https://svn.boost.org/trac10/ticket/8024 <p> It seems to be impossible to create a const_iterator for a coroutine. For example, the following fails to compile: </p> <pre class="wiki">#include &lt;boost/coroutine/coroutine.hpp&gt; typedef boost::coroutines::coroutine&lt;int()&gt; coroutine_type; void f(coroutine_type::caller_type&amp; c) {} int main() { coroutine_type c(f); coroutine_type::const_iterator it = boost::begin(c); } </pre><p> with the error: </p> <pre class="wiki">test.cpp: In function 'int main()': test.cpp:10:55: error: conversion from 'boost::range_iterator&lt;boost::coroutines::coroutine&lt;int()&gt; &gt;::type {aka boost::coroutines::detail::coroutine_op&lt;int(), boost::coroutines::coroutine&lt;int()&gt;, int, 0&gt;::iterator}' to non-scalar type 'boost::coroutines::detail::coroutine_op&lt;int(), boost::coroutines::coroutine&lt;int()&gt;, int, 0&gt;::const_iterator' requested </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8024 Trac 1.4.3 olli Thu, 14 Feb 2013 10:27:53 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/8024#comment:1 https://svn.boost.org/trac10/ticket/8024#comment:1 <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> <p> small fix in code but use 'boost::const_begin()' to create an const_iterator, please </p> Ticket Nathan Ridge Mon, 18 Feb 2013 05:55:31 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/8024#comment:2 https://svn.boost.org/trac10/ticket/8024#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> <p> What I'm really trying to get to work is code like the following: </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;boost/coroutine/coroutine.hpp&gt; typedef boost::coroutines::coroutine&lt;int()&gt; coro_t; void foo(coro_t::caller_type&amp; caller) { caller(0); caller(1); caller(2); } coro_t f() { return coro_t(&amp;foo); } template &lt;typename Range&gt; void print_range(const Range&amp; range) { for (auto element : range) std::cout &lt;&lt; element; } int main() { print_range(f()); } </pre><p> The C++11 range-based for loop requires either that the range type have a member function named 'begin', or that there exist a non-member function named 'begin' that is found by argument-dependent lookup (i.e. in the same namespace as the range type). In either case, the 'begin' function should have a const version that returns a const iterator. </p> <p> What that translates to for coroutines is that either coroutine needs to have a member function with the signature "begin() const" or there needs to be a non-member function named "begin" in "boost::coroutines" that takes a "const coroutine&amp;" parameter. (And of course the same for 'end'). </p> Ticket olli Mon, 18 Feb 2013 15:58:35 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/8024#comment:3 https://svn.boost.org/trac10/ticket/8024#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> fixed for C++11 too </p> Ticket