A comprehensive C++ knowledge repository covering everything from basic syntax to advanced patterns and modern C++ features (C++11/14/17/20).
- BasicDataTypes.cpp - Fundamental data types, operators, references, and modern type features
- BasicControlFlows.cpp - Control structures, loops, lambdas, and C++20 concepts
- BasicAbstractions.cpp - Classes, structs, unions, and basic data structures
- Threads.cpp - Basic threading with std::thread and mutexes
unique_ptr- Exclusive ownership semanticsshared_ptr- Shared ownership with reference countingweak_ptr- Breaking circular references- Custom deleters and polymorphism with smart pointers
- Factory patterns with smart pointers
- Lvalue vs Rvalue references
- Move constructors and move assignment operators
- Perfect forwarding with
std::forward - Universal references (forwarding references)
- Return Value Optimization (RVO)
- Move-only types
- STL integration with move semantics
- Template specialization (full and partial)
- Variadic templates and fold expressions
- SFINAE (Substitution Failure Is Not An Error)
- Type traits and type transformations
- Tag dispatching
- Template template parameters
- Non-type template parameters
- Expression templates
- CRTP - Curiously Recurring Template Pattern
- Singleton - Thread-safe singleton implementation
- Factory - Traditional and modern registration-based factories
- Observer - Event notification pattern
- Strategy - Runtime algorithm selection
- PIMPL - Pointer to Implementation idiom
- Builder - Step-by-step object construction
- Adapter - Interface adaptation pattern
std::asyncandstd::futurestd::promisefor cross-thread communication- Atomic operations and memory ordering
- Condition variables
- Producer-consumer pattern
- Thread pools
shared_mutexfor reader-writer locksscoped_lockfor deadlock preventionpackaged_taskandshared_futurecall_oncefor initialization
- STL algorithms (sort, find, transform, accumulate, etc.)
- Custom iterators implementation
- Iterator adaptors (back_inserter, reverse_iterator, move_iterator)
- Modern containers (unordered_map, multimap, set)
std::optionalfor optional valuesstd::variantfor type-safe unionsstd::anyfor type-erased storage- Function objects and
std::bind - Numeric algorithms
- Ranges concept (C++20)
constexprfunctions and variablesconstexprclassesif constexprfor compile-time branching- Template metaprogramming
- Compile-time computations (factorial, fibonacci, primes)
- Type computations at compile time
constexprlambdasconstevalandconstinitconcepts (C++20)- Practical compile-time examples
- LRUCache.cpp - Complete LRU cache implementation with disk I/O
- C++17 or later compiler (GCC 7+, Clang 5+, MSVC 2017+)
- For best experience, use C++20 compatible compiler
# Using g++
g++ -std=c++17 -pthread src/main.cpp -o main
# Using clang++
clang++ -std=c++17 -pthread src/main.cpp -o main
# For C++20 features
g++ -std=c++20 -pthread src/main.cpp -o main./main- BasicDataTypes.cpp
- BasicControlFlows.cpp
- BasicAbstractions.cpp
- SmartPointers.cpp
- MoveSemantics.cpp
- Threads.cpp
- ModernSTL.cpp
- DesignPatterns.cpp
- AdvancedTemplates.cpp
- AdvancedConcurrency.cpp
- CompileTime.cpp
- LRUCache.cpp (practical implementation)
- Auto and decltype
- Lambda expressions
- Smart pointers
- Move semantics
- Variadic templates
- constexpr
- Thread library
- nullptr
- Generic lambdas
- Return type deduction
- make_unique
- Extended constexpr
- Structured bindings
- if constexpr
- std::optional, std::variant, std::any
- Fold expressions
- constexpr lambda
- shared_mutex
- Concepts and requires
- consteval
- constinit
- Ranges
RevisitCPP/
βββ src/
β βββ main.cpp # Main entry point
β βββ BasicDataTypes.cpp # Basic types
β βββ BasicControlFlows.cpp # Control flow
β βββ BasicAbstractions.cpp # OOP basics
β βββ Threads.cpp # Basic threading
β βββ SmartPointers.cpp # Smart pointer patterns
β βββ MoveSemantics.cpp # Move & forward
β βββ AdvancedTemplates.cpp # Template programming
β βββ DesignPatterns.cpp # Design patterns
β βββ AdvancedConcurrency.cpp # Advanced threading
β βββ ModernSTL.cpp # STL features
β βββ CompileTime.cpp # Compile-time prog
β βββ LRUCache.cpp # LRU implementation
βββ tests/
β βββ LRUCacheTests.cpp # Unit tests
βββ README.md # This file
- Smart pointers (unique_ptr, shared_ptr, weak_ptr)
- Move semantics
- RAII patterns
- Custom allocators
- Threads and mutexes
- Futures and promises
- Atomics
- Thread pools
- Lock-free programming basics
- Generic programming
- Template metaprogramming
- Type traits
- SFINAE
- Concepts
- CRTP
- PIMPL
- Type erasure
- Expression templates
- Policy-based design
- β RAII (Resource Acquisition Is Initialization)
- β Rule of Five (copy/move constructors and assignment)
- β const correctness
- β noexcept specifications
- β Smart pointer usage over raw pointers
- β Move semantics for performance
- β constexpr for compile-time computation
- β Modern STL algorithms over manual loops
- β Lambda expressions for concise code
- β Structured bindings for readability
Feel free to add more examples, patterns, or improve existing code!
MIT License - See LICENSE file for details
This repository is designed for:
- Learning modern C++ features
- Understanding advanced patterns
- Interview preparation
- Quick reference for C++ idioms
- Teaching C++ best practices