Boost C++ Libraries: Ticket #8023: Error using iterator traits with coroutine iterator https://svn.boost.org/trac10/ticket/8023 <p> I am getting compiler errors when using std::iterator_traits with a coroutine's iterator type: </p> <pre class="wiki"> #include &lt;boost/coroutine/coroutine.hpp&gt; #include &lt;boost/iterator/iterator_traits.hpp&gt; typedef boost::coroutines::coroutine&lt;int()&gt; coroutine_type; typedef std::iterator_traits&lt;coroutine_type::iterator&gt;::pointer pointer; </pre><p> The errors are (with gcc 4.7.2): </p> <pre class="wiki"> In file included from boost/boost/coroutine/coroutine.hpp:31:0, from test.cpp:1: boost/boost/coroutine/detail/coroutine_op.hpp: In instantiation of 'class boost::coroutines::detail::coroutine_op&lt;int(), boost::coroutines::coroutine&lt;int()&gt;, int, 0&gt;::iterator': c++/bits/stl_iterator_base_types.h:143:1: recursively required from 'constexpr const bool std::__has_iterator_category_helper&lt;boost::coroutines::detail::coroutine_op&lt;int(), boost::coroutines::coroutine&lt;int()&gt;, int, 0&gt;::iterator&gt;::value' c++/bits/stl_iterator_base_types.h:143:1: required from 'struct std::__has_iterator_category&lt;boost::coroutines::detail::coroutine_op&lt;int(), boost::coroutines::coroutine&lt;int()&gt;, int, 0&gt;::iterator&gt;' c++/bits/stl_iterator_base_types.h:160:12: required from 'struct std::iterator_traits&lt;boost::coroutines::detail::coroutine_op&lt;int(), boost::coroutines::coroutine&lt;int()&gt;, int, 0&gt;::iterator&gt;' test.cpp:5:55: required from here boost/boost/coroutine/detail/coroutine_op.hpp:84:73: error: no type named 'pointer' in 'struct std::iterator_traits&lt;boost::coroutines::detail::coroutine_op&lt;int(), boost::coroutines::coroutine&lt;int()&gt;, int, 0&gt;::iterator&gt;' boost/boost/coroutine/detail/coroutine_op.hpp:85:73: error: no type named 'reference' in 'struct std::iterator_traits&lt;boost::coroutines::detail::coroutine_op&lt;int(), boost::coroutines::coroutine&lt;int()&gt;, int, 0&gt;::iterator&gt;' </pre><p> The problem is the following typedefs in the iterator class: </p> <pre class="wiki"> typedef typename std::iterator_traits&lt; iterator &gt;::pointer pointer_t; typedef typename std::iterator_traits&lt; iterator &gt;::reference reference_t; </pre><p> If the iterator class is instantiated in the context of instantiating iterator_traits&lt;iterator&gt;, as is the case in my example code, these typedefs cause a recursive instantiation of iterator_traits&lt;iterator&gt;. In the recursive instantiation, 'iterator' is incomplete, and thus does not have the required members. </p> <p> A solution is to express the underlying type of these typedefs more directly, for example: </p> <pre class="wiki"> typedef typename iterator::pointer pointer_t; typedef typename iterator::reference reference_t; </pre><p> The coroutine's const_iterator has a similar problem. </p> <p> Attached is a patch with the above fix. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8023 Trac 1.4.3 Nathan Ridge Sun, 10 Feb 2013 05:40:12 GMT attachment set https://svn.boost.org/trac10/ticket/8023 https://svn.boost.org/trac10/ticket/8023 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">coroutine-iterator.patch</span> </li> </ul> <p> patch that fixes the problem </p> Ticket olli Tue, 12 Feb 2013 19:11:53 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/8023#comment:1 https://svn.boost.org/trac10/ticket/8023#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> thx </p> Ticket