Skip to content

Commit d709cd7

Browse files
committed
Templating
1 parent 69a4017 commit d709cd7

9 files changed

Lines changed: 317 additions & 0 deletions

File tree

‎.github/FUNDING.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
github: doctorlai
2+
patreon: doctorlai
3+
buy_me_a_coffee: y0BtG5R
4+
thanks_dev: doctorlai
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Screenshots**
24+
If applicable, add screenshots to help explain your problem.
25+
26+
**Desktop (please complete the following information):**
27+
- OS: [e.g. iOS]
28+
- Browser [e.g. chrome, safari]
29+
- Version [e.g. 22]
30+
31+
**Smartphone (please complete the following information):**
32+
- Device: [e.g. iPhone6]
33+
- OS: [e.g. iOS8.1]
34+
- Browser [e.g. stock browser, safari]
35+
- Version [e.g. 22]
36+
37+
**Additional context**
38+
Add any other context about the problem here.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

‎.github/workflows/ci.yml‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: C++ Build
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
strategy:
12+
matrix:
13+
compiler: [g++]
14+
15+
steps:
16+
- name: Checkout repo
17+
uses: actions/checkout@v4
18+
19+
- name: Install build tools
20+
run: |
21+
sudo apt-get update
22+
sudo apt-get install -y build-essential
23+
24+
- name: Build all examples
25+
run: |
26+
make
27+
28+
- name: Run examples
29+
run: |
30+
for dir in */ ; do
31+
if [ -f "$dir/Makefile" ]; then
32+
echo "Running $dir"
33+
(cd "$dir" && make run || true)
34+
fi
35+
done
36+
37+
- name: Clean
38+
run: |
39+
make clean

‎LICENSE‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 DoctorLai
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎Makefile‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
SUBDIRS := $(dir $(wildcard */Makefile))
2+
3+
.PHONY: all clean $(SUBDIRS)
4+
5+
all: $(SUBDIRS)
6+
7+
$(SUBDIRS):
8+
$(MAKE) -C $@
9+
10+
clean:
11+
for dir in $(SUBDIRS); do \
12+
$(MAKE) -C $$dir clean; \
13+
done

‎README.md‎

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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.

‎common.mk‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CXX := g++
2+
CXXFLAGS := -std=c++20 -O2 -Wall -Wextra

‎thread-safe-queue/Makefile‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# pull in shared compiler settings
2+
include ../common.mk
3+
4+
# per-example flags
5+
CXXFLAGS += -pthread
6+
7+
TARGET := thread_safe_queue
8+
SRCS := main.cpp
9+
OBJS := $(SRCS:.cpp=.o)
10+
11+
all: $(TARGET)
12+
13+
$(TARGET): $(OBJS)
14+
$(CXX) $(CXXFLAGS) -o $@ $^
15+
16+
%.o: %.cpp
17+
$(CXX) $(CXXFLAGS) -c $< -o $@
18+
19+
run: $(TARGET)
20+
./$(TARGET)
21+
22+
clean:
23+
rm -f $(OBJS) $(TARGET)
24+
25+
.PHONY: all clean run

0 commit comments

Comments
 (0)