"typename ="是什么?在模板参数中表示什么? [英] What does "typename =" mean in the template parameters?
问题描述
我在《有效的现代C ++》一书的第189页中看到了这种表达方式:
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);
我只是想知道"typename =
"部分是什么意思.它肯定看起来像模板参数的默认参数.但是,您是否不需要在默认参数中添加诸如"typename some_name = ...
"之类的东西?第二个模板参数没有名称,在这种情况下我看不到使用第二个模板参数.
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.当我在google(或任何其他搜索引擎)上搜索答案时,等号始终会被丢弃,这几乎使寻找答案几乎不可能...
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...
推荐答案
这是一个可选的模板参数,没有名称,且为默认值.
它用于应用enable_if
条件;如果不满足条件,将产生编译器错误.
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.
这篇关于"typename ="是什么?在模板参数中表示什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!