|
| 1 | +# cpp-coding-exercise |
| 2 | + |
| 3 | +A collection of **modern C++ coding examples** and small exercises, focused on correctness, clarity, and real‑world patterns. |
| 4 | + |
| 5 | +This repository is intended as: |
| 6 | + |
| 7 | +* A interview‑prep playground |
| 8 | +* A reference for **concurrency, synchronization, low‑level and modern C++ techniques** |
| 9 | +* A growing set of **self‑contained, buildable examples** |
| 10 | +* A collection of more useful examples than leetcode puzzles. |
| 11 | + |
| 12 | +Examples include (and will expand to): |
| 13 | + |
| 14 | +* Thread‑safe queue |
| 15 | +* Lock‑free / wait‑free data structures |
| 16 | +* Atomics and memory ordering |
| 17 | +* RAII and ownership patterns |
| 18 | +* Performance‑oriented C++ idioms |
| 19 | +* Smart pointers |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +## Repository Structure |
| 24 | + |
| 25 | +```text |
| 26 | +cpp-coding-exercise/ |
| 27 | +├── Makefile # top-level dispatcher |
| 28 | +├── common.mk # shared compiler flags |
| 29 | +├── thread-safe-queue/ |
| 30 | +│ ├── Makefile |
| 31 | +│ └── main.cpp |
| 32 | +├── <future-example>/ |
| 33 | +│ ├── Makefile |
| 34 | +│ └── ... |
| 35 | +└── .github/workflows/ |
| 36 | + └── ci.yml # GitHub Actions CI |
| 37 | +``` |
| 38 | + |
| 39 | +### Design principles |
| 40 | + |
| 41 | +* **Each example is self-contained** |
| 42 | +* Each folder has its own `Makefile` |
| 43 | +* The top-level `Makefile` automatically discovers and builds all examples |
| 44 | +* No central list to maintain when adding new folders |
| 45 | + |
| 46 | +--- |
| 47 | + |
| 48 | +## Building |
| 49 | + |
| 50 | +### Build everything |
| 51 | + |
| 52 | +```bash |
| 53 | +make |
| 54 | +``` |
| 55 | + |
| 56 | +This will recursively build every directory that contains a `Makefile`. |
| 57 | + |
| 58 | +### Build a single example |
| 59 | + |
| 60 | +```bash |
| 61 | +cd thread-safe-queue |
| 62 | +make |
| 63 | +``` |
| 64 | + |
| 65 | +--- |
| 66 | + |
| 67 | +## Running examples |
| 68 | + |
| 69 | +Runnable examples expose a `run` target: |
| 70 | + |
| 71 | +```bash |
| 72 | +make run |
| 73 | +``` |
| 74 | + |
| 75 | +This keeps CI safe (build-only by default) while allowing local execution. |
| 76 | + |
| 77 | +--- |
| 78 | + |
| 79 | +## Cleaning |
| 80 | + |
| 81 | +Clean everything: |
| 82 | + |
| 83 | +```bash |
| 84 | +make clean |
| 85 | +``` |
| 86 | + |
| 87 | +Or clean a single example: |
| 88 | + |
| 89 | +```bash |
| 90 | +cd thread-safe-queue |
| 91 | +make clean |
| 92 | +``` |
| 93 | + |
| 94 | +--- |
| 95 | + |
| 96 | +## Shared build configuration |
| 97 | + |
| 98 | +Common compiler settings live in `common.mk`: |
| 99 | + |
| 100 | +```make |
| 101 | +CXX := g++ |
| 102 | +CXXFLAGS := -std=c++20 -O2 -Wall -Wextra |
| 103 | +``` |
| 104 | + |
| 105 | +Individual examples may extend this, e.g.: |
| 106 | + |
| 107 | +```make |
| 108 | +CXXFLAGS += -pthread |
| 109 | +``` |
| 110 | + |
| 111 | +--- |
| 112 | + |
| 113 | +## Continuous Integration |
| 114 | + |
| 115 | +GitHub Actions automatically builds all examples on: |
| 116 | + |
| 117 | +* Every push |
| 118 | +* Every pull request |
| 119 | + |
| 120 | +The CI setup requires **no updates** when new example folders are added. |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +## Toolchain |
| 125 | + |
| 126 | +* C++20 |
| 127 | +* GNU Make |
| 128 | +* GCC / Clang (CI currently uses GCC) |
| 129 | +* Linux (Ubuntu) |
| 130 | + |
| 131 | +--- |
| 132 | + |
| 133 | +## Goals (non-goals) |
| 134 | + |
| 135 | +- ✔ Correctness over cleverness |
| 136 | +- ✔ Explicit concurrency semantics |
| 137 | +- ✔ Minimal dependencies |
| 138 | + |
| 139 | +- ✘ No frameworks |
| 140 | +- ✘ No large abstractions |
| 141 | +- ✘ No header‑only meta‑programming for its own sake |
| 142 | + |
| 143 | +--- |
| 144 | + |
| 145 | +## License |
| 146 | + |
| 147 | +[MIT](./LICENSE) (unless otherwise stated in a specific example). |
| 148 | + |
| 149 | +--- |
| 150 | + |
| 151 | +## Notes |
| 152 | + |
| 153 | +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. |
| 154 | + |
| 155 | +Contributions and discussions are welcome. |
0 commit comments