agentic-team-templates 0.13.2 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/package.json +1 -1
- package/src/index.js +91 -13
- package/src/index.test.js +95 -1
- package/templates/cpp-expert/.cursorrules/concurrency.md +211 -0
- package/templates/cpp-expert/.cursorrules/error-handling.md +170 -0
- package/templates/cpp-expert/.cursorrules/memory-and-ownership.md +220 -0
- package/templates/cpp-expert/.cursorrules/modern-cpp.md +211 -0
- package/templates/cpp-expert/.cursorrules/overview.md +87 -0
- package/templates/cpp-expert/.cursorrules/performance.md +223 -0
- package/templates/cpp-expert/.cursorrules/testing.md +230 -0
- package/templates/cpp-expert/.cursorrules/tooling.md +312 -0
- package/templates/cpp-expert/CLAUDE.md +242 -0
- package/templates/csharp-expert/.cursorrules/aspnet-core.md +311 -0
- package/templates/csharp-expert/.cursorrules/async-patterns.md +206 -0
- package/templates/csharp-expert/.cursorrules/dependency-injection.md +206 -0
- package/templates/csharp-expert/.cursorrules/error-handling.md +235 -0
- package/templates/csharp-expert/.cursorrules/language-features.md +204 -0
- package/templates/csharp-expert/.cursorrules/overview.md +92 -0
- package/templates/csharp-expert/.cursorrules/performance.md +251 -0
- package/templates/csharp-expert/.cursorrules/testing.md +282 -0
- package/templates/csharp-expert/.cursorrules/tooling.md +254 -0
- package/templates/csharp-expert/CLAUDE.md +360 -0
- package/templates/java-expert/.cursorrules/concurrency.md +209 -0
- package/templates/java-expert/.cursorrules/error-handling.md +205 -0
- package/templates/java-expert/.cursorrules/modern-java.md +216 -0
- package/templates/java-expert/.cursorrules/overview.md +81 -0
- package/templates/java-expert/.cursorrules/performance.md +239 -0
- package/templates/java-expert/.cursorrules/persistence.md +262 -0
- package/templates/java-expert/.cursorrules/spring-boot.md +262 -0
- package/templates/java-expert/.cursorrules/testing.md +272 -0
- package/templates/java-expert/.cursorrules/tooling.md +301 -0
- package/templates/java-expert/CLAUDE.md +325 -0
- package/templates/javascript-expert/.cursorrules/overview.md +5 -3
- package/templates/javascript-expert/.cursorrules/typescript-deep-dive.md +348 -0
- package/templates/javascript-expert/CLAUDE.md +34 -3
- package/templates/kotlin-expert/.cursorrules/coroutines.md +237 -0
- package/templates/kotlin-expert/.cursorrules/error-handling.md +149 -0
- package/templates/kotlin-expert/.cursorrules/frameworks.md +227 -0
- package/templates/kotlin-expert/.cursorrules/language-features.md +231 -0
- package/templates/kotlin-expert/.cursorrules/overview.md +77 -0
- package/templates/kotlin-expert/.cursorrules/performance.md +185 -0
- package/templates/kotlin-expert/.cursorrules/testing.md +213 -0
- package/templates/kotlin-expert/.cursorrules/tooling.md +258 -0
- package/templates/kotlin-expert/CLAUDE.md +276 -0
- package/templates/swift-expert/.cursorrules/concurrency.md +230 -0
- package/templates/swift-expert/.cursorrules/error-handling.md +213 -0
- package/templates/swift-expert/.cursorrules/language-features.md +246 -0
- package/templates/swift-expert/.cursorrules/overview.md +88 -0
- package/templates/swift-expert/.cursorrules/performance.md +260 -0
- package/templates/swift-expert/.cursorrules/swiftui.md +260 -0
- package/templates/swift-expert/.cursorrules/testing.md +286 -0
- package/templates/swift-expert/.cursorrules/tooling.md +285 -0
- package/templates/swift-expert/CLAUDE.md +275 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
# C++ Tooling and Build System
|
|
2
|
+
|
|
3
|
+
CMake is the standard. Sanitizers are mandatory. Static analysis catches bugs before they ship.
|
|
4
|
+
|
|
5
|
+
## CMake
|
|
6
|
+
|
|
7
|
+
### Modern CMake (Target-Based)
|
|
8
|
+
|
|
9
|
+
```cmake
|
|
10
|
+
cmake_minimum_required(VERSION 3.25)
|
|
11
|
+
project(myapp VERSION 1.0.0 LANGUAGES CXX)
|
|
12
|
+
|
|
13
|
+
set(CMAKE_CXX_STANDARD 20)
|
|
14
|
+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
15
|
+
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
16
|
+
|
|
17
|
+
# Main library
|
|
18
|
+
add_library(mylib
|
|
19
|
+
src/types.cpp
|
|
20
|
+
src/utils.cpp
|
|
21
|
+
)
|
|
22
|
+
target_include_directories(mylib PUBLIC
|
|
23
|
+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
24
|
+
$<INSTALL_INTERFACE:include>
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
# Executable
|
|
28
|
+
add_executable(myapp src/main.cpp)
|
|
29
|
+
target_link_libraries(myapp PRIVATE mylib)
|
|
30
|
+
|
|
31
|
+
# Tests
|
|
32
|
+
option(BUILD_TESTING "Build tests" ON)
|
|
33
|
+
if(BUILD_TESTING)
|
|
34
|
+
enable_testing()
|
|
35
|
+
add_subdirectory(tests)
|
|
36
|
+
endif()
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### CMake Presets
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"version": 6,
|
|
44
|
+
"configurePresets": [
|
|
45
|
+
{
|
|
46
|
+
"name": "dev",
|
|
47
|
+
"generator": "Ninja",
|
|
48
|
+
"binaryDir": "${sourceDir}/build/dev",
|
|
49
|
+
"cacheVariables": {
|
|
50
|
+
"CMAKE_BUILD_TYPE": "Debug",
|
|
51
|
+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
|
|
52
|
+
"ENABLE_SANITIZERS": "ON"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"name": "release",
|
|
57
|
+
"generator": "Ninja",
|
|
58
|
+
"binaryDir": "${sourceDir}/build/release",
|
|
59
|
+
"cacheVariables": {
|
|
60
|
+
"CMAKE_BUILD_TYPE": "Release",
|
|
61
|
+
"CMAKE_INTERPROCEDURAL_OPTIMIZATION": "ON"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
"buildPresets": [
|
|
66
|
+
{ "name": "dev", "configurePreset": "dev" },
|
|
67
|
+
{ "name": "release", "configurePreset": "release" }
|
|
68
|
+
],
|
|
69
|
+
"testPresets": [
|
|
70
|
+
{ "name": "dev", "configurePreset": "dev", "output": { "outputOnFailure": true } }
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Essential Commands
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# Configure and build
|
|
79
|
+
cmake --preset dev
|
|
80
|
+
cmake --build --preset dev
|
|
81
|
+
|
|
82
|
+
# Run tests
|
|
83
|
+
ctest --preset dev
|
|
84
|
+
|
|
85
|
+
# Clean build
|
|
86
|
+
cmake --build --preset dev --target clean
|
|
87
|
+
|
|
88
|
+
# Install
|
|
89
|
+
cmake --install build/release --prefix /usr/local
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Package Management
|
|
93
|
+
|
|
94
|
+
### vcpkg
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"dependencies": [
|
|
99
|
+
"fmt",
|
|
100
|
+
"spdlog",
|
|
101
|
+
"catch2",
|
|
102
|
+
"benchmark",
|
|
103
|
+
"nlohmann-json"
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
```cmake
|
|
109
|
+
# CMakeLists.txt
|
|
110
|
+
find_package(fmt CONFIG REQUIRED)
|
|
111
|
+
find_package(spdlog CONFIG REQUIRED)
|
|
112
|
+
target_link_libraries(myapp PRIVATE fmt::fmt spdlog::spdlog)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Conan
|
|
116
|
+
|
|
117
|
+
```ini
|
|
118
|
+
# conanfile.txt
|
|
119
|
+
[requires]
|
|
120
|
+
fmt/10.2.1
|
|
121
|
+
spdlog/1.13.0
|
|
122
|
+
catch2/3.5.2
|
|
123
|
+
|
|
124
|
+
[generators]
|
|
125
|
+
CMakeDeps
|
|
126
|
+
CMakeToolchain
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## .clang-format
|
|
130
|
+
|
|
131
|
+
```yaml
|
|
132
|
+
BasedOnStyle: Google
|
|
133
|
+
IndentWidth: 4
|
|
134
|
+
ColumnLimit: 100
|
|
135
|
+
PointerAlignment: Left
|
|
136
|
+
AllowShortFunctionsOnASingleLine: Inline
|
|
137
|
+
AllowShortIfStatementsOnASingleLine: Never
|
|
138
|
+
AllowShortLoopsOnASingleLine: false
|
|
139
|
+
BreakBeforeBraces: Attach
|
|
140
|
+
IncludeBlocks: Regroup
|
|
141
|
+
SortIncludes: CaseSensitive
|
|
142
|
+
SpaceAfterCStyleCast: false
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
# Format all files
|
|
147
|
+
find src include tests -name '*.cpp' -o -name '*.hpp' | xargs clang-format -i
|
|
148
|
+
|
|
149
|
+
# CI check
|
|
150
|
+
find src include tests -name '*.cpp' -o -name '*.hpp' | xargs clang-format --dry-run --Werror
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## .clang-tidy
|
|
154
|
+
|
|
155
|
+
```yaml
|
|
156
|
+
Checks: >
|
|
157
|
+
-*,
|
|
158
|
+
bugprone-*,
|
|
159
|
+
clang-analyzer-*,
|
|
160
|
+
cppcoreguidelines-*,
|
|
161
|
+
misc-*,
|
|
162
|
+
modernize-*,
|
|
163
|
+
performance-*,
|
|
164
|
+
readability-*,
|
|
165
|
+
-modernize-use-trailing-return-type,
|
|
166
|
+
-readability-identifier-length
|
|
167
|
+
|
|
168
|
+
WarningsAsErrors: '*'
|
|
169
|
+
|
|
170
|
+
CheckOptions:
|
|
171
|
+
- key: readability-identifier-naming.ClassCase
|
|
172
|
+
value: CamelCase
|
|
173
|
+
- key: readability-identifier-naming.FunctionCase
|
|
174
|
+
value: lower_case
|
|
175
|
+
- key: readability-identifier-naming.VariableCase
|
|
176
|
+
value: lower_case
|
|
177
|
+
- key: readability-identifier-naming.PrivateMemberSuffix
|
|
178
|
+
value: '_'
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
# Run clang-tidy
|
|
183
|
+
clang-tidy -p build/dev src/*.cpp -- -std=c++20
|
|
184
|
+
|
|
185
|
+
# With CMake integration
|
|
186
|
+
set(CMAKE_CXX_CLANG_TIDY "clang-tidy")
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Docker
|
|
190
|
+
|
|
191
|
+
```dockerfile
|
|
192
|
+
FROM ubuntu:24.04 AS build
|
|
193
|
+
RUN apt-get update && apt-get install -y \
|
|
194
|
+
cmake ninja-build g++-14 \
|
|
195
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
196
|
+
|
|
197
|
+
WORKDIR /app
|
|
198
|
+
COPY CMakeLists.txt CMakePresets.json vcpkg.json ./
|
|
199
|
+
COPY include/ include/
|
|
200
|
+
COPY src/ src/
|
|
201
|
+
|
|
202
|
+
RUN cmake --preset release && cmake --build --preset release
|
|
203
|
+
|
|
204
|
+
FROM ubuntu:24.04 AS runtime
|
|
205
|
+
RUN useradd -m appuser
|
|
206
|
+
USER appuser
|
|
207
|
+
COPY --from=build /app/build/release/myapp /usr/local/bin/
|
|
208
|
+
ENTRYPOINT ["myapp"]
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## CI/CD (GitHub Actions)
|
|
212
|
+
|
|
213
|
+
```yaml
|
|
214
|
+
name: CI
|
|
215
|
+
|
|
216
|
+
on:
|
|
217
|
+
push:
|
|
218
|
+
branches: [main]
|
|
219
|
+
pull_request:
|
|
220
|
+
branches: [main]
|
|
221
|
+
|
|
222
|
+
jobs:
|
|
223
|
+
build-and-test:
|
|
224
|
+
strategy:
|
|
225
|
+
matrix:
|
|
226
|
+
os: [ubuntu-latest]
|
|
227
|
+
compiler: [gcc-14, clang-18]
|
|
228
|
+
|
|
229
|
+
runs-on: ${{ matrix.os }}
|
|
230
|
+
|
|
231
|
+
steps:
|
|
232
|
+
- uses: actions/checkout@v4
|
|
233
|
+
|
|
234
|
+
- name: Install dependencies
|
|
235
|
+
run: |
|
|
236
|
+
sudo apt-get update
|
|
237
|
+
sudo apt-get install -y ninja-build ${{ matrix.compiler }}
|
|
238
|
+
|
|
239
|
+
- name: Configure
|
|
240
|
+
run: cmake --preset dev
|
|
241
|
+
env:
|
|
242
|
+
CXX: ${{ matrix.compiler == 'gcc-14' && 'g++-14' || 'clang++-18' }}
|
|
243
|
+
|
|
244
|
+
- name: Build
|
|
245
|
+
run: cmake --build --preset dev
|
|
246
|
+
|
|
247
|
+
- name: Test
|
|
248
|
+
run: ctest --preset dev
|
|
249
|
+
|
|
250
|
+
- name: clang-format check
|
|
251
|
+
run: |
|
|
252
|
+
find src include tests -name '*.cpp' -o -name '*.hpp' | \
|
|
253
|
+
xargs clang-format --dry-run --Werror
|
|
254
|
+
|
|
255
|
+
- name: clang-tidy
|
|
256
|
+
run: |
|
|
257
|
+
clang-tidy -p build/dev src/*.cpp -- -std=c++20
|
|
258
|
+
|
|
259
|
+
sanitizers:
|
|
260
|
+
runs-on: ubuntu-latest
|
|
261
|
+
strategy:
|
|
262
|
+
matrix:
|
|
263
|
+
sanitizer: [address, thread]
|
|
264
|
+
|
|
265
|
+
steps:
|
|
266
|
+
- uses: actions/checkout@v4
|
|
267
|
+
- name: Build with sanitizer
|
|
268
|
+
run: |
|
|
269
|
+
cmake -B build -DCMAKE_BUILD_TYPE=Debug \
|
|
270
|
+
-DCMAKE_CXX_FLAGS="-fsanitize=${{ matrix.sanitizer }} -fno-omit-frame-pointer"
|
|
271
|
+
cmake --build build
|
|
272
|
+
- name: Test with sanitizer
|
|
273
|
+
run: ctest --test-dir build --output-on-failure
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## Logging (spdlog)
|
|
277
|
+
|
|
278
|
+
```cpp
|
|
279
|
+
#include <spdlog/spdlog.h>
|
|
280
|
+
#include <spdlog/sinks/stdout_color_sinks.h>
|
|
281
|
+
#include <spdlog/sinks/rotating_file_sink.h>
|
|
282
|
+
|
|
283
|
+
auto logger = spdlog::stdout_color_mt("app");
|
|
284
|
+
logger->set_level(spdlog::level::info);
|
|
285
|
+
|
|
286
|
+
logger->info("Server starting on port {}", port);
|
|
287
|
+
logger->warn("Connection pool at {}% capacity", utilization);
|
|
288
|
+
logger->error("Failed to process order {}: {}", order_id, ec.message());
|
|
289
|
+
|
|
290
|
+
// Structured logging with fmt
|
|
291
|
+
spdlog::info("request method={} path={} status={} duration_ms={}",
|
|
292
|
+
method, path, status, duration.count());
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
## Anti-Patterns
|
|
296
|
+
|
|
297
|
+
```cpp
|
|
298
|
+
// Never: hand-written Makefiles for complex projects
|
|
299
|
+
// Use CMake with presets
|
|
300
|
+
|
|
301
|
+
// Never: header-only for everything (compile time explosion)
|
|
302
|
+
// Use compilation units, forward declarations, and pimpl
|
|
303
|
+
|
|
304
|
+
// Never: skipping sanitizers in CI
|
|
305
|
+
// ASan + UBSan + TSan catch real bugs that tests miss
|
|
306
|
+
|
|
307
|
+
// Never: -Wno-* to suppress warnings without fixing
|
|
308
|
+
// Fix the code, don't silence the compiler
|
|
309
|
+
|
|
310
|
+
// Never: system-installed dependencies without version pinning
|
|
311
|
+
// Use vcpkg, Conan, or FetchContent with pinned versions
|
|
312
|
+
```
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# C++ Expert Development Guide
|
|
2
|
+
|
|
3
|
+
Principal-level guidelines for C++ engineering. Deep language mastery, zero-cost abstractions, and systems-level thinking.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
This guide applies to:
|
|
10
|
+
- Systems programming (OS, drivers, embedded)
|
|
11
|
+
- High-performance computing and real-time systems
|
|
12
|
+
- Game engines and graphics programming
|
|
13
|
+
- Networking and server infrastructure
|
|
14
|
+
- Libraries and frameworks
|
|
15
|
+
- Scientific computing and simulation
|
|
16
|
+
|
|
17
|
+
### Core Philosophy
|
|
18
|
+
|
|
19
|
+
C++ gives you control. That control comes with responsibility. Write code that is correct, clear, and fast — in that order.
|
|
20
|
+
|
|
21
|
+
- **Resource management is automatic.** RAII is not optional — every resource has an owner, every owner has a destructor.
|
|
22
|
+
- **Zero-cost abstractions are the goal.** If an abstraction adds runtime overhead you don't need, you're using the wrong abstraction.
|
|
23
|
+
- **The type system is your strongest tool.** Use it to make invalid states unrepresentable at compile time.
|
|
24
|
+
- **Undefined behavior is a bug, period.** No shortcuts. No "it works on my machine."
|
|
25
|
+
- **Modern C++ is the baseline.** C++17 minimum, C++20/23 features where they improve clarity.
|
|
26
|
+
- **If you don't know, say so.** Admitting uncertainty about compiler behavior, ABI details, or standard wording is professional.
|
|
27
|
+
|
|
28
|
+
### Key Principles
|
|
29
|
+
|
|
30
|
+
1. **RAII Everywhere** — Every resource acquisition is an initialization, every release is a destruction
|
|
31
|
+
2. **Value Semantics by Default** — Copy, move, compare. References and pointers are the exception
|
|
32
|
+
3. **const Correctness** — If it doesn't mutate, it's `const`. No exceptions
|
|
33
|
+
4. **Prefer the Standard Library** — `std::vector`, `std::string`, `std::optional`, `std::variant`
|
|
34
|
+
5. **Compile-Time Over Runtime** — `constexpr`, `static_assert`, `concepts`
|
|
35
|
+
|
|
36
|
+
### Project Structure
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
project/
|
|
40
|
+
├── include/mylib/ # Public headers
|
|
41
|
+
├── src/ # Implementation files
|
|
42
|
+
├── tests/ # Test files
|
|
43
|
+
├── benchmarks/ # Performance benchmarks
|
|
44
|
+
├── cmake/ # CMake modules
|
|
45
|
+
├── CMakeLists.txt
|
|
46
|
+
├── CMakePresets.json
|
|
47
|
+
├── .clang-format
|
|
48
|
+
├── .clang-tidy
|
|
49
|
+
└── vcpkg.json or conanfile.txt
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Modern C++
|
|
55
|
+
|
|
56
|
+
### std::optional, std::variant, std::expected
|
|
57
|
+
|
|
58
|
+
```cpp
|
|
59
|
+
std::optional<User> find_user(std::string_view email);
|
|
60
|
+
|
|
61
|
+
using JsonValue = std::variant<std::nullptr_t, bool, double, std::string>;
|
|
62
|
+
|
|
63
|
+
auto parse_port(std::string_view input) -> std::expected<uint16_t, ParseError>;
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Concepts (C++20)
|
|
67
|
+
|
|
68
|
+
```cpp
|
|
69
|
+
template <typename T>
|
|
70
|
+
concept Numeric = std::integral<T> || std::floating_point<T>;
|
|
71
|
+
|
|
72
|
+
template <Numeric T>
|
|
73
|
+
auto clamp(T value, T low, T high) -> T;
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Ranges (C++20)
|
|
77
|
+
|
|
78
|
+
```cpp
|
|
79
|
+
auto result = users
|
|
80
|
+
| std::views::filter(&User::is_active)
|
|
81
|
+
| std::views::transform(&User::email)
|
|
82
|
+
| std::ranges::to<std::vector>();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Memory and Ownership
|
|
88
|
+
|
|
89
|
+
### Smart Pointers
|
|
90
|
+
|
|
91
|
+
- `std::unique_ptr` — Single ownership (default choice, zero overhead)
|
|
92
|
+
- `std::shared_ptr` — Shared ownership (rare, atomic ref count overhead)
|
|
93
|
+
- Raw pointer — Non-owning reference only
|
|
94
|
+
|
|
95
|
+
### Rules
|
|
96
|
+
|
|
97
|
+
- No raw `new`/`delete` in application code
|
|
98
|
+
- RAII for every resource (files, sockets, mutexes, memory)
|
|
99
|
+
- Rule of Zero: prefer classes that need no custom special members
|
|
100
|
+
- Rule of Five: if you need one custom special member, define all five
|
|
101
|
+
- Move semantics for efficient transfers
|
|
102
|
+
|
|
103
|
+
```cpp
|
|
104
|
+
auto widget = std::make_unique<Widget>(42);
|
|
105
|
+
auto shared = std::make_shared<Resource>();
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Concurrency
|
|
111
|
+
|
|
112
|
+
### Core Rules
|
|
113
|
+
|
|
114
|
+
- Immutable data is thread-safe — share via `const` references
|
|
115
|
+
- Every mutable shared state needs synchronization
|
|
116
|
+
- `std::jthread` (C++20) — automatically joins on destruction
|
|
117
|
+
- `std::scoped_lock` — deadlock-free multi-mutex locking
|
|
118
|
+
- `std::atomic` for single variables, `std::mutex` for compound operations
|
|
119
|
+
|
|
120
|
+
```cpp
|
|
121
|
+
auto worker = std::jthread([](std::stop_token stop) {
|
|
122
|
+
while (!stop.stop_requested()) { /* work */ }
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Parallel Algorithms
|
|
127
|
+
|
|
128
|
+
```cpp
|
|
129
|
+
std::sort(std::execution::par, data.begin(), data.end());
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Error Handling
|
|
135
|
+
|
|
136
|
+
### Exception Safety Guarantees
|
|
137
|
+
|
|
138
|
+
1. **No-throw** — Function never throws. Mark `noexcept`.
|
|
139
|
+
2. **Strong** — If exception thrown, state rolls back.
|
|
140
|
+
3. **Basic** — Invariants preserved, no leaks.
|
|
141
|
+
|
|
142
|
+
### std::expected (C++23)
|
|
143
|
+
|
|
144
|
+
```cpp
|
|
145
|
+
auto result = validate(input)
|
|
146
|
+
.and_then([&](auto v) { return save(db, v); })
|
|
147
|
+
.transform([](auto s) { return Response::from(s); });
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Rules
|
|
151
|
+
|
|
152
|
+
- Throw by value, catch by const reference
|
|
153
|
+
- `noexcept` on destructors, move operations, swap
|
|
154
|
+
- `static_assert` for compile-time invariants
|
|
155
|
+
- Never throw in destructors
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Testing
|
|
160
|
+
|
|
161
|
+
### Framework Stack
|
|
162
|
+
|
|
163
|
+
| Tool | Purpose |
|
|
164
|
+
|------|---------|
|
|
165
|
+
| Google Test / Catch2 | Test framework |
|
|
166
|
+
| Google Mock | Mocking |
|
|
167
|
+
| Google Benchmark | Micro-benchmarks |
|
|
168
|
+
| ASan | Address sanitizer |
|
|
169
|
+
| UBSan | Undefined behavior sanitizer |
|
|
170
|
+
| TSan | Thread sanitizer |
|
|
171
|
+
| Valgrind | Memory leak detection |
|
|
172
|
+
|
|
173
|
+
### Sanitizers Are Mandatory
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
cmake -B build -DENABLE_SANITIZERS=ON
|
|
177
|
+
cmake --build build && ctest --test-dir build
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Every sanitizer finding is a real bug. No exceptions.
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Performance
|
|
185
|
+
|
|
186
|
+
### Profile First
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
perf record -g ./myapp && perf report
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Key Patterns
|
|
193
|
+
|
|
194
|
+
- Cache-friendly data structures (SoA vs AoS for hot loops)
|
|
195
|
+
- Pre-allocate containers with `reserve()`
|
|
196
|
+
- Move semantics to avoid copies
|
|
197
|
+
- `constexpr` computation at compile time
|
|
198
|
+
- Help auto-vectorization with simple loops and `__restrict`
|
|
199
|
+
- `std::string_view` for zero-copy string operations
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## Tooling
|
|
204
|
+
|
|
205
|
+
### Essential Stack
|
|
206
|
+
|
|
207
|
+
| Tool | Purpose |
|
|
208
|
+
|------|---------|
|
|
209
|
+
| CMake + Ninja | Build system |
|
|
210
|
+
| vcpkg / Conan | Package management |
|
|
211
|
+
| clang-format | Code formatting |
|
|
212
|
+
| clang-tidy | Static analysis |
|
|
213
|
+
| Sanitizers | Runtime bug detection |
|
|
214
|
+
| perf / Valgrind | Profiling |
|
|
215
|
+
| spdlog | Structured logging |
|
|
216
|
+
|
|
217
|
+
### CI Essentials
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
cmake --preset dev && cmake --build --preset dev
|
|
221
|
+
ctest --preset dev
|
|
222
|
+
clang-format --dry-run --Werror src/*.cpp
|
|
223
|
+
clang-tidy -p build/dev src/*.cpp
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Definition of Done
|
|
229
|
+
|
|
230
|
+
A C++ feature is complete when:
|
|
231
|
+
|
|
232
|
+
- [ ] Compiles with zero warnings under `-Wall -Wextra -Wpedantic -Werror`
|
|
233
|
+
- [ ] All tests pass (unit, integration)
|
|
234
|
+
- [ ] Sanitizers pass (ASan, UBSan, TSan)
|
|
235
|
+
- [ ] `clang-tidy` reports zero findings
|
|
236
|
+
- [ ] No undefined behavior
|
|
237
|
+
- [ ] No memory leaks
|
|
238
|
+
- [ ] `const` correctness enforced
|
|
239
|
+
- [ ] RAII used for all resource management
|
|
240
|
+
- [ ] No raw `new`/`delete` in application code
|
|
241
|
+
- [ ] Exception safety guarantees documented
|
|
242
|
+
- [ ] Code reviewed and approved
|