C++0x issue: Constant time insertion into std::set

后端 未结 4 1426
生来不讨喜
生来不讨喜 2021-02-20 04:21

According to this page, I can achieve constant time insertion if I use

iterator std::set::insert ( iterator position, const value_type& x );
<
4条回答
  •  情话喂你
    2021-02-20 04:44

    Only supplying an iterator that falls immediately after the new value makes any sense.

    That's because in a collection of N elements, there are N+1 possible insertion points. An iterator exists that comes after a value higher than any preexisting element, but there is no iterator that comes before a value before all elements.

提交回复
热议问题