Lesson 20 of 45 · C++
Lesson 27: Standard Template Library (STL) Overview
Duration: 13 min
Lesson 20 of 45 · C++
Duration: 13 min
vector, deque, list, forward_list, array.\n- Associative containers – set, map, multiset, multimap.\n- Unordered associative containers – unordered_set, unordered_map.\n- Container adapters – stack, queue, priority_queue.\n\n## Iterators\nIterators are abstractions over pointer‑like traversal. They come in categories:\n- Input, Output, Forward, Bidirectional, Random‑Access.\n- The container determines the iterator category it provides.\n\n## Algorithms\nAll algorithms are generic functions that operate on iterator ranges. Examples include std::sort, std::find, std::copy, std::transform.\n\n---\n\n## Example: Using std::copy with a vector\ncpp\nstd::vector<int> src = {1, 2, 3, 4, 5};\nstd::vector<int> dst(src.size());\nstd::copy(src.begin(), src.end(), dst.begin());\nfor (int v : dst) std::cout << v << ' ';\nstd::cout << '\\n';\n\n\n> Tip: Choose the container that matches the required complexity guarantees (e.g., std::list for O(1) insertions anywhere, std::vector for contiguous storage and cache‑friendly iteration).\n\n---\n\n<Alert type="info">Many STL algorithms have overloads that accept range objects (C++20) – you can write std::ranges::copy(src, dst);.