mercredi 12 décembre 2018

Wrapping variadic templates in pybind11

I'm writing python bindings for glog like library which uses macro and has cout like syntax for logging. LOG(LEVEL)<<" "<<" ".... So I'm using this function to call the macro

    template <typename Arg, typename... Args>
    void log(auto level, Arg&& arg, Args&&... args)
    {
        std::stringstream out;
        out << std::forward<Arg>(arg);
        using expander = int[];
        (void)expander{0, (void(out << ' ' << std::forward<Args>(args)), 0)...};
        LOG(level) << out.str();
    }

So in order to wrap this function for pybind11 module I need to specify template type. Is there any possible workaround or way to bind this function using pybind11? I'm also open to use other libraries like boost.python or even cython if its possible.

Aucun commentaire:

Enregistrer un commentaire