
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
Containers, Iteration, Ranges
- Containers
- vector
- lists
- C arrays, std::array, std::span
- set, map, pair, tuple, tie, unordered_map, multimap, unordered_set, multiset
- Queue, Priority queue, deque, stack
- 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)
- Comparator function objects: std::less, std::greater, std::not_fn (and the deprecated std::not1)
Strings, I/O, and Formatting
- 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
Concurrency, Async, and Coroutines
- 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
- Coroutines (C++20)
- Abstract Class Vs Interface
- Cast Base Class to Derived / Derived to Base
- Class Forward Declaration
- Object Initialization & Static Lifetime
- Copy / Move semantics, Rule of 5, copy-and-swap, temporaries, shallow vs 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
- Special Member Functions
- Structs
- Virtual functions, abstract classes, virtual destructor, vtable / vptr
Advanced C++ Concepts and Idioms
Data File Storage Parsing
REST API, Microservices, and Communication Libraries
Event Streaming and Message Queuing
Code Benchmarking and Profiling
Documentation, Packaging, Versioning
C++ Coding Standards and Style
Principles and Foundations
- 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)
Architecture and Modularity
Observability and Testability
Domain-Specific Architectures