|
Boost : |
Subject: Re: [boost] [coroutine] Experimenting with interfaces
From: Oliver Kowalke (oliver.kowalke_at_[hidden])
Date: 2012-09-21 13:34:12
Am 21.09.2012 19:17, schrieb Eugene Yakubovich:
>
> template <typename C>
> void timer(C c, chrono::seconds interval) {
> while( interval != chrono::seconds::zero() ) {
> this_thread::sleep_for(interval);
> interval = c(interval);
> }
> }
>
> chrono::seconds tick(chrono::seconds last_interval) {
> std::cout << "tick" << std::endl;
> return last_interval;
> }
>
> // use with function
> timer(tick, chrono::seconds(1));
>
> // use with coroutine
> coroutine<chrono::seconds(chrono::seconds)> c(
> [](coroutine<chrono::seconds(chrono::seconds)> c, chrono::seconds i) {
> timer(c, i);
> }
> );
>
> chrono::seconds s = c(chrono::seconds(1));
> s = c(2*s);
> s = c(3*s);
> s = c(5*s);
>
>
> I'm not sure what this means for the best interface but I did want to
> share these thoughts and examples.
thank you for your examples:
If coroutine's template signature returns a type different from void it
is required that the coroutine function does return the same type
instead of void as in your example.
template <typename C>
void timer(C c, chrono::seconds interval) {
// while( interval != chrono::seconds::zero() ) {
// this_thread::sleep_for(interval);
// interval = c(interval);
// }
}
coroutine<chrono::seconds(chrono::seconds)> c(
[](coroutine<chrono::seconds(chrono::seconds)> c, chrono::seconds i) {
timer(c, i);
}
);
chrono::seconds s = c(chrono::seconds(1));
Which value has variable 's' after return from 'c(chrono::seconds(1))' ?
regards,
Oliver
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk