# learn_stl **Repository Path**: thammer/learn_stl ## Basic Information - **Project Name**: learn_stl - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-30 - **Last Updated**: 2026-08-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # STL Learning Project This project is a systematic C++ Standard Template Library (STL) learning tutorial, guiding developers through 11 progressive stages to deeply understand STL's core concepts and practical applications. ## Project Overview This project employs a "theory explanation + code demonstration" approach, covering topics from basic template syntax to advanced memory management. Each stage includes detailed conceptual explanations and accompanying exercises to help learners build a comprehensive STL knowledge system. ## Project Structure ``` learn_stl/ ├── 00_templates/ # Stage 0: Template Fundamentals ├── 01_raii/ # Stage 1: RAII Enhancement ├── 02_lambda/ # Stage 2: Lambda and std::function ├── 03_sequence/ # Stage 3: Sequence Containers ├── 04_optional_variant/ # Stage 4: std::optional and std::variant ├── 05_iterators/ # Stage 5: Iterators ├── 06_algorithms/ # Stage 6: Algorithms ├── 07_associative/ # Stage 7: Associative Containers ├── 08_adapters_chrono/ # Stage 8: Adapters and chrono ├── 09_allocators/ # Stage 9: Allocators and Memory └── 10_advanced/ # Stage 10: Advanced Topics (Optional) ``` ## Stage Overview | Stage | Topic | Core Concepts | |-------|-------|---------------| | 0 | Template Fundamentals | Function templates, class templates, CTAD, specialization, constexpr, explicit, type_traits | | 1 | RAII Enhancement | Rule of Five, move semantics, unique_ptr, shared_ptr, weak_ptr, noexcept | | 2 | Lambda | Lambda expressions, capture semantics, std::function, callback patterns | | 3 | Sequence Containers | vector, string, array, deque, list, forward_list, span, initializer_list | | 4 | Optional and Variant | std::optional, std::variant, std::visit | | 5 | Iterators | Five iterator categories, iterator_traits, iterator invalidation rules | | 6 | Algorithms | Non-modifying algorithms, modifying algorithms, sorting algorithms, binary search, Erase-Remove idiom | | 7 | Associative Containers | pair/tuple, map/set, unordered_map/set, container selection | | 8 | Adapters and chrono | stack, queue, priority_queue, duration, timing | | 9 | Allocators and Memory | std::allocator, custom allocators, memory pools, embedded systems | | 10 | Advanced Topics | string_view, Ranges, PMR, structured bindings | ## Getting Started ### Prerequisites - C++ compiler supporting C++17 or higher (recommended: C++20) - CMake 3.15+ ### Build and Run ```bash mkdir build && cd build cmake .. make ./learn_stl ``` ### Learning Recommendations 1. **Progressive Learning**: Follow the stages in order; master each before proceeding to the next. 2. **Hands-on Practice**: Write code to verify each concept yourself. 3. **Complete Exercises**: The exercises at each stage are the best way to reinforce your understanding. 4. **Consult Documentation**: Use [cppreference.com](https://en.cppreference.com/) as a reference to deepen your comprehension. ## Detailed Content ### Stage 0: Template Fundamentals Master explicit and implicit instantiation of function templates, on-demand instantiation of class template member functions, template specialization (full and partial), the distinction between constexpr and const, and compile-time branching using if constexpr. ### Stage 1: RAII Enhancement Understand the semantics of the Rule of Five (Rule of Three/Five/Zero), distinguish between rvalue references and std::move for move semantics, effectively use unique_ptr and shared_ptr for resource management, and comprehend how noexcept affects container resizing strategies. ### Stage 2: Lambda and std::function Master the basic syntax and capture semantics of lambdas (by value/by reference), understand the role of mutable, and learn to use std::function to implement type-erased callback patterns. ### Stage 3: Sequence Containers Deeply understand vector’s three-pointer memory model and expansion mechanism, string’s SSO optimization, deque’s segmented contiguous structure, and why std::sort cannot be used on list. ### Stage 4: std::optional and std::variant Learn to use optional to replace sentinel values, understand the advantages of variant as a type-safe union, and master using std::visit for type dispatching over variants. ### Stage 5: Iterators Understand the hierarchical capabilities of the five iterator categories, grasp the extraction mechanism of iterator_traits, and be aware of iterator invalidation caused by container operations. ### Stage 6: Algorithms Familiarize yourself with the `[first, last)` range convention, understand the complexity characteristics of common algorithms, and learn to use the Erase-Remove idiom for element deletion. ### Stage 7: Associative Containers Understand the pitfalls of map’s operator[], recognize the underlying differences between red-black trees and hash tables, and choose appropriate containers based on use cases. ### Stage 8: Adapters and chrono Master the usage of stack, queue, and priority_queue; understand how to implement max-heaps and min-heaps with custom comparators; learn to use chrono for precise timing. ### Stage 9: Allocators and Memory Understand the two-level allocation mechanism of the default allocator, comprehend allocator interface requirements, and implement a simple fixed-size memory pool. ### Stage 10: Advanced Topics Optional advanced topics include in-depth applications of modern C++ features such as string_view, Ranges, PMR allocators, and structured bindings. ## License This project is intended solely for learning and educational purposes. ## References - [cppreference.com](https://en.cppreference.com/) - C++ Reference Manual - *Stl Source Code Analysis* - Hou Jie - *Effective C++* - Scott Meyers - *C++ Primer* - Lippman