【问题标题】:Where does the C++ 98 standard specify that locally declared template names are not dependent?C++ 98 标准在哪里指定本地声明的模板名称不依赖?
【发布时间】:2012-09-22 12:52:10
【问题描述】:

根据此页面: http://womble.decadent.org.uk/c++/template-faq.html#non-dependent “非依赖名称是那些被认为不依赖于模板参数的名称,加上模板本身的名称和在其中声明的名称(成员、朋友和局部变量)”

这似乎得到了以下代码被认为是有效的事实的支持(LLVM/Comeau)

template<typename T>
struct Template
{
    typedef int I;
    typedef Template::I Type; // 'Template' is NOT dependent
    typedef Template<T>::I Type2; // 'Template<T>' is NOT dependent
    Template<T>* m;
    void f()
    {
        m->f(); // 'm' is NOT dependent
    }
};

花了一些时间阅读 C++ 98 标准后,我找不到指定此行为的位置。我希望在“temp.nondep”下找到对此的提及。

【问题讨论】:

  • 注意,从 C++11 开始,现在有一堆语言涉及“名称指的是 当前实例化 if”,这涉及到这种用法。

标签: c++ templates name-lookup dependent-name c++98


【解决方案1】:

C++98 标准没有定义“非依赖”、“非依赖”或“不依赖”名称的确切含义(您可以在标准文本中找到所有三种形式)。

相反,它选择定义哪些名称和类型取决于 14.6 [temp.res] 及其子章节中的模板参数。应用简单的逻辑......所有不依赖的东西都是不依赖的。只阅读 14.6.3 [temp.nondep] 没有帮助。

【讨论】:

  • 重读 14.6 [temp.res] 回答了我的问题:“在模板定义中可以使用三种名称:- 模板本身的名称,以及在模板中声明的名称本身 - 依赖于模板参数的名称 - 来自模板定义中可见范围的名称。”这意味着模板的名称被排除在“依赖于模板参数的名称”集中。
  • @willj 是的,你确实比我更清楚地回答了你自己的问题。 :)
猜你喜欢
  • 2013-03-03
  • 2021-08-11
  • 2021-12-09
  • 2018-01-06
  • 1970-01-01
  • 2014-05-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多