Created
November 19, 2013 03:18
-
-
Save bholt/7539752 to your computer and use it in GitHub Desktop.
Experimenting with async/balancing syntax for task spawn, parallel loop, etc.
This file contains hidden or 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 <accel-cpp/log.hpp> | |
#include <boost/variant.hpp> | |
#include <map> | |
#include <vector> | |
#include <sstream> | |
using namespace std; | |
enum SyncMode { async, blocking }; | |
enum BalancingMode { none, balancing }; | |
template< SyncMode S = SyncMode::blocking, BalancingMode B = BalancingMode::none > | |
void foo() { | |
stringstream s; | |
s << "foo<"; | |
s << ((S == SyncMode::blocking) ? "blocking" : "async"); | |
s << ((B == BalancingMode::none) ? ",none" : ",balancing"); | |
s << ">"; | |
cout << s.str() << endl; | |
} | |
template<> | |
void foo<async,none>() { cout << "foo<async,none> (specialized)" << endl; } | |
// overload so you can specify in the other order (or just balancing mode) | |
template< BalancingMode B, SyncMode S = SyncMode::blocking > | |
void foo() { foo<S,B>(); } | |
int main(int argc, char* argv[]) { | |
foo<async>(); | |
foo<balancing>(); | |
foo<balancing,async>(); | |
return 0; | |
} | |
///////////////////////////////////////////////////////////// | |
///////////////////////////////////////////////////////////// | |
//> foo<async,none> (specialized) | |
//> foo<blocking,balancing> | |
//> foo<async,balancing> | |
///////////////////////////////////////////////////////////// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment