mercredi 24 juin 2020

forward variable Argument list to mock std::thread

I want to mock my threads and wrote therefor an Adapter that just forward everything I need to std::thread. I am failing to do so for the constructor. I tried following:

class ThreadAdapter {
public:
    template< class Function, class... Args >
    explicit ThreadAdapter(Function&& f, Args&&... args) : thread_(f, args) {
    }

    virtual ~ThreadAdapter() = default;

   virtual  bool joinable() {
        return thread_.joinable();
    }

    virtual void join() {
        thread_.join();
    }

private:
    std::thread thread_;
};

Unfortunately this does not compile. My idea to forward the parameters in the constructor seems not to be valid, the compiler seems not to like the variable argument list. Does anybody have an idea how I can solve this?

bests

Sascha

Aucun commentaire:

Enregistrer un commentaire