std::bind ??

Hi,
I have this code and it works, but I do not understand why I need a _1 placeholder in the call to std::bind since I am not allowed to call source with a parameter...

Any insights?

Juan

void cooperative(coroutine<int>::push_type &sink, int i)
{
int j = i;
sink(++j);
sink(++j);
std::cout << "end\n";
}

void co_routine()
{
using std::placeholders::_1;
coroutine<int>::pull_type source{std::bind(cooperative, _1, 3)};

std::cout << source.get() << '\n';
source();
std::cout << source.get() << '\n';
source();
}
source and cooperative are a different objects.

When source is called it will pass the parametercoroutine<int>::push_type &sink to the function object [cooperative]. Hence you need a placeholder to enable source to do so.
Topic archived. No new replies allowed.