mardi 29 août 2017

how to use std::bind with stl and save the return type?

I'm working on a class that schedules functions by binding them in a queue like that:

std::queue <void()> q;

template<typename R,typename... ArgsT>
        void
        schedule(R& fn, ArgsT&... args)
        {
            q.push(std::bind(fn, std::forward<ArgsT>(args)...) );


        };

template<typename R,typename... ArgsT>
        void
        schedule(R&& fn, ArgsT&&... args)
        {
            q.push(std::bind(fn, std::forward<ArgsT>(args)...) );


        };

so as you see I made the type of the queue void() to make it hold any type of function objects but now I can't get the return when I execute it. what should I do to solve this?

Note: I don't want to use an external library like boost and I don't know what's the kind of function the user will pass it.

Aucun commentaire:

Enregistrer un commentaire