首页

  • 2014
  • Effective STL 学习笔记: Item 22 ~ 24

    » read more...

  • Effective STL 学习笔记14: Use reserve to avoid unnecessary reallocations.

    vector 和 string 容器在动态插入一个新的对象时,如果容器内空间不够,该容器会: 重新分配空间 通常的做法是分配当前 Capacity 大小两倍的空间。 将旧空间中的所有元素拷贝进新的空间中。 销毁原有空间中存储的对象。 销毁原有的空间。 » read more...

  • Effective STL 学习笔记 Item 38 Design functor classes for pass-by-value

    » read more...

  • Effective STL 学习笔记 Item 34: 了解哪些算法希望输入有序数据

    » read more...

  • Effective STL 学习笔记 Item 30 ~ 保证目标区间足够大

    » read more...

  • Effective STL 学习笔记 Item 26: Prefer Iterator to reverse_iterator and const_rever_itertor

    Table of Contents 1. Iterator 的类型 2. 迭代器之间的转换 3. Iterator is Special 4. 总结: » read more...

  • Effective STL 学习笔记 Item 21:Comparison Function 相关

    » read more...

  • Effective STL 学习笔记 Item 18: 慎用 vector<bool>

    vector<bool> 看起来像是一个存放布尔变量的容器,但是其实本身其实并不是一个容器,它里面存放的对象也不是布尔变量,这一点在 GCC 源码中 vector<bool> 的注释中写的很清楚: /** * @brief A specialization of vector for booleans which offers fixed time * access to individual elements in any order. * * Note that vector<bool> does not actually meet the requirements for being * a container. This is because the reference and pointer types are not * really references and pointers to bool. See DR96 for details. @see * vector for functio... » read more...

  • Effective STL 学习笔记 Item 17: Swap Trick

    假设有若干对象存于一个 vector 中: class Widget; vector<Widget> vw; 后来由于某些原因,从该容器中删除了若干对象(参考erase-remove idiom )。对于 vector 和 string 来讲, erase() 和 clear() 并不会改变容器的capacity,也就不会改变他们的内存占用。 swap() 本意是用来交换两个容器的内容( Iterators, pointers, and references),但我们可以用他来快速将容器的 capacity 调整为 合适 的大小: vector<Widget>(vw).swap(vw); 巧妙之处在于, vector 的拷贝构造函数仅仅拷贝有用的部分而忽略那些未占用的空间,用这个拷贝构造出来的容器来和 vw 进行 swap() 就可以调整 vw 的 capacity 为一个 相对较小的值 。 这里之所以说是 相对较小的值 而不是与 size() 绝对相等,是因为容器的 Implementation 在构造的时候会自己选取合适的值来保证分配的... » read more...

  • Effective STL 学习笔记 Item 16:vector, string & C API

    有时需要支持 C 的接口,但这并不复杂。 对于 vector 来讲, \(v[0]\) 的地址 \(\&v[0]\) 即可作为数组指针传递给 C API: 1: // Legacy C API. 2: extern void doSomething(const int* pInts, size_t numInts); 3: 4: vector<int> v; 5: // ... 6: // Operations on v. 7: // ... 8: 9: if (!v.empty()) 10: { 11: doSomething(&v[0], v.size()); 12: } 也许有人会说:可以用 v.begin() 来替代 \(\&v[0]\), 但并非永远如此, v.begin() 返回的是一个迭,迭代器指向的对象的地址才是真正的 \(\&v[0]\) ,即: &*v.begin() == &v[0] String 对象没有要求保证所有字符串都存放在连续的内存空间,而且 ... » read more...

  • Effective STL 学习笔记 39 ~ 41

    » read more...

  • Effective STL 学习笔记 32 ~ 33

    » read more...

  • Effective STL 学习笔记 31:排序算法

    Effective STL 学习笔记 31:排序算法 » read more...

  • Effective STL 43 - Prefer algorithm calls to hand-written loops

    Suppose you have a Widget class that supports redrawing: class Widget { public: Widget(); virtual ~Widget(); void redraw() const; }; and you'd like to redraw all the Widgets in a list, you could do it within a loop: list<Widget> lw; // ... for (list<Widget>::iterator i = lw.begin(); i != lw.end(); ++i) { i->redraw(); } But you could also do it with the for_each algorithm: for_each(lw.begin(), lw.end(), mem_fun_ref(&Widge... » read more...

  • Effective API Design

    » read more...

  • CPP Info Memo part1(2)

    Table of Contents 1 Overview 1.1 Initial Processing 1.2 Tokenization 1.2.1 Preprocessor is greedy 1.2.2 Token Boundary 1.2.3 Tokens 的分类 1 Overview   1.1 Initial Processing   1.2 Tokenization   1.2.1 Preprocessor is greedy It always makes each token, starting from the left, as big as... » read more...

  • CPP Info Memo part 2

    Table of Contents 1 Overview 2 Header Files 2.1 Include 语法 2.2 Include 操作 2.2.1 头文件的展开 2.2.2 Files that can be included 2.3 搜索路径 2.3.1 默认路径 2.3.2 路径的修改 1 Overview   2 Header Files C 里面有很多声明和宏定义是专门用来在多个源文件(source file)中共享的, 这些东西被放在专门的文件中,即传说中的头文件(Header file)。 我们可以通过 #include... » read more...

  • CPP Info Memo (Part 1)

    CPP Info Memo (Part 1) Table of Contents 1 Overview 1.1 Initial Processing 1.1.1 End Of Line (EOL) 1.1.2 Continued lines 1.1.3 Comments 1 Overview   1.1 Initial Processing   1.1.1 End Of Line (EOL) GCC 能够识别的 EOL 包括 ASCII 码中的 LF, CR LF 和 CR , 也就是传说中的 "\n" "\r\n" 和 "\r"。 换句话... » read more...

  • Android Debug Bridge (adb) device - no permissions

      I have a problem connecting HTC Wildfire A3333 in debugging mode with my Fedora Linux 17. Adb says: ./adb devices List of devices attached ???????????? no permissions my udev rules (first rule for Samsung which works just fine and second for HTC which is not): SUBSYSTEM==”usb”,SYSFS{idVendor}==”04e8″,SYMLINK+=”android_adb”,MODE=”0666″,GROUP="plugd... » read more...

  • Adding Completion to (interactive)

      Adding Completion to (interactive) Author: Tubo Question: Is there any way to add my own completion to an (interactive) elisp function? Ideally, I'd like to pass it a list of strings that it would tab-complete from. I know that using (interactive "D"), (interactive "F") or (interactive "b") give you completion for directories, files and buffer-names respectively, but what about more general inputs? Answer: The argument to interactive need not be a string; if it isn't, it's evaluated ... » read more...

<前页 1 2 3 4 5 6 7 8 9 后页> (共180篇)