I am trying to get a std::function for a vararg function, but I am not finding a way to do this. Looking at the following gives me an incomplete type error:
Code: std::function<void(...)> cb;
Ideally I want to give it a function of any number of arguments of any type, don't care about return (should be void). Is there some fancy way to do this (supporting up to c++11)?
You almost definitely can't give typeless arguments without at least one fixed argument. va_start has to know what comes before it.
Is there a way to not use the var arg macros? I wanted to do something like have a std::function to point at, say, void test(float *out, vec3 *in) with the arguments not known in the pointer.
It would be nice to do something like reflection in java where I can simply take a method, determine the arguments, and then set each and invoke the method dynamically.
I am basically trying to emulate OpenCL code that requires one to invoke a kernel with you manually specifying the functions before hand yourself.
Apparently
libffi does exactly what I want, will have to look into it.
Apparently C++11 supports variadic templates. Might try that as a starting place. Something like
Code:
template<typename... Ts>
std::function<void(Ts...)> cb;
perhaps?
How would I even go about calling that, given that I have an array of variables to pass? I have seen a lack of documentation.
I will look into libffi and see what I can get as it should be cross platform enough for me.
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.
»
Go to Registration page
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum