What is the complexity of std::vector::clear() when T is a primitive type?

前端 未结 2 1571
离开以前
离开以前 2020-12-17 16:30

I understand that the complexity of the clear() operation is linear in the size of the container, because the destructors must be called. But what about primitive types (and

2条回答
  •  爱一瞬间的悲伤
    2020-12-17 16:33

    gcc's version of std::_Destroy, which is what is eventually used by clear(), tries to template on on whether the type has a trivial destructor, so in that case the complexity is constant even without an optimisation pass. However I don't know how well the template works.

提交回复
热议问题