I have a function like this:
typedef std::vector<std::map<int,std::string>> MyVec1;
typedef std::vector<std::map<std::string,std::string>> MyVec2;
enum options { DEFAULT_OPTIONS = 0x0000000u,
OTHERS = 0x0000001u };
void func(std::string s1, MyVec1& vec1, MyVec2& vec2, bool type,
std::string s2, options opt, uint32_t opt2){
//do something
//And put data to the vectors
}
I want to create a luncher which can take any number of arguments (upto 7) and set default values for the arguments that are not passed and then call the func()
with all arguments, kinda like this:
void launcher(args...){
//If any string is passed, pass it as the 1st arg of func, or an empty string
//If any second string is passed, pass it as the 5th arg of func or an empty string
//If any MyVec1 type is passed, pass it as the second arg or a dummy vector.
//If any MyVec2 type is passed, pass it as the third arg or a dummy vector.
////By dummy vector I mean create a vector with MyVec1 vec; and pass it as arg.
////Like this, if other args are passed they are passed to the func with
////given value otherwise a default value is chosen
////And finally call func() with all arguments.
}
The same can be achieved by overloading and using default values for arguments but that's a huge task if you consider that I want those arguments to be non-sequential too (specially the vectors) i.e launcher will manage if you pass MyVec2
first and MyVec1
as the second.
I had to create 16 overload for a three vector function (3-vector: 6, 2-vector: 6, 1-vector: 3, 0-vector: 1).
Is this even possible?
Note:
- I think I can detect the type with this. But the rest seems kinda impossible to me.
- If it is not possible to work with reference then that will do too. I have other functions that needs the same which doesn't work with references (A function with lots of args like the above without those vectors).
Aucun commentaire:
Enregistrer un commentaire