C++: passing list of functions as argument to function
by rdx from LinuxQuestions.org on (#4SWRM)
This is really a pure C++ question (g++).
I want to pass a list of functions to another function so that it can call those in the list in sequence and accumulate their outputs in a matrix. The functions in the list are "double (*func)( vec x)" in the syntax of the Armadillo linear algebra library.
This is similar I think to the way hardware drivers used to have a list of function calls to access "read," "write," and control functions but I haven't seen that usage in a long time.
What I am trying to do is pass the pointers as "uwords" since that is a type acceptable to Armadillo and then cast the unsigned long ints to function calls. If this seems too awkward I would fall back on a STL <vector> to contain the list. Other ideas welcomed. The key feature here is that the number of functions in the list is arbitrary.


I want to pass a list of functions to another function so that it can call those in the list in sequence and accumulate their outputs in a matrix. The functions in the list are "double (*func)( vec x)" in the syntax of the Armadillo linear algebra library.
This is similar I think to the way hardware drivers used to have a list of function calls to access "read," "write," and control functions but I haven't seen that usage in a long time.
What I am trying to do is pass the pointers as "uwords" since that is a type acceptable to Armadillo and then cast the unsigned long ints to function calls. If this seems too awkward I would fall back on a STL <vector> to contain the list. Other ideas welcomed. The key feature here is that the number of functions in the list is arbitrary.