由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - STL iterator的疑问
相关主题
[合集] 如何得到一个指向STL元素的指针?STL感觉实在太变态了
既然要兄angular 推荐一个入门的tutorial吧。简明扼要好理解的c++ template question:
STL里怎样得到map的某个键值对(pair)的指针?关于inserter
C++11里list迭代器判空仍然知道具体的list对象吗?deque的pointer和reference是怎么回事?
如何把文件内容读到2D的vector里?c++ interview: iterator 和 pointer区别?
一个小程序差点搞死了g++,怎么回事?C++ vector 一边遍历一边删
说c++不难的欢迎来看看这个stl的一个问题
讨论 找单链表倒数m的节点 (转载)大家学习STL都是看SGI的文档么?
相关话题的讨论汇总
话题: iterator话题: stl话题: std话题: output话题: back
进入Programming版参与讨论
1 (共1页)
g*********s
发帖数: 1782
1
手头书不少,几本经典的都有了。但是看来看去还是对STL里的概念很不清楚,觉得这
些描述太抽象。谁能简明扼要地总结一下啊?
比如iterator,我的理解是推广的指针,是指向其他对象的对象。那么指针上的所有操
作iterator都支持吗?另外iterator又被分成input iterator, output iterator等等
。他们和iterator class之间是继承关系吗?input iterator和output iterator号称
只支持一小部分指针操作。另外书上说使用output iterator的算法必须是单遍算法,
这个又是什么意思?
下面这个例子将vs填上5个"hello"。但是为啥要用这个output iterator back_
inserter?直接vs.end()或者vs.last()不行吗?或者直接循环5次push_back。引入这
么细分的算法意义何在呢?
std::vector vs;
std::fill_n(std::back_inserter(vs), 5, "hello");
S*****n
发帖数: 227
2
从书本学那是太痛苦了。
想简单快速的学用stl,从网上、现实中找问题的例子,
自己用你熟悉的写法写一遍,再看看用stl怎么写
为什么人家写的简单了。
看看自己的code如何改进,然后就懂了。

【在 g*********s 的大作中提到】
: 手头书不少,几本经典的都有了。但是看来看去还是对STL里的概念很不清楚,觉得这
: 些描述太抽象。谁能简明扼要地总结一下啊?
: 比如iterator,我的理解是推广的指针,是指向其他对象的对象。那么指针上的所有操
: 作iterator都支持吗?另外iterator又被分成input iterator, output iterator等等
: 。他们和iterator class之间是继承关系吗?input iterator和output iterator号称
: 只支持一小部分指针操作。另外书上说使用output iterator的算法必须是单遍算法,
: 这个又是什么意思?
: 下面这个例子将vs填上5个"hello"。但是为啥要用这个output iterator back_
: inserter?直接vs.end()或者vs.last()不行吗?或者直接循环5次push_back。引入这
: 么细分的算法意义何在呢?

t****t
发帖数: 6806
3
input iterator: read-only pointer
output iterator: write-only pointer
forward iterator: you can increase by 1, but not decrease
bidirectional: you can increase/decrease by 1
random: you can +/- by any amount
1-pass: you can't go back; you can't even write twice to same slot
about your example: regular operation doesn't involve memory management. so
if you use std::copy, you must have the space already allocated. if not, you
are actually doing write+allocate, which corresponds to push_back() or
i

【在 g*********s 的大作中提到】
: 手头书不少,几本经典的都有了。但是看来看去还是对STL里的概念很不清楚,觉得这
: 些描述太抽象。谁能简明扼要地总结一下啊?
: 比如iterator,我的理解是推广的指针,是指向其他对象的对象。那么指针上的所有操
: 作iterator都支持吗?另外iterator又被分成input iterator, output iterator等等
: 。他们和iterator class之间是继承关系吗?input iterator和output iterator号称
: 只支持一小部分指针操作。另外书上说使用output iterator的算法必须是单遍算法,
: 这个又是什么意思?
: 下面这个例子将vs填上5个"hello"。但是为啥要用这个output iterator back_
: inserter?直接vs.end()或者vs.last()不行吗?或者直接循环5次push_back。引入这
: 么细分的算法意义何在呢?

g*********s
发帖数: 1782
4
收藏了。非常感谢。

so
you

【在 t****t 的大作中提到】
: input iterator: read-only pointer
: output iterator: write-only pointer
: forward iterator: you can increase by 1, but not decrease
: bidirectional: you can increase/decrease by 1
: random: you can +/- by any amount
: 1-pass: you can't go back; you can't even write twice to same slot
: about your example: regular operation doesn't involve memory management. so
: if you use std::copy, you must have the space already allocated. if not, you
: are actually doing write+allocate, which corresponds to push_back() or
: i

1 (共1页)
进入Programming版参与讨论
相关主题
大家学习STL都是看SGI的文档么?如何把文件内容读到2D的vector里?
弱问c++ iterator 和 pointer区别一个小程序差点搞死了g++,怎么回事?
gprof和STL的问题说c++不难的欢迎来看看这个
interview questions讨论 找单链表倒数m的节点 (转载)
[合集] 如何得到一个指向STL元素的指针?STL感觉实在太变态了
既然要兄angular 推荐一个入门的tutorial吧。简明扼要好理解的c++ template question:
STL里怎样得到map的某个键值对(pair)的指针?关于inserter
C++11里list迭代器判空仍然知道具体的list对象吗?deque的pointer和reference是怎么回事?
相关话题的讨论汇总
话题: iterator话题: stl话题: std话题: output话题: back