Modify

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#11234 closed Bugs (wontfix)

boost::asymmetric_coroutine doesn't compile when used with boost::range::algorithms

Reported by: kozlov.taras@… Owned by: olli
Milestone: To Be Determined Component: coroutine
Version: Boost 1.58.0 Severity: Problem
Keywords: Cc:

Description

I've tried to use generators produced by boost::asymmetric_coroutines together with boost::range::algorithms (for example find_if) and it fails to compile.

Following code raise compilation error

#include <boost/range/algorithm/count.hpp>
#include <boost/coroutine/all.hpp>

using namespace boost::range;
using namespace boost::coroutines;

asymmetric_coroutine<int>::pull_type make_dummy_range()
{
    return asymmetric_coroutine<int>::pull_type([](asymmetric_coroutine<int>::push_type& yield)
    {
        yield(1);
    });
}

template<typename Range>
void const_func(const Range& r)
{
    auto b = boost::begin(r);
}

int _tmain(int argc, _TCHAR* argv[])
{
    const_func(make_dummy_range());
	return 0;
}

c:\users\taras\documents\visual studio 2012\projects\coroutine_bug\coroutine_bug\coroutine_bug.cpp(23): error C2027: use of undefined type 'boost::coroutines::pull_coroutine<R>::const_iterator'
1>          with
1>          [
1>              R=int
1>          ]
1>          d:\work\3rdparty\boost_1_58_0\boost\coroutine\asymmetric_coroutine.hpp(812) : see declaration of 'boost::coroutines::pull_coroutine<R>::const_iterator'
1>          with
1>          [
1>              R=int
1>          ]
1>          c:\users\taras\documents\visual studio 2012\projects\coroutine_bug\coroutine_bug\coroutine_bug.cpp(28) : see reference to function template instantiation 'void const_func<boost::coroutines::pull_coroutine<R>>(const Range &)' being compiled
1>          with
1>          [
1>              R=int,
1>              Range=boost::coroutines::pull_coroutine<int>
1>          ]
1>c:\users\taras\documents\visual studio 2012\projects\coroutine_bug\coroutine_bug\coroutine_bug.cpp(23): error C2514: 'boost::coroutines::pull_coroutine<R>::const_iterator' : class has no constructors
1>          with
1>          [
1>              R=int
1>          ]
1>          d:\work\3rdparty\boost_1_58_0\boost\coroutine\asymmetric_coroutine.hpp(812) : see declaration of 'boost::coroutines::pull_coroutine<R>::const_iterator'
1>          with
1>          [
1>              R=int
1>          ]
1>
1>Build FAILED.

The problem is that boost::asymmetric_coroutine::const_iterator is declared but never defined, see boost/coroutine/asymmetric_coroutine.hpp:180

I detected this problem while was trying to migrate from Boost 1.55. With Boost 1.55 this code compiles and everything is fine.

Attachments (0)

Change History (3)

comment:1 Changed 3 years ago by olli

Resolution: wontfix
Status: newclosed

const_iterator must not be defined - it will never be const because each incrementation will modify/changed the associated coroutine. removing the declaration for const_iteration from the header will not help.

comment:2 Changed 3 years ago by kozlov.taras@…

First of all boost coroutines and ranges can't be used together at the moment. This is definitly a bug. And ok, probably it should be fixed in Boost.Range

I want to clearify problem again. Using generator together with ANY non mutating Boost.Range algorithm yields compiler error

Example

asymmetric_coroutine<int>::pull_type make_dummy_range()
{
    return asymmetric_coroutine<int>::pull_type([](asymmetric_coroutine<int>::push_type& yield)
    {
        yield(1);
    });
}

int _tmain(int argc, _TCHAR* argv[])
{
    boost::for_each(make_dummy_range(), ...); //error
    boost::max_element(make_dummy_range()); //error
    boost::distance(make_dummy_range()); //error
    boost::find(make_dummy_range(), 1); //error
}

I put this bug to boost.coroutines for two reasons.

  1. It is known problem that SinglePassRange? can't define perfect const_iterator, but it is also common and convinient workaround to override range_const_iterator to return mutable iterator. So any algorithm which accept const Range& can work with it.
  1. Coroutines in Boost 1.55 already provided const_iterator, so Boost 1.58 just broken some existing code.

comment:3 Changed 3 years ago by olli

commit pushed to branch develop

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain olli.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.