Complexity requirements for std::deque::push_back/front

前端 未结 2 1081
迷失自我
迷失自我 2021-01-02 03:33

As a result of this question from a few days ago there are a few things that have been bugging me about the complexity requirements for std::deque::push_back/push_fron

相关标签:
2条回答
  • 2021-01-02 04:13

    I suspect that the reallocation of the block pointers is done with a geometrically increasing size - this is a common trick for std::vector. I think this is technically O(log m) but as you point out m << n, so as a practical matter it doesn't affect the real-world results.

    0 讨论(0)
  • 2021-01-02 04:17

    In the C++11 FDIS, we can read:

    23.2.3 Sequence containers [sequence.reqmts]

    16/ Table 101 lists operations that are provided for some types of sequence containers but not others. An implementation shall provide these operations for all container types shown in the “container” column, and shall implement them so as to take amortized constant time.

    Where Table 101 is named Optional sequence container operations and lists deque for the push_back and push_front operations.

    Therefore, it seems more like a slight omission in the paragraph you cited. Perhaps worth a Defect Report ?

    Note that the single call to a constructor still holds.

    0 讨论(0)
提交回复
热议问题