Fatih Çil

Self-Taught Developer

Software Engineer

Programmer

Game Developer

Fatih Çil

Self-Taught Developer

Software Engineer

Programmer

Game Developer

Blog Post

ft_containers: Reimplementing the STL

December 10, 2022 École 42

Hi! ft_containers is the boss fight of the C++ branch: reimplement std::vector, std::map, std::stack (and std::set for the bonus) in C++98, so faithfully that switching ft:: for std:: in a test suite changes nothing.

The deep ends

  • vector: manual memory management with allocators — capacity growth, placement construction and destruction, exception safety in insert,
  • iterators: writing real iterator classes with traits, plus enable_if/is_integral tricks (SFINAE in C++98!) so the right overloads win,
  • map: the big one — a red-black tree underneath, with rotations, rebalancing after insert and erase, and bidirectional iterators that walk the tree in order,
  • comparison & const-correctness: lexicographical_compare, const iterators, and all the operators nobody thinks about until they break.

What I took away

You stop being afraid of the standard library. After implementing a red-black tree and debugging its edge cases at 2 AM, std::map stops being a black box — you know what every operation costs and why. That intuition about data structures is probably the single most transferable thing I took from 42 into professional work.

Source code: github.com/Fatihcill/ft_containers

42 ft_containers badge

Related Posts