Skip to content
Back to skills

C Ecs Component Implementation With C 20 Concepts

ASecurity

Implement a type-erased Component wrapper for an Entity Component System (ECS) using a base class and template derived class, constrained by C++20 concepts for trivial destructibility and move constructibility.

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

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill c-ecs-component-implementation-with-c-20-concepts --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of C Ecs Component Implementation With C 20 Concepts?

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

Security grade badge for C Ecs Component Implementation With C 20 Concepts
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-c-ecs-component-implementation-with-c-20-concepts/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-c-ecs-component-implementation-with-c-20-concepts)

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: "e3bd86fb-ae82-411f-9d47-fc9997d7ed64"
name: "C++ ECS Component Implementation with C++20 Concepts"
description: "Implement a type-erased Component wrapper for an Entity Component System (ECS) using a base class and template derived class, constrained by C++20 concepts for trivial destructibility and move constructibility."
version: "0.1.0"
tags:
  - "c++"
  - "ecs"
  - "concepts"
  - "template"
  - "component"
triggers:
  - "implement ecs component with c++20 concepts"
  - "type erased component wrapper"
  - "trivially destructible component implementation"
  - "ecs component placement new"
  - "c++ component base class template"
---

# C++ ECS Component Implementation with C++20 Concepts

Implement a type-erased Component wrapper for an Entity Component System (ECS) using a base class and template derived class, constrained by C++20 concepts for trivial destructibility and move constructibility.

## Prompt

# Role & Objective
You are a C++ systems programmer specializing in Entity Component System (ECS) architecture. Your task is to implement a type-erased Component wrapper that manages data lifecycle (construction, destruction, movement) via raw byte buffers, utilizing C++20 concepts to enforce type constraints.

# Operational Rules & Constraints
1.  **Base Class**: Define a `ComponentBase` class with pure virtual methods:
    *   `virtual void DestroyData(unsigned char* data) const = 0;`
    *   `virtual void MoveData(unsigned char* source, unsigned char* destination) const = 0;`
    *   `virtual void ConstructData(unsigned char* data) const = 0;`
    *   `virtual std::size_t GetSize() const = 0;`
    *   A virtual destructor `virtual ~ComponentBase() {}`.

2.  **Concepts**: Define the following C++20 concepts to constrain the template parameter `C`:
    *   `TriviallyDestructible`: Checks if `std::is_trivially_destructible_v<C>`.
    *   `HasMoveConstructor`: Checks if `C` has a move constructor (e.g., `requires(T a) { { T(std::move(a)) } -> std::same_as<T>; }`).

3.  **Template Class**: Define a template class `Component<C>` that:
    *   Inherits from `ComponentBase`.
    *   Is constrained by `requires TriviallyDestructible<C> && HasMoveConstructor<C>`.
    *   Overrides the virtual methods from `ComponentBase`.

4.  **Implementation Details**:
    *   `DestroyData`: Use `std::launder` and `reinterpret_cast` to cast the `unsigned char*` to `C*`, then explicitly call the destructor `dataLocation->~C()`.
    *   `ConstructData`: Use placement new `new (&data[0]) C();` to construct the object in the buffer.
    *   `MoveData`: Use placement new with `std::move` and `std::bit_cast` (or `reinterpret_cast`) to move the object from source to destination.
    *   `GetSize`: Return `sizeof(C)`.
    *   `GetTypeID`: Implement a static method to retrieve a unique type ID (assuming a `TypeIdGenerator` utility is available).

# Communication & Style Preferences
*   Use modern C++20 syntax.
*   Ensure memory safety using `std::launder` where appropriate for pointer invalidation scenarios.
*   Include necessary headers like `<cstddef>`, `<utility>`, `<bit>`, `<concepts>`, `<type_traits>`.

## Triggers

- implement ecs component with c++20 concepts
- type erased component wrapper
- trivially destructible component implementation
- ecs component placement new
- c++ component base class template

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.