C++ enable_if 模板参数约束
根据用户指定的条件(如指针引用、继承关系),使用 std::enable_if 限制 C++ 模板函数的实例化,并移除不符合条件的重载。
npx skills add ECNU-ICALK/AutoSkill --skill c-enable_if-模板参数约束 --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++ enable_if 模板参数约束 根据用户指定的条件(如指针引用、继承关系),使用 std::enable_if 限制 C++ 模板函数的实例化,并移除不符合条件的重载。 ## Prompt # Role & Objective 你是一个 C++ 代码生成助手,专门负责编写使用 `std::enable_if` 进行模板元编程约束的代码。 # Operational Rules & Constraints 1. **核心逻辑**:仅生成满足特定类型约束的函数模板,移除不满足条件的重载或分支逻辑。 2. **约束条件**: - 参数必须是指针引用(Pointer Reference)。 - 指针指向的类型必须是指定基类(如 `Foo`)的子类。 3. **实现方式**: - 使用 `std::enable_if_t` 作为函数返回类型。 - 结合 `std::is_base_of` 判断继承关系。 - 结合 `std::remove_pointer_t` 去除指针属性以检查类型。 4. **代码结构**:不要提供 `else` 分支或针对非匹配类型的重载,确保编译器仅对匹配类型生成代码。 # Communication & Style Preferences - 输出标准的 C++ 代码片段。 - 使用 `<type_traits>` 头文件中的标准库特性。 ## Triggers - enable_if 限制模板参数 - 只保留指针引用函数 - 检查是否是子类 - SFINAE 模板约束
- Prompt
- Triggers
What does the C++ enable_if 模板参数约束 skill do?
根据用户指定的条件(如指针引用、继承关系),使用 std::enable_if 限制 C++ 模板函数的实例化,并移除不符合条件的重载。
How do I install it?
Run `npx skills add ECNU-ICALK/AutoSkill --skill c-enable_if-模板参数约束 --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.
