A collection of modern C++ coding examples and small exercises, focused on correctness, clarity, and real‑world patterns.
This repository is intended as:
- A interview‑prep playground
- A reference for concurrency, synchronization, low‑level and modern C++ techniques
- A growing set of self‑contained, buildable examples
- A collection of more useful examples (and CLI tools) than leetcode puzzles.
Examples include (and will expand to):
- Multithreading
- Smart pointers
- Lock‑free / wait‑free data structures
- Views
- Atomics and memory ordering
- Folding
- RAII and ownership patterns
- Parallelism
- Performance‑oriented C++ idioms
- STL and ranges:
- Algorithms
- Data Structures
- OOP
Repository Structure
cpp-coding-exercise/
├── Makefile # top-level dispatcher
├── common.mk # shared compiler flags
├── thread-safe-queue/
│ ├── Makefile
│ └── main.cpp
├── <future-example>/
│ ├── Makefile
│ └── ...
└── .github/workflows/
└── ci.yml # GitHub Actions CI
Design principles
- Each example is self-contained
- Each folder has its own
Makefile - The top-level
Makefileautomatically discovers and builds all examples - No central list to maintain when adding new folders
Building
C++ Version
sudo apt update sudo apt install g++-14
Build everything
This will recursively build every directory that contains a Makefile.
Build a single example
cd thread-safe-queue
makeRunning examples
Runnable examples expose a run target:
make run on top level will run all built targets.
Cleaning
Clean everything:
Or clean a single example:
cd thread-safe-queue
make cleanShared build configuration
Common compiler settings live in common.mk:
CXX := g++ CXXFLAGS := -std=c++23 -Wall -Wextra
Individual examples may extend this, e.g.:
Address Sanitizer Check
The Address Sanitizer is enabled by default to ensure there is no memory leaks or other memory problems.
# Builds with AddressSanitizer automatically make # ThreadSanitizer make SANITIZE=thread # UndefinedBehaviorSanitizer make SANITIZE=undefined # No sanitizers make SANITIZE=
Clang Format
The clang-format is used to ensure the code format.
./clang-check.sh *.cpp *.hpp
At top level, you can do:
At each example directory, you can do:
Continuous Integration
GitHub Actions automatically builds all examples on:
- Every push
- Every pull request
The CI setup requires no updates when new example folders are added.
The CI will perform:
./clang-check.sh *.cpp *.hppmake SANITIZE=[address, thread, undefined]make runwhich will runmake runfor each project and./tests.shif it is present.
Toolchain
- C++23
- GNU Make
- GCC / Clang (CI currently uses GCC)
- Linux (Ubuntu)
Goals (non-goals)
-
✔ Correctness over cleverness
-
✔ Explicit concurrency semantics
-
✔ Minimal dependencies
-
✘ No frameworks
-
✘ No large abstractions
-
✘ No header‑only meta‑programming for its own sake
License
MIT (unless otherwise stated in a specific example).
Notes
Many examples intentionally focus on edge cases and failure modes (data races, lifetime issues, ordering bugs). They are meant to be read, built, and experimented with.
Contributions and discussions are welcome.