jeudi 5 octobre 2017

How do I convert a std::function wrapper into a variadic function?

I have this very nice wrapper, but I'd like it to accept any number of T, S, R, Q, ...

template<typename U, typename T, typename S>
boost::variant<U, std::string> RunSafeFn2(const std::function<U(const T&,const S&)>& f, const std::string& errMsg, const  T& a1, const  S& a2)
{
    try
    {
        return f(a1,a2);
    }
    catch (...)
    {
        return errMsg;
    }
}

I tried the below and have been googling about, but man the error messages are cryptic - is what I'm trying to do even possible?

template<typename U, class ... Ts>
boost::variant<U, std::string> RunSafeFnN(const std::function<U(Ts)>& f, const std::string& errMsg, Ts ... ts)
{
    try
    {
        return bind(f, ts...);
    }
    catch (...)
    {
        return errMsg;
    }
}

Aucun commentaire:

Enregistrer un commentaire