c++ - 模板 :Name resolution:Dependent template arguments : -->can any one tell some more examples for this statement?

标签 c++ templates

这是来自 ISO C++ 标准 14.6.2.4 的声明: 依赖模板参数:

  1. A type template-argument is dependent if the type it specifies is dependent.

  2. An integral non-type template-argument is dependent if the constant expression it specifies is value dependent.

  3. A non-integral non-type template-argument is dependent if its type is dependent or it has either of the following forms and contains a nested-name-specifier which specifies a class-name that names a dependent type.

  4. A template template-argument is dependent if it names a template parameter or is a qualified-id with a nested-name-specifier which contains a class-name that names a dependent type.

我无法理解这些要点?

任何人都可以举例说明这些陈述吗?

最佳答案

这是我的理解。我已经根据 OP 中的行号标记了内联代码中的各个代码片段。

struct A{
    void f(){}
};

template<class T> struct B{};

// The template argument B<T> is TYPE depdent on the template parameter T                      (1)
template<class T, class U = B<T> > struct T1{};

// The template argument c is VALUE dependent on the template non type parameter 'c'        (2)
template<class T, char c, int d = c> struct T2{};

// The 2nd template argument is TYPE depdent on the template parameter T                    (3)
template<class T, void (T::*p)(void) = &T::f> struct T3{};

// The template template argument B is TYPE depdent on the template parameter T             (4)
template<class T, template<class U = T> class V = B> struct T4{};


int main(){
    T1<int> t1;
    T2<int, 'A', 2> t2;
    T3<A> t3;
    T4<A> t4; 
}

关于c++ - 模板 :Name resolution:Dependent template arguments : -->can any one tell some more examples for this statement?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3793151/

相关文章:

python - 打印从 django 表单输入的内容

c++ - 具有非类型参数的成员函数的部分特化

c++ - 我如何知道何时在我的代码中访问了一个变量?

c++ - std::list 反向迭代和删除导致崩溃

c++ - 一个类可以有将当前类作为参数的成员吗

c++ - 模板化转换运算符 string() 无法编译

c++ - 我们可以限制srand的范围吗

c++ - 是否可以传递具有捕获的不可复制(移动)值的 lambda?

c++ - 元组查找函数参数替换失败

javascript - 假设我在 Django 中有这个循环......我该如何显示它?