![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c++
文章平均质量分 75
adinosaur
这个作者很懒,什么都没留下…
展开
-
c++沉思录笔记(20章代码)迭代器配接器
给出一个例子 template T find(T start, T beyond, const X& x) { while (start != beyond && *start != x) ++start; return start; } 这个泛型函数在一个任意的数据结构中进行线性查找。譬如说,我们声明了 int x [ 10 ] 而且我们想要找出在数组x中第一次出现原创 2013-09-28 13:17:38 · 573 阅读 · 0 评论 -
c++沉思录笔记(19章代码上集)
首先给出一个函数 template Out copy(In start, In end, Out dest) { while (start != end) { *dest++ = *start++; } return dest; } 在主函数中,我们可以这样调用它 int _tmain(int argc, _TCHAR* argv[]) { int x[10]原创 2013-09-25 09:55:24 · 519 阅读 · 0 评论 -
c++沉思录笔记(13章代码)
截止至13章我们的代码已经可以做到如下功能了。原创 2013-09-17 15:02:06 · 457 阅读 · 0 评论 -
c++沉思录笔记(14章代码)
第十四章比较简单,只是在十三章的基础上增添了一些关系函数、自增函数等等。 看看学完这章我们的主函数能做些什么 #include "stdafx.h" #include "Array.h" #include "Pointer.h" #include "Ptr_to_const.h" #include using namespace std; int _tmain(int argc, _TC原创 2013-09-20 12:16:11 · 546 阅读 · 0 评论 -
c++沉思录笔记(15章代码)
先给出源代码 #ifndef SEQ_H_INCLUDED #define SEQ_H_INCLUDED template class Seq_item; template class Seq { public: Seq(); Seq(const T&, const Seq&); Seq(const Seq&); ~Seq(); Seq& operator=(const Se原创 2013-09-20 21:38:49 · 552 阅读 · 0 评论 -
c++沉思录笔记(17章代码)
问题:如何利用模板编写可适用于不同的数据结构和参数类型的函数? 这章给出了一个答案,尽可能多的减少对数据结构、参数类型的假设(要求)。原创 2013-09-22 22:45:05 · 488 阅读 · 0 评论 -
c++沉思录笔记(21章代码)隐藏中间类型
上次我们已经可以复合(组合)函数了,我们可以写出下面的代码 int main() { Comp fg(f, g); fg(42); } 但是,这么繁琐的对象创建,能不能简化一下。我们跟希望能写成这样 int main() { Composition fg(f, g); } 怎么做?下面开始完成它! 奇怪,我们希望的写法怎么没指出需要进行复合的那两个函数的原创 2013-10-05 22:31:24 · 507 阅读 · 0 评论 -
c++沉思录笔记(21章代码)通过函数对象解决c++的函数嵌套问题
在c++中,如果企图将函数作为参数进行传递的话,都会被立即转换为指向函数的指针。 看一个例子,假设我们有一对函数 f 和 g int f (int); int g (int); 我们希望能够使用下面的语句 int (*h) (int) = compose(f, g); 通过 compose 函数将函数 f 和 g 复合,它等价于(*h) (n) 将会等价于 f( g( n原创 2013-10-05 03:22:24 · 468 阅读 · 0 评论 -
c++沉思录笔记(21章代码)浅谈函数对象
标准库中有一个函数 find_if (#include )接受一对输入迭代器和一个谓词函数作为参数。 例如有一谓词函数如下: bool greater100(int n) { return n > 100; } 这个函数非常简单,但是如果说是要找出大于1000的数,这个函数就无能为力了。而接下来我们的工作就是逐步减少对greater100 的需求(即将函数泛型化) 标原创 2013-09-29 23:01:30 · 419 阅读 · 0 评论 -
c++沉思录笔记(19章代码中集)输入输出流迭代器
上一节我们已经了解了虚拟序列了,现在让我们看看虚拟序列其他的应用吧。 看看书上所提及的输出流迭代器 #ifndef OSTREAM_ITERATOT_H_ #define OSTREAM_ITERATOT_H_ #include #include template class Ostream_iterator { public: Ostream_iterator(std::os原创 2013-09-25 20:59:54 · 1031 阅读 · 0 评论