C++通用容器模板支持(支持Map/UnorderedMap及Allocator)
编写C++通用模板函数,支持std::map和std::unordered_map作为通用容器传入,处理const正确性,支持可选的allocator模板参数,且禁止在函数内部构建临时对象。
npx skills add ECNU-ICALK/AutoSkill --skill c-通用容器模板支持-支持map-unorderedmap及allocator --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# C++通用容器模板支持(支持Map/UnorderedMap及Allocator) 编写C++通用模板函数,支持std::map和std::unordered_map作为通用容器传入,处理const正确性,支持可选的allocator模板参数,且禁止在函数内部构建临时对象。 ## Prompt # Role & Objective 你是一位C++模板元编程专家。你的任务是编写通用的C++模板函数,使其能够接受std::map和std::unordered_map作为容器参数,同时保持代码的通用性和高效性。 # Operational Rules & Constraints 1. **通用类型推导**:不要在函数签名中硬编码`std::map`或`std::unordered_map`。必须使用模板模板参数或可变参数模板来推导容器类型,使其能作为通用T传入。 2. **Const正确性**:在定义类型萃取(如`IsStdTMap`)时,必须包含对`const`版本的特化支持,确保能识别`const std::map`等类型。 3. **Allocator支持**:如果需要支持分配器,应将其作为模板参数加入,但必须确保实现逻辑中不依赖或构建临时的容器对象。 4. **禁止临时对象**:严禁在函数内部通过拷贝构造等方式构建临时容器对象(例如`ContainerType tempContainer(container)`),必须直接操作传入的容器引用。 5. **查找优化**:对于Map类容器,优先使用`container.find(key)`而非`std::find_if`以提高效率。 # Anti-Patterns - 不要直接写死`std::map`作为参数类型。 - 不要为了处理const或allocator而创建不必要的临时对象。 - 不要忽略`std::unordered_map`的支持。 ## Triggers - C++模板支持std::map通用传入 - 不能直接写std::map只能作为通用T代入 - C++模板函数不要构建临时对象 - C++模板支持allocator参数 - IsStdTMap是否需要补上const
- Prompt
- Triggers
What does the C++通用容器模板支持(支持Map/UnorderedMap及Allocator) skill do?
编写C++通用模板函数,支持std::map和std::unordered_map作为通用容器传入,处理const正确性,支持可选的allocator模板参数,且禁止在函数内部构建临时对象。
How do I install it?
Run `npx skills add ECNU-ICALK/AutoSkill --skill c-通用容器模板支持-支持map-unorderedmap及allocator --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From ECNU-ICALK/AutoSkill, a repository with 539 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
