Namespaces
Variants
Views
Actions

Talk:cpp/container/list/insert

From cppreference.com
< Talk:cpp‎ | container‎ | list
Revision as of 21:58, 19 April 2012 by P12bot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

[edit] Return value seems incorrect

The page states that the return value is the "iterator following the last inserted element". However, my understanding is that the returned iterator should point to the first element inserted. Thus, the newly inserted elements occupy the range [ret_val, pos).

From §23.2.3 of the C++11 standard:

  1. The iterator returned from a.insert(p, t) points to the copy of t inserted into a.
  2. The iterator returned from a.insert(p, rv) points to the copy of rv inserted into a.
  3. The iterator returned from a.insert(p, n, t) points to the copy of the first element inserted into a, or p if n == 0.
  4. The iterator returned from a.insert(p, i, j) points to the copy of the first element inserted into a, or p if i == j.
  5. The iterator returned from a.insert(p, i1) points to the copy of the first element inserted into a, or p if i1 is empty.

Thanks. 130.20.187.25 14:49, 21 March 2012 (PDT)

good catch. Updating. --Cubbi 18:52, 21 March 2012 (PDT)

[edit] Complexity for list

The complexity of insert for lists in C++11 (per §23.3.5.4) is:

1-2) Constant.

3) Linear in count

4) Linear in std::distance(first, last)

5) Linear in ilist.size()

130.20.187.25 15:47, 21 March 2012 (PDT)