Skip to content
Back to skills

C Enable If 模板参数约束

ASecurity

根据用户指定的条件(如指针引用、继承关系),使用 std::enable_if 限制 C++ 模板函数的实例化,并移除不符合条件的重载。

  • 611 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
educationc++

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill 'c-enable_if-模板参数约束' --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of C Enable If 模板参数约束?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for C Enable If 模板参数约束
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-c-enable-if/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-c-enable-if)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
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

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in education →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.