Learn C++ STL

Lesson 2 of 9 · list and forward_list: When Elements Move and Positions Must Not

Module 5 · list and forward_list: When Elements Move and Positions Must Not

Every list and forward_list Operation, One by One, With Its Cost

Free with an accountReading

Bob has a list of scores and wants them in order. He writes what worked on every vector: sort(l.begin(), l.end());. GCC 12 answers with over twenty lines, all from inside the library's own files. Bob scrolls, sighs, and asks Amara what he broke. Nothing: a list sorts itself with l.sort(), and this lesson shows why, along with every other call and its cost.

Checking what this lesson needs for you…

What is inside Every list and forward_list Operation, One by One, With Its Cost

  1. list: making one, and assign
  2. list: push_back and push_front
  3. list: pop_back and pop_front
  4. list: front, back, size and empty
  5. list: insert
  6. list: erase
  7. list: clear and resize
  8. list: remove and remove_if
  9. list: unique
  10. list: sort, and why std::sort does not compile
  11. list: merge
  12. list: reverse
  13. list: splice in three formsIntermediate
  14. list: swap
  15. Moving an iterator: ++, --, next, prev, advance and distance
  16. forward_list: before_begin, insert_after and erase_after
  17. forward_list: push_front, pop_front, and no push_back or size
  18. forward_list: splice_after and the member algorithmsIntermediate
  19. Every cost in two tables, and one measured splice