一键导入
m05-type-driven
Mastering C++ Type-Driven Design. Triggers: strong types, phantom types, type state pattern, builder pattern, invalid state unrepresentable.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Mastering C++ Type-Driven Design. Triggers: strong types, phantom types, type state pattern, builder pattern, invalid state unrepresentable.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when creating skills for C++20 standard library features, language constructs, remote third-party libraries, or local C++ projects. Keywords: create C++20 skill, create std skill C++, create concept skill, create local C++ skill, 创建 C++20 skill, 创建标准库技能, 创建 concept 技能, 本地库生成 skill, 动态 C++ skill, skill for ranges, skill for coroutines, skill for concepts, generate C++ skill from local path, C++20 技能, 从文档创建 skill, from docs create C++ skill
Mastering C++ Ownership: Move Semantics, RAII, and Reference Safety. Triggers: std::move, use-after-free, double-free, dangling pointer, copy elision, RVO, reference qualifiers.
Mastering C++ Smart Pointers: unique_ptr, shared_ptr, weak_ptr. Triggers: memory management, cycles, enable_shared_from_this, make_unique, make_shared, custom deleters.
Mastering C++ Const Correctness and Mutability. Triggers: const, mutable, logically const, bitwise const, data race, mutex, shared_mutex, thread safety.
Mastering C++ Polymorphism: Templates, Concepts, and Virtual Functions. Triggers: templates, concepts, vtable, CRTP, static polymorphism, dynamic polymorphism, SFINAE.
Mastering C++ Error Handling. Triggers: exceptions, try-catch, noexcept, std::expected, std::optional, error codes, assert, terminate.
| name | m05-type-driven |
| description | Mastering C++ Type-Driven Design. Triggers: strong types, phantom types, type state pattern, builder pattern, invalid state unrepresentable. |
Can I make this bug a compile error?
int for IDs, double for Money. Bad.struct UserId, struct Money. Good.Connection<OFF> vs Connection<ON>.| Issue | Design Question |
|---|---|
| Swapped arguments | Did you pass width to height? (Use Strong Types). |
| Invalid State | Did you call read() on closed file? (Use Type State). |
| Unit confusion | Did you mix Meters and Feet? (Use std::chrono style units). |
Is this int unique?
struct.struct UserId { int val; }; prevents process(OrderId).Does valid usage depend on order?
Builder::port() returns BuilderWithPort.Are units compatible?
Dist<Meters> + Dist<Feet>.Trace Up:
double calculate_trajectory(double dist) accepted any number.Dist<Meters> calculate(Dist<Meters> d). Compilation fails if you pass Feet.Trace Down:
File<Open> f = File<Closed>().open(); f.read();| Pattern | Cost | Use When |
|---|---|---|
| Struct Wrapper | Zero | Distinct IDs, coordinates. |
| Enum Class | Zero | Type-safe flags (no implicit int conv). |
| Phantom Type | Zero | Tracking state without storage. |
| User Literal | Zero | 10_m, 50_s. |