Opened 10 years ago

Closed 10 years ago

#8023 closed Bugs (fixed)

Error using iterator traits with coroutine iterator

Reported by: Nathan Ridge Owned by: olli
Milestone: To Be Determined Component: coroutine
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description

I am getting compiler errors when using std::iterator_traits with a coroutine's iterator type:

#include <boost/coroutine/coroutine.hpp>
#include <boost/iterator/iterator_traits.hpp>

typedef boost::coroutines::coroutine<int()> coroutine_type;
typedef std::iterator_traits<coroutine_type::iterator>::pointer pointer;

The errors are (with gcc 4.7.2):

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<int(), boost::coroutines::coroutine<int()>, int, 0>::iterator':
c++/bits/stl_iterator_base_types.h:143:1:   recursively required from 'constexpr const bool std::__has_iterator_category_helper<boost::coroutines::detail::coroutine_op<int(), boost::coroutines::coroutine<int()>, int, 0>::iterator>::value'
c++/bits/stl_iterator_base_types.h:143:1:   required from 'struct std::__has_iterator_category<boost::coroutines::detail::coroutine_op<int(), boost::coroutines::coroutine<int()>, int, 0>::iterator>'
c++/bits/stl_iterator_base_types.h:160:12:   required from 'struct std::iterator_traits<boost::coroutines::detail::coroutine_op<int(), boost::coroutines::coroutine<int()>, int, 0>::iterator>'
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<boost::coroutines::detail::coroutine_op<int(), boost::coroutines::coroutine<int()>, int, 0>::iterator>'
boost/boost/coroutine/detail/coroutine_op.hpp:85:73: error: no type named 'reference' in 'struct std::iterator_traits<boost::coroutines::detail::coroutine_op<int(), boost::coroutines::coroutine<int()>, int, 0>::iterator>'

The problem is the following typedefs in the iterator class:

typedef typename std::iterator_traits< iterator >::pointer      pointer_t;
typedef typename std::iterator_traits< iterator >::reference    reference_t;

If the iterator class is instantiated in the context of instantiating iterator_traits<iterator>, as is the case in my example code, these typedefs cause a recursive instantiation of iterator_traits<iterator>. In the recursive instantiation, 'iterator' is incomplete, and thus does not have the required members.

A solution is to express the underlying type of these typedefs more directly, for example:

typedef typename iterator::pointer      pointer_t;
typedef typename iterator::reference    reference_t;

The coroutine's const_iterator has a similar problem.

Attached is a patch with the above fix.

Attachments (1)

coroutine-iterator.patch (1.0 KB ) - added by Nathan Ridge 10 years ago.
patch that fixes the problem

Download all attachments as: .zip

Change History (2)

by Nathan Ridge, 10 years ago

Attachment: coroutine-iterator.patch added

patch that fixes the problem

comment:1 by olli, 10 years ago

Resolution: fixed
Status: newclosed

thx

Note: See TracTickets for help on using tickets.