I am actually thinking of something similar to the '*' operator in python like this:
args = [1,2,4]
f(*args)
Is there a similar solution in C++?
What I can come up with is as follows:
template <size_t num_args, typename FuncType>
struct unpack_caller;
template <typename FuncType>
struct unpack_caller<3>
{
void operator () (FuncType &f, std::vector<int> &args){
f(args[0], args[1], args[3])
}
};
Above I assume only int
argument type.
The problem is that I feel it is a hassle to write all the specializations of unpack_caller for different value of num_args
.
Any good solution to this? Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…