English | 中文
A hands-on project for systematically learning advanced C++ topics, focused on techniques commonly used in AI/LLM development: concurrency & thread pools, design patterns, modern C++ features, metaprogramming, and performance optimization.
Official C++ reference: https://en.cppreference.com
modern-cpp-forge/
├── CMakeLists.txt # Root build file
├── .clang-format # Code formatting config
├── .clang-tidy # Static analysis config
├── common/ # Shared library (logger, timer)
│ ├── include/common/
│ │ ├── logger.h # Thread-safe colored logging
│ │ └── timer.h # High-precision timer
│ └── src/
│ ├── logger.cpp
│ └── timer.cpp
├── reference/ # 📖 Reference implementations
│ ├── concurrency/ # Multithreading & concurrency
│ │ ├── thread_basics.cpp # Thread creation & management
│ │ ├── mutex_and_lock.cpp # Mutexes & lock types
│ │ ├── condition_variable.cpp # Condition variables & producer-consumer
│ │ ├── thread_pool.cpp # Complete thread pool
│ │ ├── atomic_operations.cpp # Atomics & lock-free programming
│ │ └── async_and_future.cpp # std::async & std::future
│ ├── design_patterns/ # Design patterns
│ │ ├── singleton.cpp # Singleton (3 variants)
│ │ ├── factory.cpp # Factory (registry-based)
│ │ ├── observer.cpp # Observer & event system
│ │ └── strategy.cpp # Strategy pattern
│ ├── memory_management/ # Memory management
│ │ ├── smart_pointers.cpp # Smart pointer deep dive
│ │ ├── move_semantics.cpp # Move semantics & perfect forwarding
│ │ └── raii.cpp # RAII resource management
│ ├── modern_cpp/ # Modern C++ features
│ │ ├── templates_and_concepts.cpp # Templates & C++20 Concepts
│ │ ├── lambda_and_functional.cpp # Lambda & functional programming
│ │ └── coroutines.cpp # C++20 Coroutines
│ ├── metaprogramming/ # Metaprogramming
│ │ └── type_traits_and_sfinae.cpp # Type traits & SFINAE
│ └── performance/ # Performance optimization
│ └── cache_friendly.cpp # Cache-friendly programming
├── src/ # ✏️ Practice code (your implementations)
│ ├── concurrency/
│ ├── design_patterns/
│ ├── memory_management/
│ ├── modern_cpp/
│ ├── metaprogramming/
│ └── performance/
├── tests/ # Unit tests
├── benchmarks/ # Performance benchmarks
├── docs/ # Documentation
│ └── learning_roadmap.md # Learning roadmap
├── scripts/ # Utility scripts
│ ├── build.sh # Build script
│ ├── clean.sh # Clean script
│ └── run.sh # Run script
└── .vscode/ # VS Code configuration
├── launch.json # F5 debug config
├── tasks.json # Build tasks
├── settings.json # Editor settings
└── extensions.json # Recommended extensions
- Compiler: GCC 10+ or Clang 12+ (C++20 support required)
- Build system: CMake 3.16+
- Debugger: GDB
- OS: Linux (Ubuntu 20.04+)
git clone https://github.com/zhanmyz/modern-cpp-forge.git
cd modern-cpp-forge# Option 1: Build script (recommended)
chmod +x scripts/*.sh
./scripts/build.sh debug # Debug mode (sanitizers enabled)
./scripts/build.sh release # Release mode (optimized)
# Option 2: Manual CMake
mkdir -p build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
cmake --build . --parallel $(nproc)# Run reference implementations
./bin/reference/concurrency/thread_basics
./bin/reference/design_patterns/singleton
./bin/reference/performance/cache_friendly
# Run tests
./bin/tests/test_logger
# Run benchmarks
./bin/benchmarks/bench_containers
# Using the run script
./scripts/run.sh thread_pool- Open any
.cppfile - Press
F5— auto-builds and debugs the current file - Breakpoints, variable inspection, call stack — all work out of the box
- Read the reference code under
reference/(detailed comments included) - Understand the core concepts and their AI/ML applications
- Implement your own version under
src/in the corresponding directory - Compare your implementation against the reference
- Experiment — tweak parameters, test edge cases, observe behavior
Suggested order: Memory Management → Concurrency → Design Patterns → Modern C++ → Metaprogramming → Performance
| Feature | Description |
|---|---|
| 🎨 Colored logging | Timestamped, thread-ID, file:line colored terminal output |
| ⏱️ Scoped timer | RAII-based auto-timing for performance measurement |
| 🔧 Modern CMake | Each source file compiles to its own executable |
| 🐛 Debug support | AddressSanitizer + UBSanitizer + GDB |
| 📏 Code standards | clang-format + clang-tidy configured |
| 📊 Benchmarks | Built-in performance comparison framework |
| 🧪 Unit tests | Test framework ready |
| 📖 Annotated code | Each concept explained with real-world analogies |
# Build
./scripts/build.sh debug
# Clean
./scripts/clean.sh
# Format code
find . -name "*.cpp" -o -name "*.h" | xargs clang-format -i
# Static analysis
clang-tidy src/**/*.cpp -- -std=c++20 -I common/include
# Run all tests
find build/bin/tests -type f -executable -exec {} \;- Create a reference implementation under
reference/<category>/ - Create a practice template under
src/<category>/ - Rebuild:
./scripts/build.sh debug - New files are auto-discovered by CMake
MIT