[英]How can I understand the meaning of "Point of Instantiation"
I am now learning some meta-programming skills from non-constant-constant-expressions , and I feel confused about "Point of Instantiation".我现在正在从non-constant-constant-expressions学习一些元编程技能,我对“实例化点”感到困惑。 The author says作者说
Whenever a template specialization is referenced in a context that requires instantiation, that context gives birth to a "point of instantiation" (which effectively denotes a location where the compiler is allowed to generate code for the referenced template specialization).每当在需要实例化的上下文中引用模板特化时,该上下文就会产生“实例化点”(它有效地表示允许编译器为引用的模板特化生成代码的位置)。
If a template specialization X is referenced in a context that depends on a template-parameter of some surrounding template Y, the given point of instantation depends on the point of instantation of Y.如果在依赖于某个周围模板 Y 的模板参数的上下文中引用了模板特化 X,则给定的实例化点取决于 Y 的实例化点。
- If X is a function template specialization, the point of instantiation is that of Y.如果 X 是函数模板特化,则实例化点是 Y 的实例化点。
- If X is a class template specialization, the point of instantiation is immediately before the point of instantiation of Y.如果 X 是类模板特化,则实例化点就在 Y 的实例化点之前。
Otherwise, the given point of instantiation is tied to the location of the namespace scope declaration/definition (D) which contains the statement referring to X.否则,给定的实例化点与包含引用 X 的语句的命名空间范围声明/定义 (D) 的位置相关联。
- If X is a function template specialization, the point of instantiation is immediately after D.如果 X 是函数模板特化,则实例化点紧跟在 D 之后。
- If X is a class template specialization, the point of instantiation is immediately before D.如果 X 是类模板特化,则实例化点就在 D 之前。
I don't know what is "a template specialization X is referenced in a context that depends on a template-parameter of some surrounding template Y", does he mean我不知道什么是“在依赖于某个周围模板 Y 的模板参数的上下文中引用了模板特化 X”,他的意思是
template<typename T>
class Y{
template<typename U1> void X1(){...};
template<typename U2> class X2{...};
}
Consider Y<int>::X1<int>(...)
, X1
and Y
instantiate at the same time.考虑Y<int>::X1<int>(...)
, X1
和Y
实例化。
Consider Y<int>::X2<int>{...}
, X2
first Y
second.考虑Y<int>::X2<int>{...}
, X2
第一个Y
第二个。
It just means that, given这只是意味着,给定
template<class> class A {};
template<class T> void f(T) {}
template<class T> void g() {f(A<T>{});}
the point of instantiation of (say) A<int>
is immediately before that shared by f<int>
and g<int>
. (比如说) A<int>
的实例化点紧接在f<int>
和g<int>
共享的点之前。 (Remember that function (but not class) templates can have more than one point of instantiation in a translation unit.) (请记住,函数(但不是类)模板在翻译单元中可以有多个实例化点。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.