What does “typename =” mean in the template parameters?

前提是你 提交于 2019-12-20 09:11:39

问题


I have seen this expression in page 189 of the book "Effective Modern C++":

    template<typename T,
             typename = typename std::enable_if<condition>::type>
    explicit Person(T&& n);

I am just wondering what does the part "typename =" mean. It certainly looks like a default argument for a template parameter. But don't you need something like "typename some_name = ..." in a default argument? There is no name for the second template argument, and I don't see the second template argument being used in this case.

P.S. When I search on google (or any other search engine) for an answer, the equal sign is always discarded, and this just makes finding an answer almost impossible...


回答1:


That's an optional template parameter with no name and a default value.
It's used to apply the enable_if condition; it will create a compiler error if the condition is not met.

You can use exactly the same syntax for normal method arguments.



来源:https://stackoverflow.com/questions/29136749/what-does-typename-mean-in-the-template-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!