For performance reasons, I use the Curiously Reoccuring Template Pattern to avoid virtual functions. I have many small commands that run millions of times. I am trying to set this in Command Pattern. I want to add a ton of commands to the queue, and then iterate over them, each executing one at a time. Each team uses CRTP to avoid virtual functions. The problem I am facing is that the Command pattern is usually implemented using a pointer vector. But when the Command templated pattern, it becomes difficult to pass generic command pointers. I'm not an expert in C ++, so maybe there is an obvious way to store the vector of the template objects of the command? I am trying to use something like:
boost:ptr_vector commands; AddCommand(Command* command) { commands.push_back(command); }
The Command problem is not a type, so Command* command gives a compilation error. I need to use Command<CommandType> , but this will not work, because I need a queue to store different types of commands.
Any ideas for solutions? Or are these virtual functions just for me?
ADDED: Command objects are part of the monte carlo simulation algorithm. That way you can have the Command command as a random number from the normal distribution, where the normal distribution parameters are part of the class. Thus, the command template fits very well. I have a lot of calls in a specific order for functions that must support state.
source share