dimanche 31 mai 2015

C++ bind member function with variadic template

My example below uses variadic templates to register a function inside a class. Registering a single function works but what about class member functions? I tried std::bind but this expects placeholders which is not an option because I don't know the number of arguments. Is there a simple way doing this in C++11 or am I forced to implement the register function for every amount of arguments?

template<typename TReturn, typename... TArgs>
class Func {
    std::function<TReturn (TArgs...)> fn;

    template<typename TFunction, typename TObject>
    bool register(TFunction f, TObject obj){

    }

    bool register(std::function<TReturn (TArgs...)> f){
        fn = f;
        return true;
    }   
}

Aucun commentaire:

Enregistrer un commentaire