@nockdev/awf 6.2.6 → 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 +2 -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
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
## ⚡ Header Optimization (CRITICAL Best Practice)
|
|
2
|
+
|
|
3
|
+
> **GOAL**: Minimize includes in `.h` files → Faster compilation, less coupling
|
|
4
|
+
|
|
5
|
+
### 1. Forward Declarations (Prefer over #include in headers)
|
|
6
|
+
|
|
7
|
+
```cpp
|
|
8
|
+
// ❌ BAD: Heavy includes in header file
|
|
9
|
+
// user.h
|
|
10
|
+
#include <string> // Full include
|
|
11
|
+
#include <vector> // Full include
|
|
12
|
+
#include <memory> // Full include
|
|
13
|
+
#include "database.h" // Heavy include!
|
|
14
|
+
#include "logger.h" // Heavy include!
|
|
15
|
+
|
|
16
|
+
class User {
|
|
17
|
+
std::unique_ptr<Database> db_; // Requires full Database type
|
|
18
|
+
std::string name_;
|
|
19
|
+
std::vector<int> orders_;
|
|
20
|
+
};
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```cpp
|
|
24
|
+
// ✅ GOOD: Forward declarations + minimal includes
|
|
25
|
+
// user.h
|
|
26
|
+
#include <string> // Required (used directly)
|
|
27
|
+
#include <memory> // Required for unique_ptr
|
|
28
|
+
|
|
29
|
+
class Database; // Forward declaration only!
|
|
30
|
+
class Logger; // Forward declaration only!
|
|
31
|
+
|
|
32
|
+
class User {
|
|
33
|
+
std::unique_ptr<Database> db_; // OK with incomplete type
|
|
34
|
+
std::string name_;
|
|
35
|
+
std::vector<int>* orders_; // Pointer = OK with forward decl
|
|
36
|
+
};
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```cpp
|
|
40
|
+
// user.cpp - Include the full headers here
|
|
41
|
+
#include "user.h" // Own header FIRST
|
|
42
|
+
#include <vector> // Now we need full definition
|
|
43
|
+
#include "database.h" // Full include in implementation
|
|
44
|
+
#include "logger.h" // Full include in implementation
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 2. When Forward Declaration Works
|
|
48
|
+
|
|
49
|
+
| Scenario | Forward Decl OK? | Notes |
|
|
50
|
+
| ----------------------------- | ---------------------- | ----------------------------- |
|
|
51
|
+
| Pointer to class (`T*`) | ✅ Yes | Size known (pointer size) |
|
|
52
|
+
| Reference to class (`T&`) | ✅ Yes | Size known |
|
|
53
|
+
| `std::unique_ptr<T>` | ⚠️ Partial | Need full type for destructor |
|
|
54
|
+
| `std::shared_ptr<T>` | ✅ Yes | Incomplete type allowed |
|
|
55
|
+
| Class member (`T member`) | ❌ No | Size required |
|
|
56
|
+
| Inheritance (`class A : B`) | ❌ No | Full type required |
|
|
57
|
+
| Template parameter | ⚠️ Depends | Often needs full type |
|
|
58
|
+
| Function parameter (`f(T x)`) | ⚠️ Declaration only | Implementation needs full |
|
|
59
|
+
| Function return (`T f()`) | ⚠️ Declaration only | Implementation needs full |
|
|
60
|
+
|
|
61
|
+
### 3. PIMPL Idiom (Pointer to Implementation)
|
|
62
|
+
|
|
63
|
+
> **Purpose**: Hide implementation, reduce compilation dependencies, ABI stability
|
|
64
|
+
|
|
65
|
+
```cpp
|
|
66
|
+
// widget.h - PUBLIC HEADER (minimal includes!)
|
|
67
|
+
#pragma once
|
|
68
|
+
#include <memory> // Only for unique_ptr
|
|
69
|
+
|
|
70
|
+
class Widget {
|
|
71
|
+
public:
|
|
72
|
+
Widget();
|
|
73
|
+
~Widget(); // Must be declared (impl needs complete type)
|
|
74
|
+
|
|
75
|
+
// Move operations
|
|
76
|
+
Widget(Widget&& other) noexcept;
|
|
77
|
+
Widget& operator=(Widget&& other) noexcept;
|
|
78
|
+
|
|
79
|
+
// Deleted copy (or implement in .cpp)
|
|
80
|
+
Widget(const Widget&) = delete;
|
|
81
|
+
Widget& operator=(const Widget&) = delete;
|
|
82
|
+
|
|
83
|
+
void doSomething();
|
|
84
|
+
int getValue() const;
|
|
85
|
+
|
|
86
|
+
private:
|
|
87
|
+
struct Impl; // Forward declaration
|
|
88
|
+
std::unique_ptr<Impl> pimpl_; // Opaque pointer
|
|
89
|
+
};
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
```cpp
|
|
93
|
+
// widget.cpp - IMPLEMENTATION (heavy includes here)
|
|
94
|
+
#include "widget.h"
|
|
95
|
+
#include <string> // Heavy STL
|
|
96
|
+
#include <vector> // Heavy STL
|
|
97
|
+
#include <unordered_map> // Heavy STL
|
|
98
|
+
#include "database.h" // Heavy dependency
|
|
99
|
+
#include "network_client.h" // Heavy dependency
|
|
100
|
+
#include <windows.h> // Platform header - ONLY in .cpp!
|
|
101
|
+
|
|
102
|
+
struct Widget::Impl {
|
|
103
|
+
std::string name;
|
|
104
|
+
std::vector<int> data;
|
|
105
|
+
std::unordered_map<int, std::string> cache;
|
|
106
|
+
std::unique_ptr<Database> db;
|
|
107
|
+
NetworkClient client;
|
|
108
|
+
HANDLE winHandle; // Windows-specific - hidden from header
|
|
109
|
+
|
|
110
|
+
void internalHelper() { /* ... */ }
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
Widget::Widget() : pimpl_(std::make_unique<Impl>()) {}
|
|
114
|
+
|
|
115
|
+
Widget::~Widget() = default; // Must be in .cpp where Impl is complete
|
|
116
|
+
|
|
117
|
+
Widget::Widget(Widget&& other) noexcept = default;
|
|
118
|
+
Widget& Widget::operator=(Widget&& other) noexcept = default;
|
|
119
|
+
|
|
120
|
+
void Widget::doSomething() {
|
|
121
|
+
pimpl_->internalHelper();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
int Widget::getValue() const {
|
|
125
|
+
return static_cast<int>(pimpl_->data.size());
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### 4. Dangerous Headers (NEVER include in .h files)
|
|
130
|
+
|
|
131
|
+
| Header | Problem | Solution |
|
|
132
|
+
| ----------------------- | ------------------------------------ | ----------------------- |
|
|
133
|
+
| `<windows.h>` | 15k+ lines, macros pollute namespace | PIMPL or forward decl |
|
|
134
|
+
| `<winsock2.h>` | Heavy, conflicts | PIMPL only in .cpp |
|
|
135
|
+
| `<algorithm>` | 10k+ lines | Forward decl iterators |
|
|
136
|
+
| `<iostream>` | Heavy, static init | Forward declare streams |
|
|
137
|
+
| `<regex>` | Extremely heavy | PIMPL |
|
|
138
|
+
| `<thread>` | Platform headers | PIMPL |
|
|
139
|
+
| `<filesystem>` | Heavy | PIMPL |
|
|
140
|
+
| Project's large headers | Compilation cascade | Forward decl |
|
|
141
|
+
|
|
142
|
+
### 5. Include-What-You-Use (IWYU)
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
# Run IWYU on single file
|
|
146
|
+
include-what-you-use -Xiwyu --mapping_file=iwyu.imp myfile.cpp
|
|
147
|
+
|
|
148
|
+
# CMake integration
|
|
149
|
+
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE include-what-you-use)
|
|
150
|
+
|
|
151
|
+
# IWYU pragmas
|
|
152
|
+
#include "heavy.h" // IWYU pragma: keep (prevent removal)
|
|
153
|
+
// IWYU pragma: no_include "deprecated.h" (prevent suggestion)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### 6. Precompiled Headers (PCH)
|
|
157
|
+
|
|
158
|
+
```cmake
|
|
159
|
+
# CMakeLists.txt - Modern PCH (CMake 3.16+)
|
|
160
|
+
target_precompile_headers(myapp PRIVATE
|
|
161
|
+
# STL headers (stable, include once)
|
|
162
|
+
<vector>
|
|
163
|
+
<string>
|
|
164
|
+
<memory>
|
|
165
|
+
<algorithm>
|
|
166
|
+
<unordered_map>
|
|
167
|
+
|
|
168
|
+
# Third-party (stable)
|
|
169
|
+
<fmt/core.h>
|
|
170
|
+
<spdlog/spdlog.h>
|
|
171
|
+
|
|
172
|
+
# Project stable headers
|
|
173
|
+
"common/types.h"
|
|
174
|
+
"common/constants.h"
|
|
175
|
+
)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### 7. C++20 Modules (Future-Proof)
|
|
179
|
+
|
|
180
|
+
```cpp
|
|
181
|
+
// math.cppm - Module interface
|
|
182
|
+
export module math;
|
|
183
|
+
|
|
184
|
+
export int add(int a, int b);
|
|
185
|
+
export int multiply(int a, int b);
|
|
186
|
+
|
|
187
|
+
// math.cpp - Module implementation
|
|
188
|
+
module math;
|
|
189
|
+
|
|
190
|
+
int add(int a, int b) { return a + b; }
|
|
191
|
+
int multiply(int a, int b) { return a * b; }
|
|
192
|
+
|
|
193
|
+
// main.cpp - Using module
|
|
194
|
+
import math; // Fast import, no re-parsing!
|
|
195
|
+
import std; // Import entire std library (C++23)
|
|
196
|
+
|
|
197
|
+
int main() {
|
|
198
|
+
return add(1, 2);
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### 8. Header Include Order (Best Practice)
|
|
203
|
+
|
|
204
|
+
```cpp
|
|
205
|
+
// myclass.cpp
|
|
206
|
+
|
|
207
|
+
// 1. OWN HEADER FIRST (validates self-containment)
|
|
208
|
+
#include "myclass.h"
|
|
209
|
+
|
|
210
|
+
// 2. C system headers
|
|
211
|
+
#include <cstdio>
|
|
212
|
+
#include <cstdlib>
|
|
213
|
+
|
|
214
|
+
// 3. C++ STL headers
|
|
215
|
+
#include <string>
|
|
216
|
+
#include <vector>
|
|
217
|
+
#include <algorithm>
|
|
218
|
+
|
|
219
|
+
// 4. Third-party library headers
|
|
220
|
+
#include <fmt/core.h>
|
|
221
|
+
#include <spdlog/spdlog.h>
|
|
222
|
+
#include <nlohmann/json.hpp>
|
|
223
|
+
|
|
224
|
+
// 5. Project headers (alphabetical)
|
|
225
|
+
#include "database/connection.h"
|
|
226
|
+
#include "utils/string_utils.h"
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
---
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
## 🧠 Memory Management
|
|
2
|
+
|
|
3
|
+
### Smart Pointers
|
|
4
|
+
|
|
5
|
+
```cpp
|
|
6
|
+
#include <memory>
|
|
7
|
+
|
|
8
|
+
// 📦 unique_ptr (exclusive ownership)
|
|
9
|
+
auto widget = std::make_unique<Widget>(config);
|
|
10
|
+
|
|
11
|
+
// 📦 shared_ptr (shared ownership)
|
|
12
|
+
auto resource = std::make_shared<Resource>();
|
|
13
|
+
auto copy = resource; // Reference count = 2
|
|
14
|
+
|
|
15
|
+
// 📦 weak_ptr (non-owning reference)
|
|
16
|
+
std::weak_ptr<Resource> weak = resource;
|
|
17
|
+
if (auto locked = weak.lock()) {
|
|
18
|
+
// Use locked safely
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// 📦 Custom deleter
|
|
22
|
+
auto file = std::unique_ptr<FILE, decltype(&fclose)>(
|
|
23
|
+
fopen("data.txt", "r"), fclose
|
|
24
|
+
);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Move Semantics
|
|
28
|
+
|
|
29
|
+
```cpp
|
|
30
|
+
class Buffer {
|
|
31
|
+
std::unique_ptr<uint8_t[]> data_;
|
|
32
|
+
size_t size_;
|
|
33
|
+
|
|
34
|
+
public:
|
|
35
|
+
// Move constructor
|
|
36
|
+
Buffer(Buffer&& other) noexcept
|
|
37
|
+
: data_(std::move(other.data_))
|
|
38
|
+
, size_(std::exchange(other.size_, 0)) {}
|
|
39
|
+
|
|
40
|
+
// Move assignment
|
|
41
|
+
Buffer& operator=(Buffer&& other) noexcept {
|
|
42
|
+
if (this != &other) {
|
|
43
|
+
data_ = std::move(other.data_);
|
|
44
|
+
size_ = std::exchange(other.size_, 0);
|
|
45
|
+
}
|
|
46
|
+
return *this;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## � Concurrency
|
|
54
|
+
|
|
55
|
+
### std::jthread (C++20)
|
|
56
|
+
|
|
57
|
+
```cpp
|
|
58
|
+
#include <thread>
|
|
59
|
+
#include <stop_token>
|
|
60
|
+
|
|
61
|
+
std::jthread worker([](std::stop_token stoken) {
|
|
62
|
+
while (!stoken.stop_requested()) {
|
|
63
|
+
// Do work
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Automatic join on destruction
|
|
68
|
+
// Can request stop: worker.request_stop();
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### std::atomic
|
|
72
|
+
|
|
73
|
+
```cpp
|
|
74
|
+
#include <atomic>
|
|
75
|
+
|
|
76
|
+
std::atomic<int> counter{0};
|
|
77
|
+
|
|
78
|
+
void increment() {
|
|
79
|
+
counter.fetch_add(1, std::memory_order_relaxed);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
int get() {
|
|
83
|
+
return counter.load(std::memory_order_acquire);
|
|
84
|
+
}
|
|
85
|
+
```
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
## 🔧 Modern C++ Features
|
|
2
|
+
|
|
3
|
+
### C++20: Concepts
|
|
4
|
+
|
|
5
|
+
```cpp
|
|
6
|
+
#include <concepts>
|
|
7
|
+
|
|
8
|
+
// Define concept
|
|
9
|
+
template<typename T>
|
|
10
|
+
concept Numeric = std::integral<T> || std::floating_point<T>;
|
|
11
|
+
|
|
12
|
+
// Use concept
|
|
13
|
+
template<Numeric T>
|
|
14
|
+
T add(T a, T b) {
|
|
15
|
+
return a + b;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Requires clause
|
|
19
|
+
template<typename T>
|
|
20
|
+
requires std::copyable<T>
|
|
21
|
+
void process(T value) {
|
|
22
|
+
// ...
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### C++20: Ranges
|
|
27
|
+
|
|
28
|
+
```cpp
|
|
29
|
+
#include <ranges>
|
|
30
|
+
#include <vector>
|
|
31
|
+
#include <algorithm>
|
|
32
|
+
|
|
33
|
+
std::vector<int> nums{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
|
34
|
+
|
|
35
|
+
// 📦 Ranges with views (lazy evaluation)
|
|
36
|
+
auto result = nums
|
|
37
|
+
| std::views::filter([](int n) { return n % 2 == 0; })
|
|
38
|
+
| std::views::transform([](int n) { return n * 2; })
|
|
39
|
+
| std::views::take(3);
|
|
40
|
+
|
|
41
|
+
for (int n : result) {
|
|
42
|
+
std::cout << n << ' '; // 4 8 12
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 📦 Range algorithms
|
|
46
|
+
std::ranges::sort(nums);
|
|
47
|
+
auto found = std::ranges::find(nums, 5);
|
|
48
|
+
bool all_positive = std::ranges::all_of(nums, [](int n) { return n > 0; });
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### C++20: std::format
|
|
52
|
+
|
|
53
|
+
```cpp
|
|
54
|
+
#include <format>
|
|
55
|
+
#include <string>
|
|
56
|
+
|
|
57
|
+
std::string msg = std::format("User {}: {}", id, name);
|
|
58
|
+
std::string formatted = std::format("{:0>8}", 42); // "00000042"
|
|
59
|
+
std::string hex = std::format("{:#x}", 255); // "0xff"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### C++23: std::expected
|
|
63
|
+
|
|
64
|
+
```cpp
|
|
65
|
+
#include <expected>
|
|
66
|
+
#include <string>
|
|
67
|
+
|
|
68
|
+
enum class Error { NotFound, Invalid };
|
|
69
|
+
|
|
70
|
+
std::expected<User, Error> findUser(int id) {
|
|
71
|
+
if (auto it = users.find(id); it != users.end()) {
|
|
72
|
+
return it->second;
|
|
73
|
+
}
|
|
74
|
+
return std::unexpected(Error::NotFound);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Usage
|
|
78
|
+
auto result = findUser(42);
|
|
79
|
+
if (result) {
|
|
80
|
+
std::cout << result->name;
|
|
81
|
+
} else {
|
|
82
|
+
std::cerr << "Error: " << static_cast<int>(result.error());
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Or with transform
|
|
86
|
+
result.transform([](const User& u) { return u.name; })
|
|
87
|
+
.or_else([](Error e) { return "Unknown"; });
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### C++23: std::print
|
|
91
|
+
|
|
92
|
+
```cpp
|
|
93
|
+
#include <print>
|
|
94
|
+
|
|
95
|
+
// Type-safe printf replacement
|
|
96
|
+
std::print("Hello, {}!\n", name);
|
|
97
|
+
std::println("User {}: score = {}", id, score); // with newline
|
|
98
|
+
|
|
99
|
+
// Formatted output
|
|
100
|
+
std::print("{:>10} | {:>5}\n", "Name", "Score");
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### C++23: Modules
|
|
104
|
+
|
|
105
|
+
```cpp
|
|
106
|
+
// mymodule.cppm
|
|
107
|
+
export module mymodule;
|
|
108
|
+
|
|
109
|
+
export class Widget {
|
|
110
|
+
public:
|
|
111
|
+
void process();
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export void helper();
|
|
115
|
+
|
|
116
|
+
// main.cpp
|
|
117
|
+
import mymodule; // Import custom module
|
|
118
|
+
import std; // Import entire standard library!
|
|
119
|
+
|
|
120
|
+
int main() {
|
|
121
|
+
Widget w;
|
|
122
|
+
w.process();
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
## ⚠️ Platform-Specific Headers (CRITICAL)
|
|
2
|
+
|
|
3
|
+
### Windows Headers Conflicts
|
|
4
|
+
|
|
5
|
+
> **CRITICAL**: Windows headers have many conflicts. Follow this order exactly!
|
|
6
|
+
|
|
7
|
+
#### 1. Include Order (winsock2.h BEFORE windows.h)
|
|
8
|
+
|
|
9
|
+
```cpp
|
|
10
|
+
// ✅ CORRECT ORDER - winsock2.h MUST come before windows.h
|
|
11
|
+
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff
|
|
12
|
+
#define NOMINMAX // Prevent min/max macros
|
|
13
|
+
#define STRICT // Enable strict type checking
|
|
14
|
+
#define UNICODE // Use Unicode APIs
|
|
15
|
+
#define _UNICODE
|
|
16
|
+
|
|
17
|
+
#include <winsock2.h> // 1st - Winsock 2.0
|
|
18
|
+
#include <ws2tcpip.h> // 2nd - TCP/IP extensions
|
|
19
|
+
#include <windows.h> // 3rd - Windows API
|
|
20
|
+
|
|
21
|
+
// ❌ WRONG - causes redefinition errors!
|
|
22
|
+
#include <windows.h> // includes winsock.h (1.1)
|
|
23
|
+
#include <winsock2.h> // conflicts with winsock.h!
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
#### 2. Essential Macros (Define BEFORE any Windows includes)
|
|
27
|
+
|
|
28
|
+
```cpp
|
|
29
|
+
// pch.h or stdafx.h - Put at TOP of precompiled header
|
|
30
|
+
#ifndef WIN32_LEAN_AND_MEAN
|
|
31
|
+
#define WIN32_LEAN_AND_MEAN // Exclude: Cryptography, DDE, RPC, Shell, Winsock 1.1
|
|
32
|
+
#endif
|
|
33
|
+
|
|
34
|
+
#ifndef NOMINMAX
|
|
35
|
+
#define NOMINMAX // Prevent Windows min/max macros
|
|
36
|
+
#endif // Allows std::min, std::max to work
|
|
37
|
+
|
|
38
|
+
#ifndef STRICT
|
|
39
|
+
#define STRICT // Strict type checking for handles
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
// Now safe to include Windows headers
|
|
43
|
+
#include <windows.h>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
#### 3. min/max Macro Conflicts
|
|
47
|
+
|
|
48
|
+
```cpp
|
|
49
|
+
// ❌ Problem: Windows defines min/max as macros
|
|
50
|
+
#include <windows.h>
|
|
51
|
+
#include <algorithm>
|
|
52
|
+
int x = std::min(a, b); // ERROR: macro expansion!
|
|
53
|
+
|
|
54
|
+
// ✅ Solution 1: Use NOMINMAX (recommended)
|
|
55
|
+
#define NOMINMAX
|
|
56
|
+
#include <windows.h>
|
|
57
|
+
#include <algorithm>
|
|
58
|
+
int x = std::min(a, b); // Works!
|
|
59
|
+
|
|
60
|
+
// ✅ Solution 2: Parentheses workaround
|
|
61
|
+
int x = (std::min)(a, b); // Prevents macro expansion
|
|
62
|
+
|
|
63
|
+
// ✅ Solution 3: #undef after include
|
|
64
|
+
#include <windows.h>
|
|
65
|
+
#undef min
|
|
66
|
+
#undef max
|
|
67
|
+
#include <algorithm>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
#### 4. WIN32_LEAN_AND_MEAN Exclusions
|
|
71
|
+
|
|
72
|
+
```cpp
|
|
73
|
+
// WIN32_LEAN_AND_MEAN excludes these - include manually if needed:
|
|
74
|
+
#define WIN32_LEAN_AND_MEAN
|
|
75
|
+
#include <windows.h>
|
|
76
|
+
|
|
77
|
+
// If you need these, include AFTER windows.h:
|
|
78
|
+
#include <shellapi.h> // Shell API
|
|
79
|
+
#include <mmsystem.h> // Multimedia
|
|
80
|
+
#include <wincrypt.h> // Cryptography
|
|
81
|
+
#include <commdlg.h> // Common dialogs
|
|
82
|
+
#include <dde.h> // DDE
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Windows Headers Quick Reference
|
|
86
|
+
|
|
87
|
+
| Header | Purpose | Notes |
|
|
88
|
+
| -------------- | -------------------- | ----------------------------- |
|
|
89
|
+
| `<windows.h>` | Core Windows API | Always use with LEAN_AND_MEAN |
|
|
90
|
+
| `<winsock2.h>` | Sockets (Winsock 2) | MUST include BEFORE windows.h |
|
|
91
|
+
| `<ws2tcpip.h>` | TCP/IP, getaddrinfo | Include after winsock2.h |
|
|
92
|
+
| `<windowsx.h>` | Message crackers | Helper macros |
|
|
93
|
+
| `<commctrl.h>` | Common controls | ListView, TreeView, etc. |
|
|
94
|
+
| `<shlobj.h>` | Shell interface | Folder browser, etc. |
|
|
95
|
+
| `<shobjidl.h>` | Shell COM interfaces | Modern file dialogs |
|
|
96
|
+
| `<tchar.h>` | TCHAR portability | Legacy, prefer wchar_t |
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
### Linux/POSIX Headers
|
|
101
|
+
|
|
102
|
+
#### 1. Define \_REENTRANT for Thread-Safe Functions
|
|
103
|
+
|
|
104
|
+
```cpp
|
|
105
|
+
// ✅ Define BEFORE any system headers
|
|
106
|
+
#define _REENTRANT // Thread-safe libc functions
|
|
107
|
+
#define _POSIX_C_SOURCE 200809L // POSIX.1-2008
|
|
108
|
+
|
|
109
|
+
#include <pthread.h>
|
|
110
|
+
#include <unistd.h>
|
|
111
|
+
#include <signal.h>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### 2. Signal Handling with Threads (Critical)
|
|
115
|
+
|
|
116
|
+
```cpp
|
|
117
|
+
#include <pthread.h>
|
|
118
|
+
#include <signal.h>
|
|
119
|
+
|
|
120
|
+
// ✅ Block signals in worker threads, handle in dedicated thread
|
|
121
|
+
int main() {
|
|
122
|
+
sigset_t set;
|
|
123
|
+
sigemptyset(&set);
|
|
124
|
+
sigaddset(&set, SIGINT);
|
|
125
|
+
sigaddset(&set, SIGTERM);
|
|
126
|
+
|
|
127
|
+
// Block signals in main thread (inherited by child threads)
|
|
128
|
+
pthread_sigmask(SIG_BLOCK, &set, NULL);
|
|
129
|
+
|
|
130
|
+
// Create worker threads (they inherit blocked signals)
|
|
131
|
+
pthread_t worker;
|
|
132
|
+
pthread_create(&worker, NULL, worker_func, NULL);
|
|
133
|
+
|
|
134
|
+
// Handle signals in main thread with sigwait
|
|
135
|
+
int sig;
|
|
136
|
+
while (sigwait(&set, &sig) == 0) {
|
|
137
|
+
if (sig == SIGINT || sig == SIGTERM) {
|
|
138
|
+
// Clean shutdown
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
pthread_join(worker, NULL);
|
|
144
|
+
return 0;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ❌ AVOID: Signal handlers with threads (race conditions!)
|
|
148
|
+
// Use sigwait() or signalfd() instead
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
#### 3. Common POSIX Headers
|
|
152
|
+
|
|
153
|
+
| Header | Purpose | Key Functions |
|
|
154
|
+
| ---------------- | ---------------- | ----------------------------------- |
|
|
155
|
+
| `<unistd.h>` | POSIX API | read, write, close, fork, exec |
|
|
156
|
+
| `<pthread.h>` | Threads | pthread*create, pthread_mutex*\* |
|
|
157
|
+
| `<signal.h>` | Signals | sigaction, sigwait, pthread_sigmask |
|
|
158
|
+
| `<fcntl.h>` | File control | open, fcntl, O\_\* flags |
|
|
159
|
+
| `<sys/types.h>` | Type definitions | pid_t, size_t, ssize_t |
|
|
160
|
+
| `<sys/socket.h>` | Sockets | socket, bind, listen, accept |
|
|
161
|
+
| `<netinet/in.h>` | Internet addr | sockaddr_in, htons, ntohs |
|
|
162
|
+
| `<arpa/inet.h>` | IP conversion | inet_pton, inet_ntop |
|
|
163
|
+
| `<sys/stat.h>` | File status | stat, fstat, mkdir |
|
|
164
|
+
| `<sys/mman.h>` | Memory mapping | mmap, munmap, mprotect |
|
|
165
|
+
| `<dlfcn.h>` | Dynamic loading | dlopen, dlsym, dlclose |
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
### Cross-Platform Patterns
|
|
170
|
+
|
|
171
|
+
```cpp
|
|
172
|
+
// Platform detection
|
|
173
|
+
#if defined(_WIN32) || defined(_WIN64)
|
|
174
|
+
#define PLATFORM_WINDOWS
|
|
175
|
+
#elif defined(__linux__)
|
|
176
|
+
#define PLATFORM_LINUX
|
|
177
|
+
#elif defined(__APPLE__)
|
|
178
|
+
#define PLATFORM_MACOS
|
|
179
|
+
#endif
|
|
180
|
+
|
|
181
|
+
// Platform-specific includes
|
|
182
|
+
#ifdef PLATFORM_WINDOWS
|
|
183
|
+
#define WIN32_LEAN_AND_MEAN
|
|
184
|
+
#define NOMINMAX
|
|
185
|
+
#include <windows.h>
|
|
186
|
+
#include <winsock2.h>
|
|
187
|
+
#else
|
|
188
|
+
#include <unistd.h>
|
|
189
|
+
#include <sys/socket.h>
|
|
190
|
+
#include <netinet/in.h>
|
|
191
|
+
#include <pthread.h>
|
|
192
|
+
#endif
|
|
193
|
+
|
|
194
|
+
// Sleep abstraction
|
|
195
|
+
inline void sleep_ms(int ms) {
|
|
196
|
+
#ifdef PLATFORM_WINDOWS
|
|
197
|
+
Sleep(ms);
|
|
198
|
+
#else
|
|
199
|
+
usleep(ms * 1000);
|
|
200
|
+
#endif
|
|
201
|
+
}
|
|
202
|
+
```
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
## 📚 STL Containers Reference
|
|
2
|
+
|
|
3
|
+
### Sequence Containers
|
|
4
|
+
|
|
5
|
+
| Container | Access | Insert/Delete | Use Case |
|
|
6
|
+
| ---------------------- | ------ | ------------------ | ------------------- |
|
|
7
|
+
| `std::vector<T>` | O(1) | O(1) amortized end | Dynamic array |
|
|
8
|
+
| `std::deque<T>` | O(1) | O(1) both ends | Double-ended queue |
|
|
9
|
+
| `std::list<T>` | O(n) | O(1) anywhere | Frequent insertions |
|
|
10
|
+
| `std::array<T,N>` | O(1) | Fixed | Compile-time size |
|
|
11
|
+
| `std::forward_list<T>` | O(n) | O(1) | Singly linked |
|
|
12
|
+
|
|
13
|
+
### Associative Containers
|
|
14
|
+
|
|
15
|
+
| Container | Access | Insert | Ordered | Use Case |
|
|
16
|
+
| ------------------------- | -------- | -------- | ------- | ---------------- |
|
|
17
|
+
| `std::map<K,V>` | O(log n) | O(log n) | Yes | Key-value sorted |
|
|
18
|
+
| `std::set<T>` | O(log n) | O(log n) | Yes | Unique sorted |
|
|
19
|
+
| `std::multimap<K,V>` | O(log n) | O(log n) | Yes | Multiple values |
|
|
20
|
+
| `std::unordered_map<K,V>` | O(1) avg | O(1) avg | No | Fast lookups |
|
|
21
|
+
| `std::unordered_set<T>` | O(1) avg | O(1) avg | No | Fast membership |
|
|
22
|
+
|
|
23
|
+
### Container Usage
|
|
24
|
+
|
|
25
|
+
```cpp
|
|
26
|
+
#include <vector>
|
|
27
|
+
#include <map>
|
|
28
|
+
#include <unordered_map>
|
|
29
|
+
#include <array>
|
|
30
|
+
|
|
31
|
+
// 📦 Vector with reserve
|
|
32
|
+
std::vector<int> nums;
|
|
33
|
+
nums.reserve(1000); // Pre-allocate
|
|
34
|
+
nums.push_back(42);
|
|
35
|
+
nums.emplace_back(100);
|
|
36
|
+
|
|
37
|
+
// 📦 Range-based for
|
|
38
|
+
for (const auto& num : nums) {
|
|
39
|
+
std::cout << num << '\n';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 📦 Map with structured bindings
|
|
43
|
+
std::map<std::string, int> scores{{"Alice", 100}, {"Bob", 85}};
|
|
44
|
+
for (const auto& [name, score] : scores) {
|
|
45
|
+
std::cout << name << ": " << score << '\n';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 📦 Unordered map for O(1) lookups
|
|
49
|
+
std::unordered_map<int, std::string> idToName;
|
|
50
|
+
idToName[1] = "John";
|
|
51
|
+
if (auto it = idToName.find(1); it != idToName.end()) {
|
|
52
|
+
std::cout << it->second << '\n';
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// 📦 Fixed-size array
|
|
56
|
+
std::array<int, 5> arr{1, 2, 3, 4, 5};
|
|
57
|
+
```
|