Intermediate C++ Programmer, using C++17, gcc.
Premise:
Right now I am working on a CLI interface for a more advanced program.
To eliminate the need for both code duplication and readability, I want to write a Macro and/or Template where the programmer may quickly specify the parameters of a function call so that a checkArgs() function will be automatically called with variables depending on the declaration of the function.
Example:
For example:
__Command( String funcName, size_t Min, size_t Max, E_StrType Types[])
Defines a new command for the Interface, if the entered command matches funcName, it will call funcName with the required parameters, if the check passes.
- funcName= The name of the function
- Min= Minimum amount of arguments, 0 for optional.
- Max= Maximum amount of Arguments, 0 for none, unless min != 0, then it is unlimited (variable)
- Types[], a list of types, in order from first to last, that the function requires. The last item on this list becomes the one used for every new argument if- Maxis 0.
example call:
__Command( testMsg, 1, 2, { E_StrType_String, E_StrType_size_t = 1 } )
which will generate a function with this signature:
testMsg( String Args )
later a:
__DefineCommand( testMsg )
{ code body }
Will generate a call to checkArgs( 1, 2, { String, size_t } ) in the definition of the function, in addition to whatever the programmer puts into the implementation of that function.
I already have a way of checking a string "type".
tl;dr
I am just looking to see how functions can be programatically generated like that, and optionally, if there is any way to provide compile-time checking to make sure the arguments to the macro are valid.
 
    