Iterators and Ranges in the C++ Standard Library
Today we continued our discussion of the C++ Standard Library, focusing on the interaction of how containers, algorithms, and iterators work.
All C++ containers provide these pointer-like objects called "iterators" when you call .begin() or .end() on them. Begin() returns an iterator pointing to the first element in the container, end() returns an iterator pointing to one past the end of the container. You can do math with iterators, such as vec.begin()+3 to point at the element in the vector 3 after the beginning.
Typically you pass pairs of iterators to standard library algorithms (like sort() or shuffle() or whatever), which specify what range of a container you want to sort or shuffle or whatever. The only trick is to remember that the element pointed to by the second parameter is not included in the sorting or shuffling, this is because of the half-open range pattern that you're familiar with from doing for loops in CSCI 40.
Other Videos By Bill Kerney
2022-02-11 | ACM Workshop: Intro to Python |
2022-02-11 | Ethics (Part III): Kantian Ethics, Natural Rights |
2022-02-10 | Importing a material into UE4 in 10 minutes |
2022-02-09 | Introduction to Linked Lists |
2022-02-09 | Facial Recognition and Ethics (Part II on Ethics) |
2022-02-08 | UE4 Niagara (+ a bit on Source Control) |
2022-02-07 | Advice on how to approach the RTX On project |
2022-02-07 | The Ethics of NFTs |
2022-02-04 | Bounding Volume Hierarchy |
2022-02-04 | Conditionals |
2022-02-02 | Iterators and Ranges in the C++ Standard Library |
2022-02-02 | Truth Tables |
2022-02-01 | The Rasterization Pipeline in an Hour |
2022-01-31 | The Standard Library |
2022-01-31 | Evaluating Claims Pt 2., Invalid/Valid/Sound Arguments |
2022-01-29 | Ways of Knowing, Making an Argument |
2022-01-28 | Separate Compilation in C++ |
2022-01-27 | Unreal Engine Materials in 20 minutes |
2022-01-27 | ARM32 - Dynamic Arrays, Classes in Assembly |
2022-01-26 | Sorting Objects in C++, The Rule of 3 |
2022-01-25 | Ludology: Principles of Game Design |