美得让人窒息

本文通过解析STL中vector::push_back的实现细节,展现了其优雅的设计思想。不仅介绍了placement new的应用,还深入探讨了insert_aux的实现机制,并赞赏了其简洁高效的编码风格。

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值