Search code examples
c++templatesboost-mpl

C++ createObject() Factory


I would like to create a simple factory method with a simple C++ syntax:

void *createObject(const char *str,...)
{
  if(!strcmp("X",str))
     return new X(...);
}

I cannot figure out the syntax for this. I've been looking at template metaprogramming and use mpl::vectors, but I am not sure how to pass down this syntax. I want to really avoid using C va_lists if possible and go for a clean syntax like the one above.


Solution

  • The solution I ended up using was to create 0, N singletons with templated parameters. It is working pretty well with N = 8. A bit ugly, but only needs to be done once.