I’m parsing user input and doing, as an example, the following in response:
User Input 1:
Array<int> a;
Populate()(a);
int v = 10;
a.append(v);
User Input 2:
Array<bool> a;
Populate()(a);
int v = true;
a.remove(v);
User Input 3:
Array<bool> a;
Populate()(a);
a.removeAll();
Now lets say I wish to execute the functions at a later stage, such that the parse creates the Array object, establishes the command to execute for this Array(removeAll etc.) as well as the arguments, but doesn’t actually call the command – this calling occurs at a later stage.
Is there a std or boost library which might help me to do achieve such a behaviour?
In C++11 you can remember the action in
std::function:Note, that when you call the action, it will work on the exact Array you gave it (it is captured by reference), so make sure the object still exists!