00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <iostream>
00018 #include <vector>
00019 using namespace std;
00020
00021 #include "boost/lambda/lambda.hpp"
00022 #include "boost/function.hpp"
00023 using namespace boost;
00024 using namespace boost::lambda;
00025
00026
00030 void f( const double & Value )
00031 {
00032 cout << "f called. Value: " << Value << endl;
00033 }
00034
00038 void g( const double & Value )
00039 {
00040 cout << "g called. Value: " << Value << endl;
00041 }
00042
00043
00044
00045
00049 struct CallbackStorage
00050 {
00052 CallbackStorage() {}
00053
00055 vector< function< void ( const double & ) > > v;
00056
00057
00061 void insert( function< void ( const double & ) > func )
00062 {
00063 v.push_back( func );
00064 }
00065
00066
00070 void operator() ( const double & val )
00071 {
00072 vector< function< void ( const double & ) > >::iterator k;
00073 for ( k = v.begin(); k != v.end(); ++k )
00074 {
00075 (*k)( val );
00076 }
00077 }
00078
00079
00085 void insert( double & Ref )
00086 {
00087
00088 function< void ( const double & ) > g = ( var( Ref ) = _1 );
00089 v.push_back( g );
00090 }
00091
00092 };
00093
00094
00095
00096
00097
00098 int main( void )
00099 {
00100 CallbackStorage Storage;
00101 double Value1( 1.1 );
00102 double Value2( 2.2 );
00103 double Value3( 3.3 );
00104
00105
00106
00107 Storage.insert( f );
00108 Storage.insert( Value1 );
00109 Storage.insert( Value2 );
00110 Storage.insert( Value3 );
00111 Storage.insert( g );
00112
00113 cout << "Before a call" << endl
00114 << " Value1 = " << Value1 << endl
00115 << " Value2 = " << Value2 << endl
00116 << " Value3 = " << Value3 << endl;
00117
00118 Storage( 777.88 );
00119
00120 cout << "After a call" << endl
00121 << " Value1 = " << Value1 << endl
00122 << " Value2 = " << Value2 << endl
00123 << " Value3 = " << Value3 << endl;
00124
00125 return 0;
00126 }
00127