mercredi 18 septembre 2019

Advantages of using a function template argument when simply moving the parameter

Consider the following struct, which stores a function:

struct yyy {
    std::function<int()> myFunc;

    void set_func_1(std::function<int()>&& f) {
        myFunc = std::move(f);
    }

    template<typename funcT>
    void set_func_2(funcT&& f) {
        myFunc = std::move(f);
    }
};

As per this answer, I know that using a template parameter allows the compiler to optimize stuff.

But for the struct above, where I'm directly moving the function to store it, is there any benefit of using the template parameter?

Aucun commentaire:

Enregistrer un commentaire