今天读了些stl的源代码,感觉太爽了——感觉就想就想和自己女朋友刚认识的时候的一样,除了想和她在一起以外,没有任何别的想法;无时无刻都不在感谢上天赐予我这美妙的精灵。
呵呵,感觉自己又谈恋爱了。
就让我和你在我这满脑子就是荷尔蒙的时刻,和你分享这“爱情激素”的神奇。
一下是stl::vector::push_back的实现:

void push_back(const T& x) ...{
if (finish != end_of_storage) ...{
construct(finish, x);
++finish;
}
else
insert_aux(end(), x);
}
template <class T1, class T2>
inline void construct(T1* p, const T2& value) ...{
new (p) T1(value);
} 美妙之处:
I. the application of placement new.
II. the implement of insert_aux.
III. the beauty of writing style.
V. so many.....................................................~!
suggestion: read the source code as quick as possibly.
本文通过解析STL中vector::push_back的实现细节,展现了其优雅的设计思想。不仅介绍了placement new的应用,还深入探讨了insert_aux的实现机制,并赞赏了其简洁高效的编码风格。

340

被折叠的 条评论
为什么被折叠?



