In which scenario do I use a particular STL container?

后端 未结 10 933
遥遥无期
遥遥无期 2020-11-22 00:31

I\'ve been reading up on STL containers in my book on C++, specifically the section on the STL and its containers. Now I do understand each and every one of them have their

10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 01:11

    I answered this in another question which is marked as dup of this one. But I feel that it is nice to refer to some good articles regarding the decision to choose a standard container.

    As @David Thornley answered, std::vector is the way to go if there are no other special needs. This is the advice given by the creator of C++, Bjarne Stroustrup in a 2014 blog.

    Here is the link for the article https://isocpp.org/blog/2014/06/stroustrup-lists

    and quote from that one,

    And, yes, my recommendation is to use std::vector by default.

    In the comments, user @NathanOliver also provides another good blog, which has more concrete measurements. https://baptiste-wicht.com/posts/2012/12/cpp-benchmark-vector-list-deque.html .

提交回复
热议问题