为什么在Visual Studio 2008/2010这里需要typename _not_? [英] Why is typename _not_ needed here in Visual Studio 2008/2010?

查看:168
本文介绍了为什么在Visual Studio 2008/2010这里需要typename _not_?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题中,asker具有以下功能:

In this question, the asker has the following function:

template<typename ITER>
bool nextPermutation(ITER start, ITER end)
{
    return nextPermutation(start, end, std::iterator_traits<ITER>::iterator_category());
}

为什么不是 typename 需要之前 std :: iterator_traits ?我认为这是嵌套类型的模板,如果模板依赖于模板参数本身需要的? GCC似乎支持我的想法,因为它不能在 4.3.4 4.5.1 ,要求 typename 。即使如此,它仍然编译正好在Visual Studio 2008和2010下。

这只是另一个Visual Studio扩展/错误,我不知道吗?

或者它实际上可能推断出 iterator_category 是一个类型或函数,因为它后面跟着一对括号()? (参见@ DeadGM的消息从这里开始。)那么这可能是GCC中的一个错误吗?

Why isn't a typename needed before the std::iterator_traits? I thought it was needed for nested types of a template, if the template is dependent on a template parameter itself? GCC seems to support my idea, as it doesn't compile under both 4.3.4 and 4.5.1, demanding a typename. Even so, it still compiles just fine under both Visual Studio 2008 and 2010.
Is this just another Visual Studio extension/bug I don't know about?
Or is it actually possible to deduce that iterator_category is either a type or a function because it's followed by a pair of parenthesis ()? (See @DeadGM's messages starting here.) So is this maybe actually a bug in GCC?

推荐答案

MSVC是否实现后期解析方案?在这样的方案中,编译器不依赖于 typename 。它只是将所有的令牌存储在模板定义的大括号之间,并且当模板被实例化时,它解析这些令牌。因为它知道什么是什么,什么不是类型,它将工作,而不 typename

Doesn't MSVC implement the late-parsing scheme? In such a scheme, the compiler isn't dependent on typename. It just stores all the token in between the template definition's braces, and when the template is instantiated, it parses those tokens. Since it then knows what is and what is not a type, it will work without typename.

但如果编译器在您实例化模板时不诊断缺少的 typename ,那么它是不符合。

But if the compiler doesn't diagnose the missing typename when you instantiate the template, then it's non-conforming.


或者实际上可能推断出iterator_category是一个类型或函数,因为它后面跟着一对括号()?

Or is it actually possible to deduce that iterator_category is either a type or a function because it's followed by a pair of parenthesis ()?

重要的是名称是否依赖和合格。无论模板是否可以推断自己,名称总是一个类型并不重要。它可能对错误消息的质量缺少 typename 虽然。

All that matters is whether the name is dependent and qualified. Whether or not the template could deduce itself that the name is always a type doesn't matter. It might matter for the quality of error messages for missing typenames though.

FWIW,不可能在语言级别推导出 iterator_category 的任何内容。

FWIW, no it's not possible to deduce anything about iterator_category on a language level.

这篇关于为什么在Visual Studio 2008/2010这里需要typename _not_?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆