This repository contains my C++ snippets on C++ concepts/idioms, optimized C++, modern C++ and advanced C++. It includes snippets for using third-party libraries to parse CSV, YAML, and JSON files, an example of code benchmarking with Google Benchmark, and a tutorial on using CMake to build and export your project.
See BUILDING.md for CMake configuration, Docker usage (including GUI apps), and VSCode setup.
- Data Types, Numerical Limits, Machine Epsilon, Precision, std::nan
- Data Type Conversions, Casting, Type Coercion
- Static Casting, Dynamic Casting
- Const, Constexpr, consteval, constinit, Mutable
- Immutable Objects
- Decay
- Enum
- Functions, Function Objects, Function Pointer, Inline Functions
- Extern Variables, Extern Functions
- Lambda
- Callable Objects, Callbacks
- References, Lvalue/Rvalue, reference_wrapper, std::ref / std::cref
- Forwarding Reference
- Move Semantics, Copy Constructor, Move Constructor, Assignment
- Scope Resolution Operator
- Scope and Life Cycle of Objects Returned by Functions
- Nested Namespaces, Unnamed/Anonymous Namespaces
- Macros
- Literals
- Numeral Systems in C++ Decimal, Binary, Octal, Hexadecimal
- Big-endian, Little-endian
- Bitset, Bit field, Bitwise Operations
- Post-increment, Pre-increment, Unary plus
- Ternary (One Line If)
- Switch Case
- Setting argc, argv
- Simple Command Argument Parser
- Assert
- Attribute specifier sequence
[[attribute-list]] - Register Keyword
- Volatile Keyword
- Signals
- System Call
- Three-way comparison
<=>(C++20) - Structured binding declaration
- Heap and Stack, Memory Layout of C Programs
- Dynamic Memory Allocation in C
- Raw Pointers, Wild/Dangling, Memory Safety
- Smart Pointers (unique_ptr, shared_ptr, weak_ptr, atomic smart pointers)
- Memory Alignment (
alignas,alignof, cache lines, Eigen) - Allocator
- Track Memory Allocations (overriding new operator)
- Containers
- Iterator, for_each loop, range-for loop, Loop optimization
- Algorithms Library
- Ranges and Views (C++20)
- Execution Policies
- Hash Functions, Hash Data Structure (Hash Table)
- Function objects: std::less, std::greater, std::not1, std::unary_negate
- String C/C++, string_view, string literal, string conversion, ASCII, Unicode
- String View
- Basic IO Operation, Streams, Reading/Writing Files, cin, scanf, gets, getline, printf
- std::format and std::print (C++20/23)
- File System
- Regex
- Pseudo-random Number Generation, Distributions
- Clock, Date, Time
- Process, Inter Process Communication (IPC), Process Tree, Process Control Block (PCB)
- Forking
- Multithreading — Overview
- Creating and Terminating Threads (function pointer, member function, functor, lambda)
- Joining and Detaching Threads
- std::jthread and std::stop_token (C++20)
- Hardware Concurrency and Oversubscription
- Thread Identity, Sleeping, Yielding
- Race Conditions vs Data Races
- Mutex (std::scoped_lock, lock_guard, unique_lock)
- Deadlock and How to Avoid It
- Semaphores (counting, binary)
- Condition Variables and Spurious Wakeups
- std::future, std::async, std::promise, std::packaged_task
- std::atomic, Memory Ordering, ABA Problem
- Designing Thread-Safe Classes
- Atomic Operations and Atomic Types
- Asynchronous Programming
- Packaged Task
- Event handling / Concurrency / Thread Design Patterns
- Coroutines (C++20)
- Templates, Expression Templates
- Concepts (C++20)
- Template Specialization, Tag Dispatch
- Variadic Templates Function
- Parameter Pack Expansion
... - Substitution failure is not an error (SFINAE)
- Template argument deduction
- Type Traits
- Type Erasure
- Typedef, Type alias (using keyword)
- type_dispatch, integral_constant, true/false type
- Argument-dependent lookup (ADL)
- Error Handling
- Error Code
- Exception Handling, noexcept
- Return, Abort, Exit, Throw, Terminate
- Stack Unwinding
- C++20 Modules
- C++ Translation Units
- Conditional Compilation From CMakeLists
- Printing List of All Included Headers
- fPIE (Position Independent Executable) and fPIC (Position Independent Code)
- Optional, Variant, Any — when to use which
- Loading Classes Dynamically From Plugins
- Lexical Analyzer
- Tricky Questions
- Undefined behavior, Unspecified and Implementation-Defined
- Trivial, standard-layout, POD, and literal types
- Abstract Class Vs Interface
- Cast Base Class to Derived / Derived to Base
- Class Forward Declaration
- Class Constructor Initialization List
- Class Constructor Aggregate / Copy / Default / Direct / Value / Uniform / Zero Initialization
- Copy Constructor, Copy Assignment, Move Constructor, Assignment
- Shallow Copy, Deep Copy
- Cyclic (Circular) Dependency
- Default(=default), Deleted (=delete) Constructors
- Diamond Problem Virtual Inheritance
- Explicit Constructor, Converting Constructor
- Friend Functions
- Header Guard
- Inheritance, Inheritance Prevention (final)
- Multiple Inheritance Polymorphism
- Operator Overloading
- Object Slicing
- Passing Arguments To Parent Constructor
- Private Public Protected Inheritance
- Protected Friend Class Function
- Shadowing
- Static Member Function, Static Initialization Order Fiasco
- Special Member Functions
- Structs
- Virtual Function Abstract Class
- Virtual Destructor, Virtual Constructor
- Buffer overflow
- Copy and Swap
- Curiously Recurring Template Pattern (CRTP)
- Copy Elision, Return value optimization (RVO, NRVO)
- Double Dispatch
- Most Vexing Parse
- Metaprogramming
- Pointer to implementation (PIMPL) — see also smart_pointers_class_member.md §3
- Return Type Resolver
- Resource Acquisition Is Initialization (RAII)
- Rule of 3, Rule of 5
- Run-Time Type Information (RTTI)
- Stack overflow
- Temporary Objects
- Virtual Method Table (VTABLE), Virtual Table Pointer (VPTR)
- Virtual address space
- Compiler Explorer (godbolt.org)
- Sanitizers (ASan, TSan, UBSan, MSan, LSan)
- Memory Error Detection with AddressSanitizer and Valgrind
- Generating and Debugging Dump File
- Static analysis and linting with clang-tidy
- Monolithic Architecture vs REST API and Microservices
- REST APIs / Webhooks with cURL (libcurl)
- gRPC C++ (official)
- WebSockets with IXWebSocket
- WebRTC with libdatachannel
- GraphQL with cppgraphqlgen
- XML SOAP with tinyxml2 + cURL
- REST API with crow
- Mocking APIs with Mockoon
- Doxygen — API documentation, UML diagrams, GitHub Action integration
- CPack Packaging
- Semantic Versioning
- Getting Version From Git in CMake
- Getting Release Version From Git (check for update)
- SOLID Principles in C++
- Design a Reusable Library
- API and ABI Design for C++ Libraries (versioning, symbol visibility, stable ABI)
- Exception Safety Guarantees (basic, strong, no-throw)
- Error Handling Strategies and Fault Tolerance (error codes, exceptions,
std::expected,tl::expected) - Dependency Injection and Inversion of Control
- Resource Management Patterns (RAII, scope guards,
unique_resource)
- Object-Oriented Design Patterns (Factory, Singleton, Observer, Strategy, Visitor, Decorator, Adapter)
- Concurrency Patterns (Thread Pool, Producer-Consumer, Active Object, Reactor, Proactor)
- Event-Driven Architecture and State Machines (HSM,
boost::sml) - Pipeline and Dataflow Architectures
- Memory Management Strategies (Pool, Arena, Slab, Bump/Linear Allocators)
- Cache-Friendly Data Structures and Data-Oriented Design
- False Sharing, Cache Line Padding, NUMA Awareness
- Lock-Free Data Structures (SPSC/SPMC/MPMC, ring buffers, hazard pointers, RCU)
- Branch Prediction, Prefetching, and SIMD
- High-Performance Computing (HPC) Patterns (SPMD, fork-join, work stealing)
- Plugin Architecture and Dynamic Loading
- Modular Design with C++20 Modules and Build-System Architecture
- Serialization and Deserialization (Protobuf, FlatBuffers, Cap'n Proto, MessagePack)
- Inter-Process Communication and Shared Memory (mmap, Boost.Interprocess)
- Configuration Management (compile-time vs runtime, feature flags)
- Logging, Metrics, and Distributed Tracing (OpenTelemetry C++)
- Testing Strategies (mocking, fuzzing, property-based, contract testing)
- Designing for Testability (seams, dependency injection, fakes vs mocks)