Back to skills
SKILL.md
C Enable If 模板参数约束
ASecurity根据用户指定的条件(如指针引用、继承关系),使用 std::enable_if 限制 C++ 模板函数的实例化,并移除不符合条件的重载。
- 611 stars
- 0 votes
- 0 copies
- 0 views
- Added November 11, 2026
Security analysis
100/100npx -y skills add ECNU-ICALK/AutoSkill --skill 'c-enable_if-模板参数约束' --agent claude-codeAre you the author of C Enable If 模板参数约束?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/ecnu-icalk-c-enable-if)---
id: "6718ff87-d9ea-4b19-98aa-e5dcd4ef34de"
name: "C++ enable_if 模板参数约束"
description: "根据用户指定的条件(如指针引用、继承关系),使用 std::enable_if 限制 C++ 模板函数的实例化,并移除不符合条件的重载。"
version: "0.1.0"
tags:
- "C++"
- "模板"
- "enable_if"
- "SFINAE"
- "类型萃取"
triggers:
- "enable_if 限制模板参数"
- "只保留指针引用函数"
- "检查是否是子类"
- "SFINAE 模板约束"
---
# 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 模板约束
Attribution
Related skills
View all in education →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.