Containers and algorithms

This part of the C++ course is the standard library at work. An iterator is the interface every container shares, and an algorithm written once runs over all of them: find, count, transform, sort and binary search. Lambdas pass the comparison, std::map and std::set keep a key in order, and the adaptors wrap a container in a stack or a queue. The part ends with views, the numeric algorithms, a value that may be absent, one of several types, and the formatting that replaced a stream manipulator.

5.1 Iterators begin and end, iterator categories, ++ and *, const_iterator and std::distance Open 5.2 Algorithms find, count, any_of, transform and copy, and the difference between a loop and an algorithm Open 5.3 Sorting and searching sort, stable_sort, a custom comparator, lower_bound, binary_search and is_sorted Open 5.4 Lambda expressions capture by value and by reference, mutable lambdas, init captures and generic lambdas Open 5.5 Function objects and std::function a functor with state, std::function as a type-erased callable and the cost of the wrapper Open 5.6 std::map and std::unordered_map insert, find, operator[], iteration order, hashing and choosing between the two Open 5.7 std::set and std::unordered_set unique keys, insert and erase, set operations on sorted ranges and a visited set Open 5.8 deque, list and forward_list when a list beats a vector, splice, push_front and the memory each container spends Open 5.9 stack, queue and priority_queue the adaptor interface, the container underneath and a priority queue with a comparator Open 5.10 Ranges and views ranges::sort, views::filter, transform and take, and a lazy pipeline over a vector Open 5.11 Numeric algorithms accumulate, reduce, inner_product, iota and partial_sum in a running total Open 5.12 Tuples and pairs return two values, std::tie, structured bindings and std::apply Open 5.13 std::optional a value that may be absent, value_or, has_value, and a lookup that returns optional Open 5.14 std::variant one of several types, std::get, std::holds_alternative, std::visit and valueless_by_exception Open 5.15 std::format placeholders, format specifiers, alignment, numbers and a table built with std::format Open 5.16 std::print and std::println printing without iostream manipulators, formatting arguments, stdout and stderr Open

Lessons