- Home
- Skills
- Copyleftdev
- Sk1llz
- Alexandrescu
alexandrescu_skill
- Python
3
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill copyleftdev/sk1llz --skill alexandrescu- SKILL.md6.7 KB
Overview
This skill guides writing C++ code following Andrei Alexandrescu's Modern C++ Design principles, emphasizing policy-based design, template metaprogramming, and type-safe generic abstractions. It helps you design zero-overhead, highly configurable libraries where compile-time computation replaces runtime cost. Use it to make reusable, expressive, and efficient APIs that leverage the type system as a design tool.
How this skill works
The skill inspects design intent and suggests transforming runtime variability into compile-time policies and type-level computations. It recommends patterns like policy mixins, type lists, SFINAE-to-concepts migration, constexpr replacements for metafunctions, and static visitor/variant techniques. It also provides concrete idioms for enforcing template requirements, tagging dispatch, and safe compile-time checks.
When to use it
- Designing libraries that must be highly configurable with no vtable overhead
- When behavior variations are known at compile time and performance matters
- Replacing runtime branching with type-based dispatch or constexpr evaluation
- Building type-safe DSLs, compile-time registries, or heterogenous containers
- When you need clear, documentable template requirements and improved compile-time diagnostics
Best practices
- Prefer policy classes to runtime inheritance; mix policies by composition to avoid vtables
- Use static_assert and concepts to document and enforce template contracts
- Favor constexpr and consteval for computation where possible; use template metaprogramming only when necessary
- Make templates SFINAE-friendly or migrate to C++20 concepts for clearer overloads
- Use variadic templates and fold expressions instead of recursive type lists when available
- Measure compile-time cost; avoid unnecessary metaprogramming that slows builds without runtime benefit
Example use cases
- Configurable smart pointers built from creation, threading, and checking policy classes
- Compile-time registries and dispatch tables implemented with type lists or std::variant
- Conditional serialization that detects serialize() at compile time using traits or concepts
- Zero-overhead design patterns: static visitors, policy-based factories, and mixin composition
- Library APIs exposing customizable behavior via template parameters rather than runtime flags
FAQ
Avoid heavy template techniques when runtime polymorphism is required, when compile times are already critical, or when the team lacks template expertise.
Should I prefer concepts or SFINAE?
Use concepts (C++20) for clearer, faster-to-diagnose constraints. Use SFINAE only for older standards or specific backward-compatible overloads.