3

I'm currently working with boost::asymmetric_coroutine. Let's say we have an ordinary function in the global namespace:

void foo(boost::coroutines::asymmetric_coroutine<int>::push_type & sink)
{
    //do something
    sink(100);
    //do something else
}

In that case, we can create and execute a coroutine using this function in the following manner:

boost::coroutines::asymmetric_coroutine<void>::pull_type coro{foo};

What I need to do is to use a class member function the same way. As I understand it, boost::bind should be used somehow, however, the following code doesn't work:

class MyClass
{
public:
    void create_coro()
    {
        boost::coroutines::asymmetric_coroutine<int>::pull_type coro
        {
            boost::bind(&MyClass::foo, _1);
        };
    }

private:
    void foo(boost::coroutines::asymmetric_coroutine<int>::push_type & sink)
    {
        //do something
    }
}

The error it raises is

no matching function to call to 'get_pointer(const boost::coroutines::push_coroutine&)'

How do I do it properly?

SingerOfTheFall
  • 29,228
  • 8
  • 68
  • 105

1 Answers1

4

It should be

    boost::coroutines::asymmetric_coroutine<int>::pull_type coro
    {
        boost::bind(&MyClass::foo, this, _1);
    };

note this, since you use member function.

ForEveR
  • 55,233
  • 2
  • 119
  • 133
  • 2
    for future readers who, like me, are looking for a way to use a **different** class member function as a coroutine, here's how: `coroutine::pull_type source{std::bind(&MyClass::my_coroutine, &c, std::placeholders::_1)}`, while `c` is an instance of `MyClass`. – narengi Jan 01 '17 at 09:21