Reputation: 1269
I have a function which can take any number of any type of arguments(generic arguments).
I don't want to use va_arg stuffs and variadic template arguments is not supported in my compiler. I use boost library.
Can anyone suggest me how to implement this ?
Upvotes: 0
Views: 111
Reputation: 184
You could also cheat, by passing in an array of void pointers,
void func(void**args);
and require the last be a Null, or pass in a vector,
void func(std::vector<void*> args);
But you're exposing your API to abuse and untraceable runtime errors, and any decent code review will require you to go away and redesign your code properly.
Upvotes: 0
Reputation: 26381
If you don't want to use va_args
and don't want to use a decently recent compiler that supports variadic templates (like the free and open-source GCC
or Clang
compilers), there's no way to achieve that. If you can live with an upper limit in the number of arguments, you can use Boost.Preprocessor
to define functions that take 0 to N
arguments.
Upvotes: 4