Created
November 25, 2008 01:13
-
-
Save dreiss/28732 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <tr1/functional> | |
#include <cstdio> | |
struct FooSyncIface { | |
virtual int bar(int arg) = 0; | |
virtual int baz(int arg) = 0; | |
}; | |
struct FooAsyncIface { | |
virtual void bar(std::tr1::function<void(int)> cob, int arg) = 0; | |
virtual void baz(std::tr1::function<void(int)> cob, int arg) = 0; | |
}; | |
struct FooSyncNull : virtual public FooSyncIface { | |
virtual int bar(int /* arg */) { | |
int _return = 0; | |
return _return; | |
} | |
virtual int baz(int /* arg */) { | |
int _return = 0; | |
return _return; | |
} | |
}; | |
#if 0 | |
struct FooAsyncDefaulter : virtual protected FooSyncNull , virtual public FooAsyncIface { | |
using FooSyncIface::bar; | |
virtual void bar(std::tr1::function<void(int)> cob, int arg) { | |
int _return = static_cast<FooSyncIface*>(this)->bar(arg); | |
return cob(_return); | |
} | |
using FooSyncIface::baz; | |
virtual void baz(std::tr1::function<void(int)> cob, int arg) { | |
int _return = static_cast<FooSyncIface*>(this)->baz(arg); | |
return cob(_return); | |
} | |
}; | |
#endif | |
#if 0 | |
struct FooSyncHandler { | |
virtual int bar(int arg) { | |
return arg+1; | |
} | |
}; | |
#endif | |
struct FooAsyncHandler : public FooAsyncIface { | |
virtual int bar(int arg) { | |
return arg+1; | |
} | |
virtual void bar(std::tr1::function<void(int)> cob, int arg) { | |
return cob(bar(arg)); | |
} | |
virtual void baz(std::tr1::function<void(int)> cob, int arg) { | |
return cob(arg*2); | |
} | |
}; | |
void print_int(int arg) { | |
printf("%d\n", arg); | |
} | |
int main() { | |
FooAsyncIface* iface = new FooAsyncHandler; | |
iface->bar(print_int, 2); | |
iface->baz(print_int, 4); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment