CT 301 Exam 2 Topics
Scope
Exam 2 covers the Homework 2 material: the implementation of ct::Vector<T>. Anything from the assignment
is fair game, including both the interface you implemented and the reference implementation provided to you. You should be
able to read, explain, and reason about any part of it, not only how to use the vector but how its internals work and why.
The list below is the full set of topics it can draw on, each with where to read.
1. Memory management on the free store
- The two ways to manage a buffer: ordinary
new[]/delete[]versus the decoupled form the vector uses,::operator newfor raw bytes, placementnewto construct elements in place, explicit destruction (std::destroy_n,std::destroy_at, or an explicit~T()call), and::operator deleteto free. - What
allocate()anddeallocate()each do. - Why allocation and construction are separated, and how that lets capacity exceed size.
- Leaks, double-free, dangling pointers, and the cleanup order in the destructor (
clear()thendeallocate()).
Where to read: L7 · Tour §1.7, §5.2, §15.2 · PPP Ch. 15 · learncpp: 12.7, 19.1, 15.4 (placement new / ::operator new: no direct lesson)
2. Pointers, arrays, and iterators
- The buffer as contiguous memory; pointer arithmetic; why
p[i]equals*(p + i). - Iterators as raw pointers:
begin/end,cbegin/cend. - Reverse iterators built on
std::reverse_iterator:rbegin/rend,crbegin/crend. const_iteratorand const-correctness.- Turning an iterator into an index with
static_cast<size_type>(pos - begin()).
Where to read: L7, L8 · Tour §1.7, §15.3-15.4 · PPP Ch. 15-16 · learncpp: 12.7, 17.9
3. Essential operations: the rule of 5/7
- The destructor.
- Copy constructor and copy assignment as a deep copy (including copy-and-swap).
- Move constructor and move assignment that steal the buffer and leave the source empty, marked
noexcept. - Shallow versus deep copy, and the double-free bug a shallow copy causes.
- Self-assignment.
- The
assign()overloads andswap()(member and non-member).
Where to read: L9 · Tour Ch. 6, §16.6 · PPP Ch. 17 · learncpp: 14.14, 21.12, 21.13, 22.3
4. Element access and operators
operator[](no bounds check) versusat()(throwsstd::out_of_range).front(),back(), anddata().- The non-member
operator==.
Where to read: L6, L9 · Tour Ch. 6, §5.2.2 · PPP Ch. 17 · learncpp: 21.9, 21.x (operators)
5. Capacity and growth
size(),capacity(),empty(), andmax_size().reserve(): allocate a new buffer, move the elements over (std::uninitialized_move_n), destroy the old ones, and free.grow_if_needed()and the growth strategy: when capacity grows and by how much.shrink_to_fit().
Where to read: L7 · Tour §5.2, §15.3 · PPP Ch. 15 · learncpp: no direct lesson (manual capacity and growth are vector-internal)
6. The full Vector interface: constructors and modifiers
- Constructors: default, count, count-and-value, initializer-list, range (
first/last), copy, and move. - Modifiers:
clear,push_back(const&and&&),emplace_back,emplace,pop_back,insert(single value, count-and-value, range, initializer-list),erase(single and range), andresize(with and without a fill value). - How
insertandemplaceplace an element at a position usingstd::rotate.
Where to read: L7, L9 · Tour §5.2.2, Ch. 6 · PPP Ch. 15, 17 · learncpp: initializer-list constructors are covered in passing; the modifier set is vector-specific
7. Templates and member types
ct::Vector<T>as a class template, and the type parameterT.- The member type aliases (
using):value_type,size_type,iterator,const_iterator,reference, and the rest. - Using the vector with more than one element type.
Where to read: L10 · Tour Ch. 7 · PPP Ch. 18 · learncpp: 11.6, 13.13
8. Exceptions
at(),front(), andback()throwstd::out_of_range.reserve()andresize()throwstd::length_errorwhen a request would exceedmax_size().try/catch, and which operations can throw.
Where to read: L10 · Tour §4.2 · PPP Ch. 18 · learncpp: 27.2
9. Idioms used in the implementation
noexcept,explicit,static_cast,std::move,std::forward(perfect forwarding inemplaceandemplace_back), andstd::rotate.- The uninitialized-memory helpers:
std::uninitialized_copy,std::uninitialized_fill_n,std::uninitialized_move_n,std::uninitialized_value_construct_n. - The single-header design: the include guard
CT_VECTOR_H, thectnamespace, andtemplate <typename T>.
Where to read: L9, L10 · Tour Ch. 6, §16.6, Ch. 7 · PPP Ch. 17-18 · learncpp: 22.3, 27.2 (noexcept, perfect forwarding: no single lesson)
10. The driver
- The
driver.cppwork you wrote (thetotal()function and the data it processes), and reading values back out of a populated vector.
Where to read: Applies areas 1-9; no separate reading (your own code that uses the vector).
Where to read (at a glance)
The same mapping as above, gathered in one place.
| Topic area | Lecture | A Tour of C++ 3e (required) | PPP 3e (optional) | learncpp (if any) |
|---|---|---|---|---|
| 1. Memory management on the free store | L7 | §1.7, §5.2, §15.2 | Ch. 15 | 12.7, 19.1, 15.4 (placement new: no direct lesson) |
| 2. Pointers, arrays, and iterators | L7, L8 | §1.7, §15.3-15.4 | Ch. 15-16 | 12.7, 17.9 |
| 3. Essential operations: rule of 5/7 | L9 | Ch. 6, §16.6 | Ch. 17 | 14.14, 21.12, 21.13, 22.3 |
| 4. Element access and operators | L6, L9 | Ch. 6, §5.2.2 | Ch. 17 | 21.9, 21.x (operators) |
| 5. Capacity and growth | L7 | §5.2, §15.3 | Ch. 15 | no direct lesson (vector-internal) |
| 6. Constructors and modifiers | L7, L9 | §5.2.2, Ch. 6 | Ch. 15, 17 | init-list in passing; modifiers vector-specific |
| 7. Templates and member types | L10 | Ch. 7 | Ch. 18 | 11.6, 13.13 |
| 8. Exceptions | L10 | §4.2 | Ch. 18 | 27.2 |
| 9. Implementation idioms | L9, L10 | Ch. 6, §16.6, Ch. 7 | Ch. 17-18 | 22.3, 27.2 (noexcept, forwarding: no single lesson) |
| 10. The driver | applies areas 1-9 | (none) | (none) | your own code that uses the vector |
Also from the lectures (beyond the HW2 code)
These topics are taught in lectures 7 through 10 but are not part of the ct::Vector implementation. Review them as context. They are secondary to the areas above, which is where the exam concentrates.
- Smart pointers and RAII.
std::unique_ptrandstd::shared_ptras the managed-memory counterpart to the manualnew/deleteyou wrote in HW2.
L10 · Tour Ch. 6, §15.2 · PPP Ch. 18 · learncpp: 22.5, 22.6
Section numbers (§) refer to A Tour of C++ 3rd ed. (required); chapter numbers in the PPP references are Programming: Principles and Practice using C++ 3rd ed. (optional).