Is there a difference between using .begin() vs .end() for std::inserter for std::set?

前端 未结 2 1389
旧时难觅i
旧时难觅i 2021-01-01 10:59

If there is any difference between it1 and it2?

std::set s;

auto it1 = std::inserter(s, s.begin());
auto it2 = std::inserter(s, s.end());
<         


        
2条回答
  •  -上瘾入骨i
    2021-01-01 11:10

    From http://www.sgi.com/tech/stl/insert_iterator.html

    In the case of a Sorted Associative Container, however, the iterator in the insert_iterator's constructor is almost irrelevant. The new elements will not necessarily form a contiguous range; they will appear in the appropriate location in the container, in ascending order by key. The order in which they are inserted only affects efficiency: inserting an already-sorted range into a Sorted Associative Container is an O(N) operation.

提交回复
热议问题