mercredi 27 mai 2015

How to wrap all but one template arguments using typedef and variadic templates?

I have a class I wrap with SWIG that is std::function proxy:

template <class TR = void, class ... Types>
struct GenericFunc 
#ifndef SWIG
    : std::function<TR (Types...)>
#endif
{
    GenericFunc() {}

#ifndef SWIG
    GenericFunc(const std::function<TR (Types... t)> & Action) : std::function<TR (Types... t)>(Action) {}
#endif
    virtual TR OnAction(Types ... result) {
        if(*this) {
            return (*this)(result...);
        }
        return TR();
    }
    virtual ~GenericFunc(){}
};

in C# or Java one can overload OnAction and get what he wants while on C++ side we have only one extra check.

Having a Func one would love to have an Action - a function that vould return void.

typedef GenericFunc<void,  Types...> GenericAction<class ... Types>;

So I wonder how to create an action using typedefs (not inheritance).. And I get many errors

How to wrap some types via C++11 and typedefs?

Aucun commentaire:

Enregistrer un commentaire