#include #include class IJob; class IJobPool { public: void Run(IJob *job) {};}; IJobPool *g_aPools[ #define POOL(x,i) 1 + #include "pools.h" #undef POOL 0 ]; #define POOL(x,i) struct S##x##PoolTag {}; #include "pools.h" #undef POOL class IJob {public: using tag = SmainPoolTag; }; class CNormalJob : public IJob {}; class CHttpJob : public IJob {public: using tag = ShttpPoolTag; }; #define POOL(x,i) \ void Run(IJob *job, S##x##PoolTag) \ { \ std::cout<<"dispatched to "#x<Run(job); \ } \ #include "pools.h" #undef POOL template::value>> void DispatchJob(T *job) { Run(job, typename T::tag()); } int main(int argc, char **argv) { #define POOL(x,i) \ IJobPool x##Pool; \ g_aPools[i] = &x##Pool; #include "pools.h" #undef POOL CNormalJob j1; CHttpJob j2; DispatchJob(&j1); DispatchJob(&j2); return 0; }