test.cpp 768 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <boost/coroutine/all.hpp>
  2. #include <boost/bind.hpp>
  3. #include "X.h"
  4. typedef boost::coroutines::asymmetric_coroutine< X& >::pull_type pull_coro_t;
  5. typedef boost::coroutines::asymmetric_coroutine< X& >::push_type push_coro_t;
  6. void foo1( push_coro_t & sink)
  7. {
  8. for ( int i = 0; i < 10; ++i)
  9. {
  10. X x( i);
  11. sink( x);
  12. }
  13. }
  14. void foo2( pull_coro_t & source)
  15. {
  16. while ( source) {
  17. X & x = source.get();
  18. source();
  19. }
  20. }
  21. void bar()
  22. {
  23. {
  24. pull_coro_t source( foo1);
  25. while ( source) {
  26. X & x = source.get();
  27. source();
  28. }
  29. }
  30. {
  31. push_coro_t sink( foo2);
  32. for ( int i = 0; i < 10; ++i)
  33. {
  34. X x( i);
  35. sink( x);
  36. }
  37. }
  38. }