
11 Sep
2012
11 Sep
'12
6:13 a.m.
Another issue that I see is with reference/pointer types. The fact that the following code will blow up is troubling:
struct X {...}; typedef boost::coro::generator<X*> gen_t;
void foo(gen_t::self_t& self) { X x1, x2; self.yield(&x1); self.yield(&x2); }
gen_t g(foo); while( g ) { X* val = g(); // use *val. Ok on first iteration, dangling pointer on the second!!! }
X * val is an address of x1/x2 on the stack of foo(). no danglingpointer until coroutine is alive.
An alternative approach could be to try to make generator itself into an input iterator (like Giovanni's design) but that is hard because generator is non-copyable.
I've to think about it. Oliver