mirror of
https://github.com/boostorg/coroutine.git
synced 2026-02-08 10:42:27 +00:00
fix example for multiple definitions
This commit is contained in:
13
example/cpp03/asymmetric/X.h
Normal file
13
example/cpp03/asymmetric/X.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef X_H
|
||||
#define X_H
|
||||
|
||||
struct X
|
||||
{
|
||||
int i;
|
||||
|
||||
X( int i_) :
|
||||
i( i_)
|
||||
{}
|
||||
};
|
||||
|
||||
#endif // X_H
|
||||
@@ -4,14 +4,7 @@
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/coroutine/all.hpp>
|
||||
|
||||
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;
|
||||
|
||||
@@ -1,18 +1,26 @@
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/coroutine/all.hpp>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user