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
|
|