From c15ffa714661bdcaa7ed65a5cf07a9e7f90f653a Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Sat, 23 Aug 2014 13:39:24 +0200 Subject: [PATCH] fix example for multiple definitions --- example/cpp03/asymmetric/X.h | 13 +++++++++++++ example/cpp03/asymmetric/simple.cpp | 9 +-------- example/cpp03/asymmetric/test.cpp | 22 +++++++++++++++++----- 3 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 example/cpp03/asymmetric/X.h diff --git a/example/cpp03/asymmetric/X.h b/example/cpp03/asymmetric/X.h new file mode 100644 index 0000000..254d44f --- /dev/null +++ b/example/cpp03/asymmetric/X.h @@ -0,0 +1,13 @@ +#ifndef X_H +#define X_H + +struct X +{ + int i; + + X( int i_) : + i( i_) + {} +}; + +#endif // X_H diff --git a/example/cpp03/asymmetric/simple.cpp b/example/cpp03/asymmetric/simple.cpp index aacd2fb..aae34bc 100644 --- a/example/cpp03/asymmetric/simple.cpp +++ b/example/cpp03/asymmetric/simple.cpp @@ -4,14 +4,7 @@ #include #include -struct X -{ - int i; - - X( int i_) : - i( i_) - {} -}; +#include "X.h" typedef boost::coroutines::asymmetric_coroutine< X& >::pull_type pull_coro_t; typedef boost::coroutines::asymmetric_coroutine< X& >::push_type push_coro_t; diff --git a/example/cpp03/asymmetric/test.cpp b/example/cpp03/asymmetric/test.cpp index 366d104..c0bbd47 100644 --- a/example/cpp03/asymmetric/test.cpp +++ b/example/cpp03/asymmetric/test.cpp @@ -1,18 +1,26 @@ +#include #include -typedef boost::coroutines::asymmetric_coroutine< void >::pull_type pull_coro_t; -typedef boost::coroutines::asymmetric_coroutine< void >::push_type push_coro_t; +#include "X.h" + +typedef boost::coroutines::asymmetric_coroutine< X& >::pull_type pull_coro_t; +typedef boost::coroutines::asymmetric_coroutine< X& >::push_type push_coro_t; void foo1( push_coro_t & sink) { for ( int i = 0; i < 10; ++i) - sink(); + { + X x( i); + sink( x); + } } void foo2( pull_coro_t & source) { - while ( source) + while ( source) { + X & x = source.get(); source(); + } } void bar() @@ -20,13 +28,17 @@ void bar() { pull_coro_t source( foo1); while ( source) { + X & x = source.get(); source(); } } { push_coro_t sink( foo2); for ( int i = 0; i < 10; ++i) - sink(); + { + X x( i); + sink( x); + } } }