美得让人窒息

来源:互联网 发布:医学图像三维重建软件 编辑:程序博客网 时间:2024/04/29 14:51

    今天读了些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.

原创粉丝点击