@nockdev/awf 6.2.5 → 6.2.7
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/.agent/config.yaml +2 -2
- package/.agent/core/AGENT_BEHAVIOR.md +1 -1
- package/.agent/core/AUDIT_POLICY.md +1 -1
- package/.agent/core/CACHE.md +1 -1
- package/.agent/core/DATA_SAFETY.md +1 -1
- package/.agent/core/MEMORY_PATHS.yaml +2 -2
- package/.agent/core/PERMISSIONS.md +1 -1
- package/.agent/core/README.md +1 -1
- package/.agent/core/VERSION.yaml +4 -4
- package/.agent/core/archive/ACTIVE_MEMORY.yaml +2 -2
- package/.agent/core/archive/CHECKPOINT.yaml +2 -2
- package/.agent/core/archive/CLEANUP_ENGINE.yaml +2 -2
- package/.agent/core/archive/CONTEXT_INJECTOR.yaml +2 -2
- package/.agent/core/archive/CONTEXT_LOADER.yaml +1 -1
- package/.agent/core/archive/CONTEXT_OPTIMIZATION.yaml +1 -1
- package/.agent/core/archive/CONTEXT_PRIORITY.yaml +2 -2
- package/.agent/core/archive/FLOW_ENGINE.yaml +1 -1
- package/.agent/core/archive/GRAPH_MEMORY.yaml +1 -1
- package/.agent/core/archive/HYBRID_ROUTER.yaml +1 -1
- package/.agent/core/archive/INTENT_DETECTION.yaml +1 -1
- package/.agent/core/archive/MEMORY_CONSOLIDATION.yaml +3 -3
- package/.agent/core/archive/MEMORY_ENGINE.yaml +2 -2
- package/.agent/core/archive/MEMORY_UTILS.yaml +1 -1
- package/.agent/core/archive/REFLECTION_ENGINE.yaml +1 -1
- package/.agent/core/archive/ROUTER.yaml +4 -4
- package/.agent/core/archive/SCORING_FORMULA.yaml +2 -2
- package/.agent/core/archive/SEMANTIC_ENGINE.yaml +1 -1
- package/.agent/core/archive/SKILLS_FLOW.yaml +1 -1
- package/.agent/core/archive/STATE_MACHINE.yaml +1 -1
- package/.agent/core/archive/SUMMARIZATION_ENGINE.yaml +2 -2
- package/.agent/core/archive/TOKEN_BUDGETS.yaml +2 -2
- package/.agent/core/archive/TOKEN_LOADING.yaml +2 -2
- package/.agent/core/archive/TOKEN_SUMMARY.yaml +2 -2
- package/.agent/core/reference/CODING_STYLES.yaml +1 -1
- package/.agent/core/reference/LIBRARY_REGISTRY.yaml +1 -1
- package/.agent/core/reference/MCP_TOOLS.yaml +2 -2
- package/.agent/core/reference/PATTERNS.yaml +1 -1
- package/.agent/core/reference/SKILL_SCHEMA.yaml +1 -1
- package/.agent/i18n/en.yaml +6 -6
- package/.agent/i18n/vi.yaml +6 -6
- package/.agent/ide/README.md +1 -1
- package/.agent/ide/amazonq.json +1 -1
- package/.agent/ide/amp.json +1 -1
- package/.agent/ide/antigravity.json +1 -1
- package/.agent/ide/augment.json +1 -1
- package/.agent/ide/claude.json +1 -1
- package/.agent/ide/cline.json +1 -1
- package/.agent/ide/cody.json +1 -1
- package/.agent/ide/continue.json +1 -1
- package/.agent/ide/cursor.json +1 -1
- package/.agent/ide/gemini.json +1 -1
- package/.agent/ide/jetbrains.json +1 -1
- package/.agent/ide/kiro.json +1 -1
- package/.agent/ide/opencode.json +1 -1
- package/.agent/ide/roo.json +1 -1
- package/.agent/ide/tabnine.json +1 -1
- package/.agent/ide/trae.json +1 -1
- package/.agent/ide/vscode.json +1 -1
- package/.agent/ide/windsurf.json +1 -1
- package/.agent/ide/zed.json +1 -1
- package/.agent/manifest.yaml +1 -1
- package/.agent/personas/README.md +1 -1
- package/.agent/personas/architect.md +1 -1
- package/.agent/personas/auditor.md +1 -1
- package/.agent/personas/debugger.md +1 -1
- package/.agent/personas/developer.md +1 -1
- package/.agent/personas/devops.md +1 -1
- package/.agent/personas/documenter.md +1 -1
- package/.agent/personas/orchestrator.md +1 -1
- package/.agent/personas/persona.schema.yaml +1 -1
- package/.agent/personas/planner.md +1 -1
- package/.agent/personas/researcher.md +1 -1
- package/.agent/personas/security.md +1 -1
- package/.agent/personas/tester.md +1 -1
- package/.agent/rules/README.md +1 -1
- package/.agent/rules/archive/constitutional/tier-0-core.yaml +5 -5
- package/.agent/rules/archive/constitutional/tier-1-safety.yaml +5 -5
- package/.agent/rules/archive/constitutional/tier-2-execution.yaml +6 -6
- package/.agent/rules/archive/context-management.yaml +1 -1
- package/.agent/rules/archive/duplication-prevention.md +1 -1
- package/.agent/rules/archive/evidence.yaml +1 -1
- package/.agent/rules/archive/project-detection.md +1 -1
- package/.agent/rules/archive/reflection.yaml +1 -1
- package/.agent/rules/archive/versioning.yaml +5 -5
- package/.agent/rules/data/build-systems.yaml +57 -2
- package/.agent/rules/modules/agent-delegation.yaml +2 -2
- package/.agent/rules/modules/edit-verification.yaml +1 -1
- package/.agent/rules/modules/git-workflow.yaml +1 -1
- package/.agent/rules/modules/language.yaml +1 -1
- package/.agent/rules/modules/online-research.yaml +1 -1
- package/.agent/rules/modules/performance-optimization.yaml +2 -2
- package/.agent/rules/modules/quality.yaml +1 -1
- package/.agent/rules/modules/stop-conditions.yaml +1 -1
- package/.agent/rules/modules/terminal-safety.yaml +1 -1
- package/.agent/rules/modules/yagni.yaml +1 -1
- package/.agent/rules/validation-framework.md +1 -1
- package/.agent/skills/README.md +1 -1
- package/.agent/skills/_categories.yaml +2 -2
- package/.agent/skills/ai-ml/rag-patterns/META.yaml +2 -0
- package/.agent/skills/core/api-design/META.yaml +1 -1
- package/.agent/skills/core/authentication/META.yaml +1 -1
- package/.agent/skills/core/error-handling/META.yaml +1 -1
- package/.agent/skills/core/logging/META.yaml +1 -1
- package/.agent/skills/core/observability/META.yaml +1 -1
- package/.agent/skills/core/security/META.yaml +1 -1
- package/.agent/skills/core/security/SKILL.md +1 -1
- package/.agent/skills/cross-cutting/accessibility/META.yaml +1 -1
- package/.agent/skills/cross-cutting/audit-pro/META.yaml +9 -1
- package/.agent/skills/cross-cutting/audit-pro/SKILL.md +61 -5
- package/.agent/skills/cross-cutting/bun/META.yaml +17 -8
- package/.agent/skills/cross-cutting/bun/SKILL.md +1 -1
- package/.agent/skills/cross-cutting/coding-rules/META.yaml +1 -1
- package/.agent/skills/cross-cutting/database/META.yaml +42 -1
- package/.agent/skills/cross-cutting/database/SKILL.md +44 -628
- package/.agent/skills/cross-cutting/database/references/nosql-patterns.md +194 -0
- package/.agent/skills/cross-cutting/database/references/orms-patterns.md +278 -0
- package/.agent/skills/cross-cutting/database/references/postgresql.md +144 -0
- package/.agent/skills/cross-cutting/deno/META.yaml +19 -10
- package/.agent/skills/cross-cutting/deno/SKILL.md +1 -1
- package/.agent/skills/cross-cutting/domyh-design/META.yaml +1 -1
- package/.agent/skills/cross-cutting/domyh-design/data/desktop-colors.yaml +1 -1
- package/.agent/skills/cross-cutting/electron/SKILL.md +15 -616
- package/.agent/skills/cross-cutting/electron/references/ipc-testing.md +114 -0
- package/.agent/skills/cross-cutting/electron/references/native-integrations.md +216 -0
- package/.agent/skills/cross-cutting/electron/references/performance-accessibility.md +118 -0
- package/.agent/skills/cross-cutting/electron/references/updates-persistence.md +165 -0
- package/.agent/skills/cross-cutting/seo/META.yaml +1 -1
- package/.agent/skills/cross-cutting/skill-creator/META.yaml +37 -0
- package/.agent/skills/cross-cutting/skill-creator/SKILL.md +163 -0
- package/.agent/skills/cross-cutting/skill-creator/references/patterns.md +58 -0
- package/.agent/skills/cross-cutting/skill-creator/references/schema-v2.md +44 -0
- package/.agent/skills/cross-cutting/sql/META.yaml +1 -1
- package/.agent/skills/cross-cutting/sql/SKILL.md +1 -1
- package/.agent/skills/cross-cutting/tailwind/META.yaml +1 -1
- package/.agent/skills/cross-cutting/tailwind/SKILL.md +1 -1
- package/.agent/skills/cross-cutting/tdd-workflow/META.yaml +1 -1
- package/.agent/skills/cross-cutting/testing/META.yaml +7 -1
- package/.agent/skills/cross-cutting/testing/SKILL.md +1 -1
- package/.agent/skills/cross-cutting/testing/data/frameworks.yaml +1 -1
- package/.agent/skills/cross-cutting/web-perf/META.yaml +1 -1
- package/.agent/skills/cross-cutting/web-perf/SKILL.md +1 -1
- package/.agent/skills/devops/aws/META.yaml +1 -1
- package/.agent/skills/devops/aws/SKILL.md +101 -16
- package/.agent/skills/devops/azure/SKILL.md +96 -30
- package/.agent/skills/devops/ci-cd/META.yaml +1 -1
- package/.agent/skills/devops/ci-cd/SKILL.md +114 -8
- package/.agent/skills/devops/docker/META.yaml +1 -1
- package/.agent/skills/devops/docker/SKILL.md +96 -8
- package/.agent/skills/devops/gcp/SKILL.md +106 -30
- package/.agent/skills/devops/kubernetes/META.yaml +1 -1
- package/.agent/skills/devops/kubernetes/SKILL.md +125 -8
- package/.agent/skills/frameworks/angular/META.yaml +1 -1
- package/.agent/skills/frameworks/angular/SKILL.md +1 -1
- package/.agent/skills/frameworks/flutter/META.yaml +1 -1
- package/.agent/skills/frameworks/flutter/SKILL.md +1 -1
- package/.agent/skills/frameworks/nextjs/META.yaml +1 -1
- package/.agent/skills/frameworks/nextjs/SKILL.md +1 -1
- package/.agent/skills/frameworks/nuxt/META.yaml +1 -1
- package/.agent/skills/frameworks/nuxt/SKILL.md +1 -1
- package/.agent/skills/frameworks/react/META.yaml +1 -1
- package/.agent/skills/frameworks/react/SKILL.md +24 -1
- package/.agent/skills/frameworks/react-native/META.yaml +1 -1
- package/.agent/skills/frameworks/react-native/SKILL.md +1 -1
- package/.agent/skills/frameworks/svelte/META.yaml +1 -1
- package/.agent/skills/frameworks/svelte/SKILL.md +1 -1
- package/.agent/skills/frameworks/vue/META.yaml +1 -1
- package/.agent/skills/frameworks/vue/SKILL.md +1 -1
- package/.agent/skills/index.json +2 -2
- package/.agent/skills/languages/asm/META.yaml +1 -1
- package/.agent/skills/languages/asm/SKILL.md +27 -436
- package/.agent/skills/languages/asm/references/advanced-architectures.md +191 -0
- package/.agent/skills/languages/asm/references/build-structure.md +150 -0
- package/.agent/skills/languages/asm/references/simd-programming.md +92 -0
- package/.agent/skills/languages/c/META.yaml +1 -1
- package/.agent/skills/languages/c/SKILL.md +14 -356
- package/.agent/skills/languages/c/references/data-structures.md +63 -0
- package/.agent/skills/languages/c/references/memory-management.md +74 -0
- package/.agent/skills/languages/c/references/platform-headers.md +230 -0
- package/.agent/skills/languages/clojure/META.yaml +1 -1
- package/.agent/skills/languages/clojure/SKILL.md +1 -1
- package/.agent/skills/languages/cpp/META.yaml +1 -1
- package/.agent/skills/languages/cpp/SKILL.md +22 -753
- package/.agent/skills/languages/cpp/references/headers-optimization.md +229 -0
- package/.agent/skills/languages/cpp/references/memory-concurrency.md +85 -0
- package/.agent/skills/languages/cpp/references/modern-cpp-features.md +126 -0
- package/.agent/skills/languages/cpp/references/platform-headers.md +202 -0
- package/.agent/skills/languages/cpp/references/stl-containers.md +57 -0
- package/.agent/skills/languages/crystal/META.yaml +1 -1
- package/.agent/skills/languages/crystal/SKILL.md +1 -1
- package/.agent/skills/languages/csharp/META.yaml +1 -1
- package/.agent/skills/languages/csharp/SKILL.md +1 -1
- package/.agent/skills/languages/elixir/META.yaml +1 -1
- package/.agent/skills/languages/elixir/SKILL.md +1 -1
- package/.agent/skills/languages/fsharp/META.yaml +1 -1
- package/.agent/skills/languages/fsharp/SKILL.md +1 -1
- package/.agent/skills/languages/go/META.yaml +1 -1
- package/.agent/skills/languages/go/SKILL.md +1 -1
- package/.agent/skills/languages/haskell/META.yaml +1 -1
- package/.agent/skills/languages/haskell/SKILL.md +1 -1
- package/.agent/skills/languages/java/META.yaml +1 -1
- package/.agent/skills/languages/java/SKILL.md +1 -1
- package/.agent/skills/languages/javascript/META.yaml +1 -1
- package/.agent/skills/languages/javascript/SKILL.md +1 -1
- package/.agent/skills/languages/julia/META.yaml +1 -1
- package/.agent/skills/languages/julia/SKILL.md +1 -1
- package/.agent/skills/languages/kotlin/META.yaml +1 -1
- package/.agent/skills/languages/kotlin/SKILL.md +1 -1
- package/.agent/skills/languages/lua/META.yaml +1 -1
- package/.agent/skills/languages/lua/SKILL.md +3 -3
- package/.agent/skills/languages/nim/META.yaml +1 -1
- package/.agent/skills/languages/nim/SKILL.md +1 -1
- package/.agent/skills/languages/ocaml/META.yaml +1 -1
- package/.agent/skills/languages/ocaml/SKILL.md +1 -1
- package/.agent/skills/languages/perl/META.yaml +1 -1
- package/.agent/skills/languages/perl/SKILL.md +1 -1
- package/.agent/skills/languages/php/META.yaml +1 -1
- package/.agent/skills/languages/php/SKILL.md +1 -1
- package/.agent/skills/languages/python/META.yaml +1 -1
- package/.agent/skills/languages/python/SKILL.md +1 -1
- package/.agent/skills/languages/r/META.yaml +1 -1
- package/.agent/skills/languages/r/SKILL.md +1 -1
- package/.agent/skills/languages/ruby/META.yaml +1 -1
- package/.agent/skills/languages/ruby/SKILL.md +1 -1
- package/.agent/skills/languages/rust/META.yaml +1 -1
- package/.agent/skills/languages/rust/SKILL.md +1 -1
- package/.agent/skills/languages/scala/META.yaml +1 -1
- package/.agent/skills/languages/scala/SKILL.md +1 -1
- package/.agent/skills/languages/solidity/META.yaml +1 -1
- package/.agent/skills/languages/solidity/SKILL.md +1 -1
- package/.agent/skills/languages/swift/META.yaml +1 -1
- package/.agent/skills/languages/swift/SKILL.md +1 -1
- package/.agent/skills/languages/typescript/META.yaml +19 -1
- package/.agent/skills/languages/typescript/SKILL.md +23 -1
- package/.agent/skills/languages/zig/META.yaml +1 -1
- package/.agent/skills/languages/zig/SKILL.md +1 -1
- package/.agent/templates/README.md +2 -2
- package/.agent/templates/chains/feature/step1-requirements.md +76 -0
- package/.agent/templates/chains/feature/step2-design.md +75 -0
- package/.agent/templates/chains/feature/step3-planning.md +81 -0
- package/.agent/templates/chains/feature/step4-implementation.md +74 -0
- package/.agent/templates/chains/feature/step5-testing.md +81 -0
- package/.agent/templates/debug-report.md +1 -1
- package/.agent/templates/deploy-plan.md +1 -1
- package/.agent/templates/doc-template.md +1 -1
- package/.agent/templates/feature-lifecycle.md +53 -0
- package/.agent/templates/index.yaml +53 -2
- package/.agent/templates/migrate-plan.md +1 -1
- package/.agent/templates/phase-template.md +1 -1
- package/.agent/templates/tasks/audit.yaml +1 -1
- package/.agent/templates/tasks/bug_fix.yaml +1 -1
- package/.agent/templates/tasks/code_implementation.yaml +1 -1
- package/.agent/templates/tasks/feature_development.yaml +89 -0
- package/.agent/templates/tasks/refactor.yaml +1 -1
- package/.agent/templates/test-report.md +1 -1
- package/.agent/workflows/doctor.md +124 -0
- package/.agent/workflows/feature.md +130 -0
- package/.agent/workflows/help.md +7 -5
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: cpp
|
|
3
3
|
detect: ["CMakeLists.txt", "*.cpp", "*.cxx", "*.cc", "*.hpp", "*.hxx", "*.h"]
|
|
4
|
-
version: "6.2.
|
|
4
|
+
version: "6.2.7"
|
|
5
5
|
category: language
|
|
6
6
|
tier: 1
|
|
7
7
|
---
|
|
@@ -10,7 +10,7 @@ tier: 1
|
|
|
10
10
|
|
|
11
11
|
> Modern C++ (C++20/23/26) patterns — NOT Pure C
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## 🔍 Language Detection
|
|
14
14
|
|
|
15
15
|
```yaml
|
|
16
16
|
cpp_indicators: # C++ skill activates
|
|
@@ -23,7 +23,6 @@ cpp_indicators: # C++ skill activates
|
|
|
23
23
|
- "namespace "
|
|
24
24
|
- "template<"
|
|
25
25
|
- "auto "
|
|
26
|
-
- "new/delete operators"
|
|
27
26
|
- ".cpp, .cxx, .cc, .hpp files"
|
|
28
27
|
|
|
29
28
|
c_only_indicators: # Switch to C skill
|
|
@@ -75,252 +74,9 @@ features:
|
|
|
75
74
|
- Nova engine (improved parsing)
|
|
76
75
|
```
|
|
77
76
|
|
|
78
|
-
### VS Code
|
|
79
|
-
|
|
80
|
-
```yaml
|
|
81
|
-
extensions:
|
|
82
|
-
- C/C++ (Microsoft)
|
|
83
|
-
- CMake Tools
|
|
84
|
-
- clangd (alternative language server)
|
|
85
|
-
features:
|
|
86
|
-
- CMakePresets.json support
|
|
87
|
-
- vcpkg/Conan integration
|
|
88
|
-
- Remote development
|
|
89
|
-
```
|
|
90
|
-
|
|
91
77
|
---
|
|
92
78
|
|
|
93
|
-
##
|
|
94
|
-
|
|
95
|
-
> **GOAL**: Minimize includes in `.h` files → Faster compilation, less coupling
|
|
96
|
-
|
|
97
|
-
### 1. Forward Declarations (Prefer over #include in headers)
|
|
98
|
-
|
|
99
|
-
```cpp
|
|
100
|
-
// ❌ BAD: Heavy includes in header file
|
|
101
|
-
// user.h
|
|
102
|
-
#include <string> // Full include
|
|
103
|
-
#include <vector> // Full include
|
|
104
|
-
#include <memory> // Full include
|
|
105
|
-
#include "database.h" // Heavy include!
|
|
106
|
-
#include "logger.h" // Heavy include!
|
|
107
|
-
|
|
108
|
-
class User {
|
|
109
|
-
std::unique_ptr<Database> db_; // Requires full Database type
|
|
110
|
-
std::string name_;
|
|
111
|
-
std::vector<int> orders_;
|
|
112
|
-
};
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
```cpp
|
|
116
|
-
// ✅ GOOD: Forward declarations + minimal includes
|
|
117
|
-
// user.h
|
|
118
|
-
#include <string> // Required (used directly)
|
|
119
|
-
#include <memory> // Required for unique_ptr
|
|
120
|
-
|
|
121
|
-
class Database; // Forward declaration only!
|
|
122
|
-
class Logger; // Forward declaration only!
|
|
123
|
-
|
|
124
|
-
class User {
|
|
125
|
-
std::unique_ptr<Database> db_; // OK with incomplete type
|
|
126
|
-
std::string name_;
|
|
127
|
-
std::vector<int>* orders_; // Pointer = OK with forward decl
|
|
128
|
-
};
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
```cpp
|
|
132
|
-
// user.cpp - Include the full headers here
|
|
133
|
-
#include "user.h" // Own header FIRST
|
|
134
|
-
#include <vector> // Now we need full definition
|
|
135
|
-
#include "database.h" // Full include in implementation
|
|
136
|
-
#include "logger.h" // Full include in implementation
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
### 2. When Forward Declaration Works
|
|
140
|
-
|
|
141
|
-
| Scenario | Forward Decl OK? | Notes |
|
|
142
|
-
| ----------------------------- | ------------------- | ----------------------------- |
|
|
143
|
-
| Pointer to class (`T*`) | ✅ Yes | Size known (pointer size) |
|
|
144
|
-
| Reference to class (`T&`) | ✅ Yes | Size known |
|
|
145
|
-
| `std::unique_ptr<T>` | ⚠️ Partial | Need full type for destructor |
|
|
146
|
-
| `std::shared_ptr<T>` | ✅ Yes | Incomplete type allowed |
|
|
147
|
-
| Class member (`T member`) | ❌ No | Size required |
|
|
148
|
-
| Inheritance (`class A : B`) | ❌ No | Full type required |
|
|
149
|
-
| Template parameter | ⚠️ Depends | Often needs full type |
|
|
150
|
-
| Function parameter (`f(T x)`) | ⚠️ Declaration only | Implementation needs full |
|
|
151
|
-
| Function return (`T f()`) | ⚠️ Declaration only | Implementation needs full |
|
|
152
|
-
|
|
153
|
-
### 3. PIMPL Idiom (Pointer to Implementation)
|
|
154
|
-
|
|
155
|
-
> **Purpose**: Hide implementation, reduce compilation dependencies, ABI stability
|
|
156
|
-
|
|
157
|
-
```cpp
|
|
158
|
-
// widget.h - PUBLIC HEADER (minimal includes!)
|
|
159
|
-
#pragma once
|
|
160
|
-
#include <memory> // Only for unique_ptr
|
|
161
|
-
|
|
162
|
-
class Widget {
|
|
163
|
-
public:
|
|
164
|
-
Widget();
|
|
165
|
-
~Widget(); // Must be declared (impl needs complete type)
|
|
166
|
-
|
|
167
|
-
// Move operations
|
|
168
|
-
Widget(Widget&& other) noexcept;
|
|
169
|
-
Widget& operator=(Widget&& other) noexcept;
|
|
170
|
-
|
|
171
|
-
// Deleted copy (or implement in .cpp)
|
|
172
|
-
Widget(const Widget&) = delete;
|
|
173
|
-
Widget& operator=(const Widget&) = delete;
|
|
174
|
-
|
|
175
|
-
void doSomething();
|
|
176
|
-
int getValue() const;
|
|
177
|
-
|
|
178
|
-
private:
|
|
179
|
-
struct Impl; // Forward declaration
|
|
180
|
-
std::unique_ptr<Impl> pimpl_; // Opaque pointer
|
|
181
|
-
};
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
```cpp
|
|
185
|
-
// widget.cpp - IMPLEMENTATION (heavy includes here)
|
|
186
|
-
#include "widget.h"
|
|
187
|
-
#include <string> // Heavy STL
|
|
188
|
-
#include <vector> // Heavy STL
|
|
189
|
-
#include <unordered_map> // Heavy STL
|
|
190
|
-
#include "database.h" // Heavy dependency
|
|
191
|
-
#include "network_client.h" // Heavy dependency
|
|
192
|
-
#include <windows.h> // Platform header - ONLY in .cpp!
|
|
193
|
-
|
|
194
|
-
struct Widget::Impl {
|
|
195
|
-
std::string name;
|
|
196
|
-
std::vector<int> data;
|
|
197
|
-
std::unordered_map<int, std::string> cache;
|
|
198
|
-
std::unique_ptr<Database> db;
|
|
199
|
-
NetworkClient client;
|
|
200
|
-
HANDLE winHandle; // Windows-specific - hidden from header
|
|
201
|
-
|
|
202
|
-
void internalHelper() { /* ... */ }
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
Widget::Widget() : pimpl_(std::make_unique<Impl>()) {}
|
|
206
|
-
|
|
207
|
-
Widget::~Widget() = default; // Must be in .cpp where Impl is complete
|
|
208
|
-
|
|
209
|
-
Widget::Widget(Widget&& other) noexcept = default;
|
|
210
|
-
Widget& Widget::operator=(Widget&& other) noexcept = default;
|
|
211
|
-
|
|
212
|
-
void Widget::doSomething() {
|
|
213
|
-
pimpl_->internalHelper();
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
int Widget::getValue() const {
|
|
217
|
-
return static_cast<int>(pimpl_->data.size());
|
|
218
|
-
}
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
### 4. Dangerous Headers (NEVER include in .h files)
|
|
222
|
-
|
|
223
|
-
| Header | Problem | Solution |
|
|
224
|
-
| ----------------------- | ------------------------------------ | ----------------------- |
|
|
225
|
-
| `<windows.h>` | 15k+ lines, macros pollute namespace | PIMPL or forward decl |
|
|
226
|
-
| `<winsock2.h>` | Heavy, conflicts | PIMPL only in .cpp |
|
|
227
|
-
| `<algorithm>` | 10k+ lines | Forward decl iterators |
|
|
228
|
-
| `<iostream>` | Heavy, static init | Forward declare streams |
|
|
229
|
-
| `<regex>` | Extremely heavy | PIMPL |
|
|
230
|
-
| `<thread>` | Platform headers | PIMPL |
|
|
231
|
-
| `<filesystem>` | Heavy | PIMPL |
|
|
232
|
-
| Project's large headers | Compilation cascade | Forward decl |
|
|
233
|
-
|
|
234
|
-
### 5. Include-What-You-Use (IWYU)
|
|
235
|
-
|
|
236
|
-
```bash
|
|
237
|
-
# Run IWYU on single file
|
|
238
|
-
include-what-you-use -Xiwyu --mapping_file=iwyu.imp myfile.cpp
|
|
239
|
-
|
|
240
|
-
# CMake integration
|
|
241
|
-
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE include-what-you-use)
|
|
242
|
-
|
|
243
|
-
# IWYU pragmas
|
|
244
|
-
#include "heavy.h" // IWYU pragma: keep (prevent removal)
|
|
245
|
-
// IWYU pragma: no_include "deprecated.h" (prevent suggestion)
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
### 6. Precompiled Headers (PCH)
|
|
249
|
-
|
|
250
|
-
```cmake
|
|
251
|
-
# CMakeLists.txt - Modern PCH (CMake 3.16+)
|
|
252
|
-
target_precompile_headers(myapp PRIVATE
|
|
253
|
-
# STL headers (stable, include once)
|
|
254
|
-
<vector>
|
|
255
|
-
<string>
|
|
256
|
-
<memory>
|
|
257
|
-
<algorithm>
|
|
258
|
-
<unordered_map>
|
|
259
|
-
|
|
260
|
-
# Third-party (stable)
|
|
261
|
-
<fmt/core.h>
|
|
262
|
-
<spdlog/spdlog.h>
|
|
263
|
-
|
|
264
|
-
# Project stable headers
|
|
265
|
-
"common/types.h"
|
|
266
|
-
"common/constants.h"
|
|
267
|
-
)
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
### 7. C++20 Modules (Future-Proof)
|
|
271
|
-
|
|
272
|
-
```cpp
|
|
273
|
-
// math.cppm - Module interface
|
|
274
|
-
export module math;
|
|
275
|
-
|
|
276
|
-
export int add(int a, int b);
|
|
277
|
-
export int multiply(int a, int b);
|
|
278
|
-
|
|
279
|
-
// math.cpp - Module implementation
|
|
280
|
-
module math;
|
|
281
|
-
|
|
282
|
-
int add(int a, int b) { return a + b; }
|
|
283
|
-
int multiply(int a, int b) { return a * b; }
|
|
284
|
-
|
|
285
|
-
// main.cpp - Using module
|
|
286
|
-
import math; // Fast import, no re-parsing!
|
|
287
|
-
import std; // Import entire std library (C++23)
|
|
288
|
-
|
|
289
|
-
int main() {
|
|
290
|
-
return add(1, 2);
|
|
291
|
-
}
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
### 8. Header Include Order (Best Practice)
|
|
295
|
-
|
|
296
|
-
```cpp
|
|
297
|
-
// myclass.cpp
|
|
298
|
-
|
|
299
|
-
// 1. OWN HEADER FIRST (validates self-containment)
|
|
300
|
-
#include "myclass.h"
|
|
301
|
-
|
|
302
|
-
// 2. C system headers
|
|
303
|
-
#include <cstdio>
|
|
304
|
-
#include <cstdlib>
|
|
305
|
-
|
|
306
|
-
// 3. C++ STL headers
|
|
307
|
-
#include <string>
|
|
308
|
-
#include <vector>
|
|
309
|
-
#include <algorithm>
|
|
310
|
-
|
|
311
|
-
// 4. Third-party library headers
|
|
312
|
-
#include <fmt/core.h>
|
|
313
|
-
#include <spdlog/spdlog.h>
|
|
314
|
-
#include <nlohmann/json.hpp>
|
|
315
|
-
|
|
316
|
-
// 5. Project headers (alphabetical)
|
|
317
|
-
#include "database/connection.h"
|
|
318
|
-
#include "utils/string_utils.h"
|
|
319
|
-
```
|
|
320
|
-
|
|
321
|
-
---
|
|
322
|
-
|
|
323
|
-
## �📦 Build & Package Management
|
|
79
|
+
## 📦 Build & Package Management
|
|
324
80
|
|
|
325
81
|
### CMake (Modern)
|
|
326
82
|
|
|
@@ -332,24 +88,12 @@ set(CMAKE_CXX_STANDARD 23)
|
|
|
332
88
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
333
89
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
334
90
|
|
|
335
|
-
# Find packages
|
|
336
91
|
find_package(fmt REQUIRED)
|
|
337
92
|
find_package(spdlog REQUIRED)
|
|
338
93
|
|
|
339
|
-
add_executable(myapp
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
)
|
|
343
|
-
|
|
344
|
-
target_link_libraries(myapp PRIVATE
|
|
345
|
-
fmt::fmt
|
|
346
|
-
spdlog::spdlog
|
|
347
|
-
)
|
|
348
|
-
|
|
349
|
-
# Include directories
|
|
350
|
-
target_include_directories(myapp PRIVATE
|
|
351
|
-
${CMAKE_SOURCE_DIR}/include
|
|
352
|
-
)
|
|
94
|
+
add_executable(myapp src/main.cpp src/utils.cpp)
|
|
95
|
+
target_link_libraries(myapp PRIVATE fmt::fmt spdlog::spdlog)
|
|
96
|
+
target_include_directories(myapp PRIVATE ${CMAKE_SOURCE_DIR}/include)
|
|
353
97
|
```
|
|
354
98
|
|
|
355
99
|
### CMakePresets.json
|
|
@@ -360,7 +104,6 @@ target_include_directories(myapp PRIVATE
|
|
|
360
104
|
"configurePresets": [
|
|
361
105
|
{
|
|
362
106
|
"name": "dev",
|
|
363
|
-
"displayName": "Development",
|
|
364
107
|
"generator": "Ninja",
|
|
365
108
|
"binaryDir": "${sourceDir}/build/${presetName}",
|
|
366
109
|
"cacheVariables": {
|
|
@@ -370,526 +113,52 @@ target_include_directories(myapp PRIVATE
|
|
|
370
113
|
},
|
|
371
114
|
{
|
|
372
115
|
"name": "release",
|
|
373
|
-
"displayName": "Release",
|
|
374
116
|
"generator": "Ninja",
|
|
375
117
|
"binaryDir": "${sourceDir}/build/${presetName}",
|
|
376
|
-
"cacheVariables": {
|
|
377
|
-
"CMAKE_BUILD_TYPE": "Release"
|
|
378
|
-
}
|
|
118
|
+
"cacheVariables": { "CMAKE_BUILD_TYPE": "Release" }
|
|
379
119
|
}
|
|
380
|
-
],
|
|
381
|
-
"buildPresets": [
|
|
382
|
-
{ "name": "dev", "configurePreset": "dev" },
|
|
383
|
-
{ "name": "release", "configurePreset": "release" }
|
|
384
120
|
]
|
|
385
121
|
}
|
|
386
122
|
```
|
|
387
123
|
|
|
388
|
-
###
|
|
124
|
+
### Package Managers
|
|
389
125
|
|
|
390
126
|
```bash
|
|
391
|
-
#
|
|
127
|
+
# vcpkg
|
|
392
128
|
vcpkg install fmt spdlog nlohmann-json
|
|
393
|
-
|
|
394
|
-
# CMake integration
|
|
395
129
|
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake
|
|
396
130
|
```
|
|
397
131
|
|
|
398
|
-
### Conan 2.0
|
|
399
|
-
|
|
400
132
|
```ini
|
|
401
|
-
# conanfile.txt
|
|
133
|
+
# Conan 2.0 (conanfile.txt)
|
|
402
134
|
[requires]
|
|
403
135
|
fmt/10.2.1
|
|
404
136
|
spdlog/1.13.0
|
|
405
|
-
|
|
406
137
|
[generators]
|
|
407
138
|
CMakeDeps
|
|
408
139
|
CMakeToolchain
|
|
409
|
-
|
|
410
|
-
[layout]
|
|
411
|
-
cmake_layout
|
|
412
|
-
```
|
|
413
|
-
|
|
414
|
-
---
|
|
415
|
-
|
|
416
|
-
## 📚 STL Containers Reference
|
|
417
|
-
|
|
418
|
-
### Sequence Containers
|
|
419
|
-
|
|
420
|
-
| Container | Access | Insert/Delete | Use Case |
|
|
421
|
-
| ---------------------- | ------ | ------------------ | ------------------- |
|
|
422
|
-
| `std::vector<T>` | O(1) | O(1) amortized end | Dynamic array |
|
|
423
|
-
| `std::deque<T>` | O(1) | O(1) both ends | Double-ended queue |
|
|
424
|
-
| `std::list<T>` | O(n) | O(1) anywhere | Frequent insertions |
|
|
425
|
-
| `std::array<T,N>` | O(1) | Fixed | Compile-time size |
|
|
426
|
-
| `std::forward_list<T>` | O(n) | O(1) | Singly linked |
|
|
427
|
-
|
|
428
|
-
### Associative Containers
|
|
429
|
-
|
|
430
|
-
| Container | Access | Insert | Ordered | Use Case |
|
|
431
|
-
| ------------------------- | -------- | -------- | ------- | ---------------- |
|
|
432
|
-
| `std::map<K,V>` | O(log n) | O(log n) | Yes | Key-value sorted |
|
|
433
|
-
| `std::set<T>` | O(log n) | O(log n) | Yes | Unique sorted |
|
|
434
|
-
| `std::multimap<K,V>` | O(log n) | O(log n) | Yes | Multiple values |
|
|
435
|
-
| `std::unordered_map<K,V>` | O(1) avg | O(1) avg | No | Fast lookups |
|
|
436
|
-
| `std::unordered_set<T>` | O(1) avg | O(1) avg | No | Fast membership |
|
|
437
|
-
|
|
438
|
-
### Container Usage
|
|
439
|
-
|
|
440
|
-
```cpp
|
|
441
|
-
#include <vector>
|
|
442
|
-
#include <map>
|
|
443
|
-
#include <unordered_map>
|
|
444
|
-
#include <array>
|
|
445
|
-
|
|
446
|
-
// ✅ Vector with reserve
|
|
447
|
-
std::vector<int> nums;
|
|
448
|
-
nums.reserve(1000); // Pre-allocate
|
|
449
|
-
nums.push_back(42);
|
|
450
|
-
nums.emplace_back(100);
|
|
451
|
-
|
|
452
|
-
// ✅ Range-based for
|
|
453
|
-
for (const auto& num : nums) {
|
|
454
|
-
std::cout << num << '\n';
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
// ✅ Map with structured bindings
|
|
458
|
-
std::map<std::string, int> scores{{"Alice", 100}, {"Bob", 85}};
|
|
459
|
-
for (const auto& [name, score] : scores) {
|
|
460
|
-
std::cout << name << ": " << score << '\n';
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
// ✅ Unordered map for O(1) lookups
|
|
464
|
-
std::unordered_map<int, std::string> idToName;
|
|
465
|
-
idToName[1] = "John";
|
|
466
|
-
if (auto it = idToName.find(1); it != idToName.end()) {
|
|
467
|
-
std::cout << it->second << '\n';
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
// ✅ Fixed-size array
|
|
471
|
-
std::array<int, 5> arr{1, 2, 3, 4, 5};
|
|
472
|
-
```
|
|
473
|
-
|
|
474
|
-
---
|
|
475
|
-
|
|
476
|
-
## 🔧 Modern C++ Features
|
|
477
|
-
|
|
478
|
-
### C++20: Concepts
|
|
479
|
-
|
|
480
|
-
```cpp
|
|
481
|
-
#include <concepts>
|
|
482
|
-
|
|
483
|
-
// Define concept
|
|
484
|
-
template<typename T>
|
|
485
|
-
concept Numeric = std::integral<T> || std::floating_point<T>;
|
|
486
|
-
|
|
487
|
-
// Use concept
|
|
488
|
-
template<Numeric T>
|
|
489
|
-
T add(T a, T b) {
|
|
490
|
-
return a + b;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
// Requires clause
|
|
494
|
-
template<typename T>
|
|
495
|
-
requires std::copyable<T>
|
|
496
|
-
void process(T value) {
|
|
497
|
-
// ...
|
|
498
|
-
}
|
|
499
|
-
```
|
|
500
|
-
|
|
501
|
-
### C++20: Ranges
|
|
502
|
-
|
|
503
|
-
```cpp
|
|
504
|
-
#include <ranges>
|
|
505
|
-
#include <vector>
|
|
506
|
-
#include <algorithm>
|
|
507
|
-
|
|
508
|
-
std::vector<int> nums{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
|
509
|
-
|
|
510
|
-
// ✅ Ranges with views (lazy evaluation)
|
|
511
|
-
auto result = nums
|
|
512
|
-
| std::views::filter([](int n) { return n % 2 == 0; })
|
|
513
|
-
| std::views::transform([](int n) { return n * 2; })
|
|
514
|
-
| std::views::take(3);
|
|
515
|
-
|
|
516
|
-
for (int n : result) {
|
|
517
|
-
std::cout << n << ' '; // 4 8 12
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
// ✅ Range algorithms
|
|
521
|
-
std::ranges::sort(nums);
|
|
522
|
-
auto found = std::ranges::find(nums, 5);
|
|
523
|
-
bool all_positive = std::ranges::all_of(nums, [](int n) { return n > 0; });
|
|
524
|
-
```
|
|
525
|
-
|
|
526
|
-
### C++20: std::format
|
|
527
|
-
|
|
528
|
-
```cpp
|
|
529
|
-
#include <format>
|
|
530
|
-
#include <string>
|
|
531
|
-
|
|
532
|
-
std::string msg = std::format("User {}: {}", id, name);
|
|
533
|
-
std::string formatted = std::format("{:0>8}", 42); // "00000042"
|
|
534
|
-
std::string hex = std::format("{:#x}", 255); // "0xff"
|
|
535
|
-
```
|
|
536
|
-
|
|
537
|
-
### C++23: std::expected
|
|
538
|
-
|
|
539
|
-
```cpp
|
|
540
|
-
#include <expected>
|
|
541
|
-
#include <string>
|
|
542
|
-
|
|
543
|
-
enum class Error { NotFound, Invalid };
|
|
544
|
-
|
|
545
|
-
std::expected<User, Error> findUser(int id) {
|
|
546
|
-
if (auto it = users.find(id); it != users.end()) {
|
|
547
|
-
return it->second;
|
|
548
|
-
}
|
|
549
|
-
return std::unexpected(Error::NotFound);
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
// Usage
|
|
553
|
-
auto result = findUser(42);
|
|
554
|
-
if (result) {
|
|
555
|
-
std::cout << result->name;
|
|
556
|
-
} else {
|
|
557
|
-
std::cerr << "Error: " << static_cast<int>(result.error());
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
// Or with transform
|
|
561
|
-
result.transform([](const User& u) { return u.name; })
|
|
562
|
-
.or_else([](Error e) { return "Unknown"; });
|
|
563
|
-
```
|
|
564
|
-
|
|
565
|
-
### C++23: std::print
|
|
566
|
-
|
|
567
|
-
```cpp
|
|
568
|
-
#include <print>
|
|
569
|
-
|
|
570
|
-
// Type-safe printf replacement
|
|
571
|
-
std::print("Hello, {}!\n", name);
|
|
572
|
-
std::println("User {}: score = {}", id, score); // with newline
|
|
573
|
-
|
|
574
|
-
// Formatted output
|
|
575
|
-
std::print("{:>10} | {:>5}\n", "Name", "Score");
|
|
576
|
-
```
|
|
577
|
-
|
|
578
|
-
### C++23: Modules
|
|
579
|
-
|
|
580
|
-
```cpp
|
|
581
|
-
// mymodule.cppm
|
|
582
|
-
export module mymodule;
|
|
583
|
-
|
|
584
|
-
export class Widget {
|
|
585
|
-
public:
|
|
586
|
-
void process();
|
|
587
|
-
};
|
|
588
|
-
|
|
589
|
-
export void helper();
|
|
590
|
-
|
|
591
|
-
// main.cpp
|
|
592
|
-
import mymodule; // Import custom module
|
|
593
|
-
import std; // Import entire standard library!
|
|
594
|
-
|
|
595
|
-
int main() {
|
|
596
|
-
Widget w;
|
|
597
|
-
w.process();
|
|
598
|
-
}
|
|
599
|
-
```
|
|
600
|
-
|
|
601
|
-
---
|
|
602
|
-
|
|
603
|
-
## 🧠 Memory Management
|
|
604
|
-
|
|
605
|
-
### Smart Pointers
|
|
606
|
-
|
|
607
|
-
```cpp
|
|
608
|
-
#include <memory>
|
|
609
|
-
|
|
610
|
-
// ✅ unique_ptr (exclusive ownership)
|
|
611
|
-
auto widget = std::make_unique<Widget>(config);
|
|
612
|
-
|
|
613
|
-
// ✅ shared_ptr (shared ownership)
|
|
614
|
-
auto resource = std::make_shared<Resource>();
|
|
615
|
-
auto copy = resource; // Reference count = 2
|
|
616
|
-
|
|
617
|
-
// ✅ weak_ptr (non-owning reference)
|
|
618
|
-
std::weak_ptr<Resource> weak = resource;
|
|
619
|
-
if (auto locked = weak.lock()) {
|
|
620
|
-
// Use locked safely
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
// ✅ Custom deleter
|
|
624
|
-
auto file = std::unique_ptr<FILE, decltype(&fclose)>(
|
|
625
|
-
fopen("data.txt", "r"), fclose
|
|
626
|
-
);
|
|
627
|
-
```
|
|
628
|
-
|
|
629
|
-
### Move Semantics
|
|
630
|
-
|
|
631
|
-
```cpp
|
|
632
|
-
class Buffer {
|
|
633
|
-
std::unique_ptr<uint8_t[]> data_;
|
|
634
|
-
size_t size_;
|
|
635
|
-
|
|
636
|
-
public:
|
|
637
|
-
// Move constructor
|
|
638
|
-
Buffer(Buffer&& other) noexcept
|
|
639
|
-
: data_(std::move(other.data_))
|
|
640
|
-
, size_(std::exchange(other.size_, 0)) {}
|
|
641
|
-
|
|
642
|
-
// Move assignment
|
|
643
|
-
Buffer& operator=(Buffer&& other) noexcept {
|
|
644
|
-
if (this != &other) {
|
|
645
|
-
data_ = std::move(other.data_);
|
|
646
|
-
size_ = std::exchange(other.size_, 0);
|
|
647
|
-
}
|
|
648
|
-
return *this;
|
|
649
|
-
}
|
|
650
|
-
};
|
|
651
140
|
```
|
|
652
141
|
|
|
653
142
|
---
|
|
654
143
|
|
|
655
|
-
##
|
|
656
|
-
|
|
657
|
-
### std::jthread (C++20)
|
|
144
|
+
## 📚 Deep-Dive References
|
|
658
145
|
|
|
659
|
-
|
|
660
|
-
#include <thread>
|
|
661
|
-
#include <stop_token>
|
|
146
|
+
For detailed patterns, see these reference files:
|
|
662
147
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
// Do work
|
|
666
|
-
}
|
|
667
|
-
});
|
|
668
|
-
|
|
669
|
-
// Automatic join on destruction
|
|
670
|
-
// Can request stop: worker.request_stop();
|
|
671
|
-
```
|
|
148
|
+
- **Header Optimization** — PIMPL, forward declarations, PCH, IWYU, C++20 modules
|
|
149
|
+
→ See [references/headers-optimization.md](references/headers-optimization.md)
|
|
672
150
|
|
|
673
|
-
|
|
151
|
+
- **STL Containers** — Sequence/Associative containers comparison, usage patterns
|
|
152
|
+
→ See [references/stl-containers.md](references/stl-containers.md)
|
|
674
153
|
|
|
675
|
-
|
|
676
|
-
|
|
154
|
+
- **Modern C++ Features** — C++20 Concepts, Ranges, std::format, C++23 std::expected/print
|
|
155
|
+
→ See [references/modern-cpp-features.md](references/modern-cpp-features.md)
|
|
677
156
|
|
|
678
|
-
|
|
157
|
+
- **Memory & Concurrency** — Smart pointers, move semantics, jthread, atomic
|
|
158
|
+
→ See [references/memory-concurrency.md](references/memory-concurrency.md)
|
|
679
159
|
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
int get() {
|
|
685
|
-
return counter.load(std::memory_order_acquire);
|
|
686
|
-
}
|
|
687
|
-
```
|
|
688
|
-
|
|
689
|
-
---
|
|
690
|
-
|
|
691
|
-
## ⚠️ Platform-Specific Headers (CRITICAL)
|
|
692
|
-
|
|
693
|
-
### Windows Headers Conflicts
|
|
694
|
-
|
|
695
|
-
> **CRITICAL**: Windows headers have many conflicts. Follow this order exactly!
|
|
696
|
-
|
|
697
|
-
#### 1. Include Order (winsock2.h BEFORE windows.h)
|
|
698
|
-
|
|
699
|
-
```cpp
|
|
700
|
-
// ✅ CORRECT ORDER - winsock2.h MUST come before windows.h
|
|
701
|
-
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff
|
|
702
|
-
#define NOMINMAX // Prevent min/max macros
|
|
703
|
-
#define STRICT // Enable strict type checking
|
|
704
|
-
#define UNICODE // Use Unicode APIs
|
|
705
|
-
#define _UNICODE
|
|
706
|
-
|
|
707
|
-
#include <winsock2.h> // 1st - Winsock 2.0
|
|
708
|
-
#include <ws2tcpip.h> // 2nd - TCP/IP extensions
|
|
709
|
-
#include <windows.h> // 3rd - Windows API
|
|
710
|
-
|
|
711
|
-
// ❌ WRONG - causes redefinition errors!
|
|
712
|
-
#include <windows.h> // includes winsock.h (1.1)
|
|
713
|
-
#include <winsock2.h> // conflicts with winsock.h!
|
|
714
|
-
```
|
|
715
|
-
|
|
716
|
-
#### 2. Essential Macros (Define BEFORE any Windows includes)
|
|
717
|
-
|
|
718
|
-
```cpp
|
|
719
|
-
// pch.h or stdafx.h - Put at TOP of precompiled header
|
|
720
|
-
#ifndef WIN32_LEAN_AND_MEAN
|
|
721
|
-
#define WIN32_LEAN_AND_MEAN // Exclude: Cryptography, DDE, RPC, Shell, Winsock 1.1
|
|
722
|
-
#endif
|
|
723
|
-
|
|
724
|
-
#ifndef NOMINMAX
|
|
725
|
-
#define NOMINMAX // Prevent Windows min/max macros
|
|
726
|
-
#endif // Allows std::min, std::max to work
|
|
727
|
-
|
|
728
|
-
#ifndef STRICT
|
|
729
|
-
#define STRICT // Strict type checking for handles
|
|
730
|
-
#endif
|
|
731
|
-
|
|
732
|
-
// Now safe to include Windows headers
|
|
733
|
-
#include <windows.h>
|
|
734
|
-
```
|
|
735
|
-
|
|
736
|
-
#### 3. min/max Macro Conflicts
|
|
737
|
-
|
|
738
|
-
```cpp
|
|
739
|
-
// ❌ Problem: Windows defines min/max as macros
|
|
740
|
-
#include <windows.h>
|
|
741
|
-
#include <algorithm>
|
|
742
|
-
int x = std::min(a, b); // ERROR: macro expansion!
|
|
743
|
-
|
|
744
|
-
// ✅ Solution 1: Use NOMINMAX (recommended)
|
|
745
|
-
#define NOMINMAX
|
|
746
|
-
#include <windows.h>
|
|
747
|
-
#include <algorithm>
|
|
748
|
-
int x = std::min(a, b); // Works!
|
|
749
|
-
|
|
750
|
-
// ✅ Solution 2: Parentheses workaround
|
|
751
|
-
int x = (std::min)(a, b); // Prevents macro expansion
|
|
752
|
-
|
|
753
|
-
// ✅ Solution 3: #undef after include
|
|
754
|
-
#include <windows.h>
|
|
755
|
-
#undef min
|
|
756
|
-
#undef max
|
|
757
|
-
#include <algorithm>
|
|
758
|
-
```
|
|
759
|
-
|
|
760
|
-
#### 4. WIN32_LEAN_AND_MEAN Exclusions
|
|
761
|
-
|
|
762
|
-
```cpp
|
|
763
|
-
// WIN32_LEAN_AND_MEAN excludes these - include manually if needed:
|
|
764
|
-
#define WIN32_LEAN_AND_MEAN
|
|
765
|
-
#include <windows.h>
|
|
766
|
-
|
|
767
|
-
// If you need these, include AFTER windows.h:
|
|
768
|
-
#include <shellapi.h> // Shell API
|
|
769
|
-
#include <mmsystem.h> // Multimedia
|
|
770
|
-
#include <wincrypt.h> // Cryptography
|
|
771
|
-
#include <commdlg.h> // Common dialogs
|
|
772
|
-
#include <dde.h> // DDE
|
|
773
|
-
```
|
|
774
|
-
|
|
775
|
-
### Windows Headers Quick Reference
|
|
776
|
-
|
|
777
|
-
| Header | Purpose | Notes |
|
|
778
|
-
| -------------- | -------------------- | ----------------------------- |
|
|
779
|
-
| `<windows.h>` | Core Windows API | Always use with LEAN_AND_MEAN |
|
|
780
|
-
| `<winsock2.h>` | Sockets (Winsock 2) | MUST include BEFORE windows.h |
|
|
781
|
-
| `<ws2tcpip.h>` | TCP/IP, getaddrinfo | Include after winsock2.h |
|
|
782
|
-
| `<windowsx.h>` | Message crackers | Helper macros |
|
|
783
|
-
| `<commctrl.h>` | Common controls | ListView, TreeView, etc. |
|
|
784
|
-
| `<shlobj.h>` | Shell interface | Folder browser, etc. |
|
|
785
|
-
| `<shobjidl.h>` | Shell COM interfaces | Modern file dialogs |
|
|
786
|
-
| `<tchar.h>` | TCHAR portability | Legacy, prefer wchar_t |
|
|
787
|
-
|
|
788
|
-
---
|
|
789
|
-
|
|
790
|
-
### Linux/POSIX Headers
|
|
791
|
-
|
|
792
|
-
#### 1. Define \_REENTRANT for Thread-Safe Functions
|
|
793
|
-
|
|
794
|
-
```cpp
|
|
795
|
-
// ✅ Define BEFORE any system headers
|
|
796
|
-
#define _REENTRANT // Thread-safe libc functions
|
|
797
|
-
#define _POSIX_C_SOURCE 200809L // POSIX.1-2008
|
|
798
|
-
|
|
799
|
-
#include <pthread.h>
|
|
800
|
-
#include <unistd.h>
|
|
801
|
-
#include <signal.h>
|
|
802
|
-
```
|
|
803
|
-
|
|
804
|
-
#### 2. Signal Handling with Threads (Critical)
|
|
805
|
-
|
|
806
|
-
```cpp
|
|
807
|
-
#include <pthread.h>
|
|
808
|
-
#include <signal.h>
|
|
809
|
-
|
|
810
|
-
// ✅ Block signals in worker threads, handle in dedicated thread
|
|
811
|
-
int main() {
|
|
812
|
-
sigset_t set;
|
|
813
|
-
sigemptyset(&set);
|
|
814
|
-
sigaddset(&set, SIGINT);
|
|
815
|
-
sigaddset(&set, SIGTERM);
|
|
816
|
-
|
|
817
|
-
// Block signals in main thread (inherited by child threads)
|
|
818
|
-
pthread_sigmask(SIG_BLOCK, &set, NULL);
|
|
819
|
-
|
|
820
|
-
// Create worker threads (they inherit blocked signals)
|
|
821
|
-
pthread_t worker;
|
|
822
|
-
pthread_create(&worker, NULL, worker_func, NULL);
|
|
823
|
-
|
|
824
|
-
// Handle signals in main thread with sigwait
|
|
825
|
-
int sig;
|
|
826
|
-
while (sigwait(&set, &sig) == 0) {
|
|
827
|
-
if (sig == SIGINT || sig == SIGTERM) {
|
|
828
|
-
// Clean shutdown
|
|
829
|
-
break;
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
pthread_join(worker, NULL);
|
|
834
|
-
return 0;
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
// ❌ AVOID: Signal handlers with threads (race conditions!)
|
|
838
|
-
// Use sigwait() or signalfd() instead
|
|
839
|
-
```
|
|
840
|
-
|
|
841
|
-
#### 3. Common POSIX Headers
|
|
842
|
-
|
|
843
|
-
| Header | Purpose | Key Functions |
|
|
844
|
-
| ---------------- | ---------------- | ----------------------------------- |
|
|
845
|
-
| `<unistd.h>` | POSIX API | read, write, close, fork, exec |
|
|
846
|
-
| `<pthread.h>` | Threads | pthread*create, pthread_mutex*\* |
|
|
847
|
-
| `<signal.h>` | Signals | sigaction, sigwait, pthread_sigmask |
|
|
848
|
-
| `<fcntl.h>` | File control | open, fcntl, O\_\* flags |
|
|
849
|
-
| `<sys/types.h>` | Type definitions | pid_t, size_t, ssize_t |
|
|
850
|
-
| `<sys/socket.h>` | Sockets | socket, bind, listen, accept |
|
|
851
|
-
| `<netinet/in.h>` | Internet addr | sockaddr_in, htons, ntohs |
|
|
852
|
-
| `<arpa/inet.h>` | IP conversion | inet_pton, inet_ntop |
|
|
853
|
-
| `<sys/stat.h>` | File status | stat, fstat, mkdir |
|
|
854
|
-
| `<sys/mman.h>` | Memory mapping | mmap, munmap, mprotect |
|
|
855
|
-
| `<dlfcn.h>` | Dynamic loading | dlopen, dlsym, dlclose |
|
|
856
|
-
|
|
857
|
-
---
|
|
858
|
-
|
|
859
|
-
### Cross-Platform Patterns
|
|
860
|
-
|
|
861
|
-
```cpp
|
|
862
|
-
// Platform detection
|
|
863
|
-
#if defined(_WIN32) || defined(_WIN64)
|
|
864
|
-
#define PLATFORM_WINDOWS
|
|
865
|
-
#elif defined(__linux__)
|
|
866
|
-
#define PLATFORM_LINUX
|
|
867
|
-
#elif defined(__APPLE__)
|
|
868
|
-
#define PLATFORM_MACOS
|
|
869
|
-
#endif
|
|
870
|
-
|
|
871
|
-
// Platform-specific includes
|
|
872
|
-
#ifdef PLATFORM_WINDOWS
|
|
873
|
-
#define WIN32_LEAN_AND_MEAN
|
|
874
|
-
#define NOMINMAX
|
|
875
|
-
#include <windows.h>
|
|
876
|
-
#include <winsock2.h>
|
|
877
|
-
#else
|
|
878
|
-
#include <unistd.h>
|
|
879
|
-
#include <sys/socket.h>
|
|
880
|
-
#include <netinet/in.h>
|
|
881
|
-
#include <pthread.h>
|
|
882
|
-
#endif
|
|
883
|
-
|
|
884
|
-
// Sleep abstraction
|
|
885
|
-
inline void sleep_ms(int ms) {
|
|
886
|
-
#ifdef PLATFORM_WINDOWS
|
|
887
|
-
Sleep(ms);
|
|
888
|
-
#else
|
|
889
|
-
usleep(ms * 1000);
|
|
890
|
-
#endif
|
|
891
|
-
}
|
|
892
|
-
```
|
|
160
|
+
- **Platform Headers** — Windows/Linux-specific includes, macro conflicts, cross-platform
|
|
161
|
+
→ See [references/platform-headers.md](references/platform-headers.md)
|
|
893
162
|
|
|
894
163
|
---
|
|
895
164
|
|