关于C++模板函数的疑问

关于C++模板函数的疑问,看代码时遇到如下代码,无法理解:

template<typename B, typename... Args>
class RegisterFactoty : public NoCopyable {
public:
    using CreatorFunc = std::function<std::shared_ptr<B>(Args...)>;
    static RegisterFactoty& Instance()
    {
        static RegisterFactoty r;
        return r;
    }

    template<typename T, typename std::enable_if_t<std::is_base_of_v<B, T>>* = nullptr>
    std::string DoRegister(const std::vector<std::string>& names, CreatorFunc f)
    {
        std::string result;
        for (const auto& it : names) {
            result += it;
            builder_.emplace(it, f);
        }
        return result;
    }

    std::shared_ptr<B> CreateShared(const std::string& name, Args... args)
    {
        std::shared_ptr<B> result = nullptr;
        for (auto&& [n, builder] : builder_) {
            if (n == name) {
                result = builder(std::forward<Args>(args)...);
                break;
            }
        }
        return result;
    }
    RegisterFactoty() = default;
    ~RegisterFactoty() = default;
private:
    std::unordered_map<std::string, CreatorFunc> builder_;
};

其中的模板函数是什么意思?如下:

template<typename T, typename std::enable_if_t<std::is_base_of_v<B, T>>* = nullptr>
    std::string DoRegister(const std::vector<std::string>& names, CreatorFunc f)

首先搜一下std::is_base_of_vhttps://www.apiref.com/cpp-zh/cpp/types/is_base_of.html,可以知道只有T继承自B,其value才为true
然后看一下std::enable_if_t

template<bool _Test,
    class _Ty = void>
    struct enable_if
    {    // type is undefined for assumed !_Test
    };

template<class _Ty>
    struct enable_if<true, _Ty>
    {    // type is _Ty for _Test
    typedef _Ty type;
    };

其只有在第一个参数为true时,其type才能得到类型,在false的时候type没有定义
所以这段话的意思是在编译期判断T是否是B的子类,如不是其子类,enable_if的第一个模板参数为false,type没有定义就会报错