lundi 28 septembre 2015

I want to create a std::function but add args incrementally

I hope some one can help me a little here. I am relatively new to C++ and also to the concept of Templates. I need to create a std::function based on some data that I am getting in a list. The signature of the function should be according to the data available. I am looking for something like this

template <typename ret, typename... Args, typename newArg>
struct typeparser<ret(...Args)>{
    typeparser<ret(...Args)> insertArg(newArg)
    { 
       retrun typeparser <ret(...args, newArg) > ; 
    }
};

What I want to do is iterate through a vector of boost::variant and then based on the type of value i see, add it to the list of parameters once complete, create a std:function and load it from a lib, then execute it. Make any sense?

std::vector<boost::varient<int, char, std::string>> list;
arglist = typeparser<int()>;   //all functions have int return, so start with return int and 0 args
for(boost::varient<int, char, std::string> a : list) {
    if(a.type() ==  typeid(int)){
        arglist.addArg(int); // now add int to list of args
    } else 
    if(a.type()== typeid(char)) {
       arglist.add(char);
    } else
    if (a.type()== typeid(bla)) {
        arglist.add(bla);
    }
  } // end for 
//now create the function here 
std::function<arglist> f = //load from library;

Does this even seem possible? Maybe I am looking at the problem in the wrong way? Any thing will help at this time. Thanks a lot!!

Aucun commentaire:

Enregistrer un commentaire