avatar
sgi stl 源代码一问# Programming - 葵花宝典
c*z
1
正在看stl源代码,其中list的iterator是这样定义的:
template
struct _List_iterator : public _List_iterator_base {
typedef _List_iterator<_tp> iterator;
typedef _List_iterator<_tp _tp=""> const_iterator;
typedef _List_iterator<_tp> _Self;
..........//以下略去
第一次看到这种情况,请问这是specialization吗?
感觉specialization是同一个接口不同版本,这个怎么有嵌套的感觉那?不懂为什么这
么设计
avatar
k*z
2
I think this is not specialization. I don't know why it is designed that way
, but it has no ambiguity once you provide _Tp, _Ref and _Ptr, so this is
compilable code.
avatar
L*r
3
partial specialization
avatar
t*t
4
这怎么是partial specialization呢,不要胡说好不好

【在 L*********r 的大作中提到】
: partial specialization
avatar
L*r
5
the result of this specialization is still of a template.
the specialization is partially on pointer and reference of same type.

【在 t****t 的大作中提到】
: 这怎么是partial specialization呢,不要胡说好不好
avatar
t*t
6
你VC用多了,不懂partial specialization可以理解,但是请不要误导别人
template class A { /* ... */ };
template class A { /* ... */ };
这个叫partial specialization,specialization的意思是要重新给出class的定义的
OP贴的那个,叫做instantiation,虽然参数仍然没有给定,而且self-reference,但不代
表这就变成specialization了

【在 L*********r 的大作中提到】
: the result of this specialization is still of a template.
: the specialization is partially on pointer and reference of same type.

avatar
L*r
7
It is not instantiation. Is there a rule in standard that template
instantiation can still has the type parameter?
it is to partially specialize a synonym for the template class. the result
still is a template, a template synonym.
your sample is partially specialize the definition of the template class.


【在 t****t 的大作中提到】
: 你VC用多了,不懂partial specialization可以理解,但是请不要误导别人
: template class A { /* ... */ };
: template class A { /* ... */ };
: 这个叫partial specialization,specialization的意思是要重新给出class的定义的
: OP贴的那个,叫做instantiation,虽然参数仍然没有给定,而且self-reference,但不代
: 表这就变成specialization了

avatar
t*t
8
给你举个例子好了
template class A {};
template class B : public A { // what is this A?
// do you call this "partial specialization"?
A c; // and this?
typedef A G1; // and this?
typedef B G2; // and this?
};



【在 L*********r 的大作中提到】
: It is not instantiation. Is there a rule in standard that template
: instantiation can still has the type parameter?
: it is to partially specialize a synonym for the template class. the result
: still is a template, a template synonym.
: your sample is partially specialize the definition of the template class.
:

avatar
L*r
9


【在 t****t 的大作中提到】
: 给你举个例子好了
: template class A {};
: template class B : public A { // what is this A?
: // do you call this "partial specialization"?
: A c; // and this?
: typedef A G1; // and this?
: typedef B G2; // and this?
: };
:
:

avatar
t*t
10
ok, to be precise, this is not the point of instantiation, since typedef
doesn't induce instantiation in any case. but if you use G1 and G2, then A**> and B are instantiated.
but the bottom line is, it's not partial specialization!

【在 L*********r 的大作中提到】

avatar
L*r
11
in your case, B::G1 oG1; is instantiation
there only 2 key terms in template, one is instantiation, the other is
specilization. we both agree that it is not instantiation.
thrust,
could you tell me what is the term we should call it?



【在 t****t 的大作中提到】
: ok, to be precise, this is not the point of instantiation, since typedef
: doesn't induce instantiation in any case. but if you use G1 and G2, then A: **> and B are instantiated.
: but the bottom line is, it's not partial specialization!

avatar
t*t
12
typedef is neither instantiation nor specialization. it's a typedef, i.e. an
alias of a type. when you use the alias, it instantiate the aliased
template.

【在 L*********r 的大作中提到】
: in your case, B::G1 oG1; is instantiation
: there only 2 key terms in template, one is instantiation, the other is
: specilization. we both agree that it is not instantiation.
: thrust,
: could you tell me what is the term we should call it?
:
:
:
avatar
L*r
13
是不是有点牵强
和一般的typedef不一样,这个 alias 仍然是template, 仍然有type parameter.
只不过比original template 更具体了. 但按照你的说法,我不能说它是specialize.


an

【在 t****t 的大作中提到】
: typedef is neither instantiation nor specialization. it's a typedef, i.e. an
: alias of a type. when you use the alias, it instantiate the aliased
: template.

avatar
t*t
14
template class A { typedef T* X; }
X is an alias for T*. it still has "type parameter" (which is based on T).
would you call it a "specialization"?
it's just a dependent name, with an alias. dependent name is defined in
Standard 14.6.2. Whatever it is, please remember, any specialization begins
with keyword "template". No keyword, no specialization.

【在 L*********r 的大作中提到】
: 是不是有点牵强
: 和一般的typedef不一样,这个 alias 仍然是template, 仍然有type parameter.
: 只不过比original template 更具体了. 但按照你的说法,我不能说它是specialize.
:
:
: an

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。