由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - STL感觉实在太变态了
相关主题
C++ 菜鸟问一个关于template 的问题。c++ interview: iterator 和 pointer区别?
c++ template question:C++ vector 一边遍历一边删
这两个地方是否需要typename?stl的一个问题
C++ question about template typedef再来讨论一直算法课的作业吧
intel icc hash_map 求救!help understanding code (random number)
[菜鸟问题]类模板问题a c++ question
stl 的 member type 看起来挺头大的sgi stl 源代码一问
讨论 找单链表倒数m的节点 (转载)iterator一问
相关话题的讨论汇总
话题: random话题: iter话题: iterator话题: class话题: typename
进入Programming版参与讨论
1 (共1页)
s*******d
发帖数: 59
1
为什么不直接引入对type的操作呢?
比如_Iter_random(Const _Iter1&, Const _Iter2&)返回random_category如果
_Iter1, _Iter2都是random iterator, 否则返回forward_category.
目前的做法是
template
class _Iter_random_helper
{
public:
typedef forward_iterator_tag _Iter_random_cat;
};
template<>
class _Iter_random_helper iterator_tag>
{
public:
typedef random_access_iterator_tag _Iter_random_cat;
};
template
s*******d
发帖数: 59
2
再加上typename关键词来定义类型,比如
typename GetIteratorCategory(typename myType)
{
return iterator_traits::iterator_category;
}
c*****e
发帖数: 11
3
considering the efficiency for the two different implementation,
this is finished when compiling period,
the other is determined when run-time
there should be many such cases in stl, otherwise we can just use our own
library.

【在 s*******d 的大作中提到】
: 为什么不直接引入对type的操作呢?
: 比如_Iter_random(Const _Iter1&, Const _Iter2&)返回random_category如果
: _Iter1, _Iter2都是random iterator, 否则返回forward_category.
: 目前的做法是
: template
: class _Iter_random_helper
: {
: public:
: typedef forward_iterator_tag _Iter_random_cat;
: };

s*******d
发帖数: 59
4
typenames are constants during compile. so type1 == type2
doesn't involve runtime check.
And partial specialization is indeed simply comparing types.
What's more, there are already some typename manipulation
keywords such as __is_base_of, __is_class, which are not
standard but frequently used.
So adding one more extension "==" won't be a problem.
Then allowing typename expressions and statements will be
fully reasonable.
c*****e
发帖数: 11
5
o, if so, sorry for my statement about efficiency:)
besides, maybe it can be explained from the maintainance cost for the lib
by partialspecialization, maybe it is a little easier to extend current
library, however, using typename, we should change the source code for each
extension. maybe later, we will still add some more specialization into the
library.

【在 s*******d 的大作中提到】
: typenames are constants during compile. so type1 == type2
: doesn't involve runtime check.
: And partial specialization is indeed simply comparing types.
: What's more, there are already some typename manipulation
: keywords such as __is_base_of, __is_class, which are not
: standard but frequently used.
: So adding one more extension "==" won't be a problem.
: Then allowing typename expressions and statements will be
: fully reasonable.

1 (共1页)
进入Programming版参与讨论
相关主题
iterator一问intel icc hash_map 求救!
template question[菜鸟问题]类模板问题
这段 C++ 怎么改才能编译?stl 的 member type 看起来挺头大的
vector::iterator不对讨论 找单链表倒数m的节点 (转载)
C++ 菜鸟问一个关于template 的问题。c++ interview: iterator 和 pointer区别?
c++ template question:C++ vector 一边遍历一边删
这两个地方是否需要typename?stl的一个问题
C++ question about template typedef再来讨论一直算法课的作业吧
相关话题的讨论汇总
话题: random话题: iter话题: iterator话题: class话题: typename