Subject: [Boost-bugs] [Boost C++ Libraries] #8023: Error using iterator traits with coroutine iterator
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-02-10 05:39:45
#8023: Error using iterator traits with coroutine iterator
-------------------------------------+--------------------------------------
Reporter: nathanridge | Owner: olli
Type: Bugs | Status: new
Milestone: To Be Determined | Component: coroutine
Version: Boost Development Trunk | Severity: Problem
Keywords: |
-------------------------------------+--------------------------------------
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.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/8023> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:12 UTC