Generic factory library for C++