CPP template parameter specified as some kind of std::function

I have a class:

<template class F>
class test
{
public:
    test(F fn) : fn_(fn)
    {
    
    }
private:
    F fn_;
};


I want to specify F as std::function, for example F can be std::function < void () >. But there can be many kinds of std::function, such as std::function < int () >. I just want to limit F to std::function. How do I write it without further specific restrictions?

CPP
Jun.14,2022

template<typename F>
class Test
{
public:
    typedef std::function<F> func_type;

    Test(const func_type& fn)
        : _fn(fn)
    {}

    template<typename ...Args>
    auto operator ()(Args&& ...args)
    {
        return _fn(std::forward<Args>(args)...);
    }

private:
    func_type _fn;
};


int main() {
    std::function<void(const std::string&)> print = [](const std::string& name) {
        std::cout << "Hello " << name << " !" << std::endl;
    };

    Test<void(const std::string&)> t(print);

    t("Jason");

    return 0;
}

take a look, isn't it?

Menu