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 than leetcode puzzles.
Examples include (and will expand to):
- thread-safe-queue
- Smart pointers
- Lock‑free / wait‑free data structures
- Views
- Atomics and memory ordering
- Folding
- RAII and ownership patterns
- Parallelism
- Performance‑oriented C++ idioms
- Algorithms
- OOP
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
- 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
makeThis will recursively build every directory that contains a Makefile.
cd thread-safe-queue
makeRunnable examples expose a run target:
make runmake run on top level will run all built targets.
Clean everything:
make cleanOr clean a single example:
cd thread-safe-queue
make cleanCommon compiler settings live in common.mk:
CXX := g++
CXXFLAGS := -std=c++23 -Wall -WextraIndividual examples may extend this, e.g.:
CXXFLAGS += -pthreadThe 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=The clang-format is used to ensure the code format.
./clang-check.sh *.cpp *.hppAt top level, you can do:
make check-format-allAt each example directory, you can do:
make check-formatGitHub 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.
- C++23
- GNU Make
- GCC / Clang (CI currently uses GCC)
- Linux (Ubuntu)
-
✔ Correctness over cleverness
-
✔ Explicit concurrency semantics
-
✔ Minimal dependencies
-
✘ No frameworks
-
✘ No large abstractions
-
✘ No header‑only meta‑programming for its own sake
MIT (unless otherwise stated in a specific example).
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.