agentsclimarketplace

C 通用容器模板支持 支持map unorderedmap及allocator

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt3.5_8/c-通用容器模板支持-支持map-unorderedmap及allocator

编写C++通用模板函数,支持std::map和std::unordered_map作为通用容器传入,处理const正确性,支持可选的allocator模板参数,且禁止在函数内部构建临时对象。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill c-通用容器模板支持-支持map-unorderedmap及allocator

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

2.4 KB, 574 tokens by cl100k_base, as published. Nobody here has run it

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::mapstd::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

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.