233 words
1 minute
C++ Modules (00–09) — OOP, Memory Semantics, Templates & STL
C++ Modules (00 through 09)
The C++ modules in the 1337 / 42 curriculum transition from procedural C to object-oriented programming, generic metaprogramming, and STL container algorithms under the C++98 standard.
Curriculum Breakdown
| Module | Timeline | Core Focus |
|---|---|---|
| CPP 00–01 | 10 months ago | Namespaces, classes, member functions, references, memory allocation (new/delete). |
| CPP 02–03 | 9 months ago | Orthodox Canonical Class Form, fixed-point representation, operator overloading, class inheritance. |
| CPP 04–05 | 8 months ago | Subtype polymorphism, abstract interfaces, custom exception hierarchies (std::exception). |
| CPP 06–07 | 7 months ago | C++ cast operators (static_cast, dynamic_cast, const_cast, reinterpret_cast), function & class templates. |
| CPP 08 | 11 days ago | Templated containers, iterators, and generic algorithms (std::span, easyfind). |
| CPP 09 | 2 days ago | STL algorithms: Bitcoin exchange parsing, Reverse Polish Notation calculator, Ford-Johnson merge-insertion sort (PmergeMe). |
Implementation Details
1. Orthodox Canonical Class Form (OCF)
All classes follow strict copy and memory ownership semantics:
class Subject{public: Subject(); // Default constructor Subject(const Subject &other); // Copy constructor Subject &operator=(const Subject &rhs); // Copy assignment operator virtual ~Subject(); // Virtual destructor};2. Abstract Interfaces & Polymorphism
Decoupled class hierarchies implemented via pure virtual functions:
class ICharacter{public: virtual ~ICharacter() {} virtual std::string const &getName() const = 0; virtual void equip(AMateria *m) = 0; virtual void unequip(int idx) = 0; virtual void use(int idx, ICharacter &target) = 0;};3. Module 09: Ford-Johnson Merge-Insertion Sort (PmergeMe)
Implements the Ford-Johnson sorting algorithm to minimize comparisons:
- Recursively pairs and sorts elements.
- Inserts un-paired elements using Jacobsthal-number-guided binary insertion sequences.
- Benchmarked across
std::vectorandstd::dequewith identical sorted outputs.
Standards and Verification
- Compiled with
-Wall -Wextra -Werror -std=c++98. - Validated with zero memory leaks via Valgrind.
Sphynx | Ismail Larhrib