English
Summary
Conclusions
An array fixes the number of elements, while a vector allows changing it. Size and capacity have different meanings; reallocation affects the validity of addresses and references. A string owns its bytes, while string_view only observes them. Algorithms must preserve bounds, the link between the fields of a record and the lifetime of the owner.
Self-check questions
- What is the last index of an array with N elements?
- How does array differ from a built-in array?
- What does at check, and what does [] not guarantee?
- When does a loop need auto&?
- How does reserve differ from resize?
- When does push_back invalidate references?
- What is the precondition of binary search?
- Why is the whole record sorted rather than one of its fields?
- Why can a vector of vectors be non-rectangular?
- What does string::size count in UTF-8?
- What does npos mean?
- Why does cctype not decode UTF-8 Cyrillic?
- How is the complete result of from_chars checked?
- How does string_view::substr differ from string::substr?
- What conditions make a view dangling?
Review questions for the lab
- When is a vector empty after reserve?
- How do you correctly check a number entered by the user?
- Why is [] not checked access?
- When does the address of an element stop being valid?
- How do you avoid skipping an element after erase?
- Why does binary search require sorting?
- What is the difference between a string and a view?
- Why does size not count UTF-8 letters?
- How do you determine that a number was parsed completely?
- How does splitting words differ from CSV?
Useful links
- Vector: https://learn.microsoft.com/cpp/standard-library/vector-class.
- Array: https://learn.microsoft.com/cpp/standard-library/array-class-stl.
- String view: https://learn.microsoft.com/cpp/standard-library/basic-string-view-class.
- Conversions: https://learn.microsoft.com/cpp/standard-library/charconv-functions.