Opened 10 years ago

Closed 10 years ago

#8101 closed Bugs (fixed)

coroutine's iterator doesn't have postfix ++ operator

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

Description

The following code fails to compile:

#include <iostream>
#include <iterator>
#include <boost/coroutine/coroutine.hpp>
#include <boost/range/algorithm/copy.hpp>

typedef boost::coroutines::coroutine<int()> coro_t;

void foo(coro_t::caller_type& caller)
{
    caller(0);
    caller(1);
    caller(2);
}

coro_t f()
{
    return coro_t(&foo);
}

int main()
{
    boost::copy(f(), std::ostream_iterator<int>(std::cout, "\n"));
}

The reason is that std::copy (which is called by boost::copy) uses the postfix version of the iterator's increment operator, but the coroutine's iterator only provides the prefix version.

One way to write an iterator class that satisfies all the iterator interface requirements with minimal work is to use iterator_facade (http://www.boost.org/doc/libs/1_53_0/libs/iterator/doc/iterator_facade.html).

Change History (1)

comment:1 by olli, 10 years ago

Resolution: fixed
Status: newclosed

fixed for input-iterators only

Note: See TracTickets for help on using tickets.