Tuesday, April 24, 2012

mixed-type, variable length argument list (varargin, *args, ...) for C++

I am building a C++ clone of a project originally written in MATLAB. I'd like to "translate" the code keeping as close to the original as possible (given the unavoidable differences between a dynamically typed language like MATLAB and a statically typed language like C++).



My question is about variable length argument lists as function parameters which can contain arguments of mixed type.



MATLAB has varargin as a function parameter:



 varargin Variable length input argument list.
Allows any number of arguments to a function. The variable
varargin is a cell array containing the optional arguments to the
function. varargin must be declared as the last input argument
and collects all the inputs from that point onwards. In the
declaration, varargin must be lowercase (i.e., varargin).


In Python, *args and **kwargs handle this very comfortably.



How close can I get to this kind of flexibility in C++? Are there any standard argument list classes I should use?





No comments:

Post a Comment