Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

cpp

/cpp

Pomaga pisać wydajny kod w nowoczesnym C++17/20/23: RAII, inteligentne wskaźniki, metaprogramowanie szablonów, semantyka przenoszenia i profilowanie pamięci w systemach natywnych.

Repozytorium
Agent-Skills ↗
Licencja
MIT
Ostatnia zmiana repozytorium
01.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
2
Przestarzałość

Brak sygnałów. Repozytorium zmienione 01.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Pomaga pisać wydajny kod w nowoczesnym C++17/20/23: RAII, inteligentne wskaźniki, metaprogramowanie szablonów, semantyka przenoszenia i profilowanie pamięci w systemach natywnych.

Oryginalny opis (EN)

Expert modern C++ (C++17/C++20/C++23) assistance covering RAII, smart pointers, template metaprogramming, STL containers, move semantics, and memory profiling. Use when developing high-performance native systems, low-latency algorithms, game engines, or embedded C++ codebases.

Jak działa

  1. When to Use
  2. Quick Start
  3. Core Concepts
  4. Common Patterns
  5. Best Practices
  6. Troubleshooting
  7. References
Sekcje z nagłówków SKILL.md, w oryginale · 182 linii, 650 słów
Podgląd SKILL.md
---
name: cpp
description: Expert modern C++ (C++17/C++20/C++23) assistance covering RAII, smart pointers, template metaprogramming, STL containers, move semantics, and memory profiling. Use when developing high-performance native systems, low-latency algorithms, game engines, or embedded C++ codebases.
---

# C++

Modern C++ development with smart pointers, RAII, and performance optimization.

## When to Use

- **High-Performance Game Engine & Graphics Development**: Unreal Engine, Vulkan, DirectX 12, and real-time ray tracing pipelines.
- **Low-Latency Quantitative Finance**: Writing high-frequency trading (HFT) engines with microsecond and nanosecond execution SLAs.
- **Systems & Database Infrastructure**: Building foundational engines (Chromium, ClickHouse, RocksDB, MongoDB).
- **Embedded & Autonomous Robotics**: ROS 2, computer vision pipelines, and self-driving automotive control systems.

## Quick Start

```cpp
#include <memory>
#include <string>
#include <vector>

class User {
public:
    User(std::string name, std::string email)
        : name_(std::move(name)), email_(std::move(email)) {}

    const std::string& name() const { return name_; }
    const std::string& email() const { return email_; }

private:
    std::string name_;
    std::string email_;
};

auto user = std::make_unique<User>("John", "john@example.com");
```

## Core Concepts

### RAII & Modern Smart Pointers (C++20/C++23)

Resource Acquisition Is Initialization (RAII) ties resource management directly to object lifetime:

```cpp
#include <iostream>
#include <memory>
#include <string>

class DatabaseConnection {
public:
    explicit DatabaseConnection(std::string conn_str) { std::cout << "Connected
"; }
    ~DatabaseConnection() { std::cout << "Closed connection safely
"; }
    void query(std::string sql) { std::cout << "Executing: " << sql << "
"; }
};

void execute_task() {
    // std::unique_ptr automatically destructs and frees resource when exiting scope
    auto conn = std::make_unique<DatabaseConnection>("postgres://localhost");
    conn->query("SELECT 1;");
} // conn goes out of scope here; destructor executes automatically
```

### Move Semantics & `std::move`

Transfers ownership of heavy heap resources without expensive deep memory copying:

```cpp
#include <vector>

std::vector<int> generate_data() {
    std::vector<int> large_vector(1'000'000, 42);
    return large_vector; // Move semantics (or RVO) avoids copying 1M integers
}
```

### C++20 Concepts & Constexpr Metaprogramming

Constrains template arguments with readable compile-time predicates:

```cpp
#include <concepts>

template<typename T>
concept Numeric = std::integral<T> || std::floating_point<T>;

template<Numeric T>
T calculate_mean(T a, T b) {
    return (a + b) / 2;
}
```

## Common Patterns

### Structured Bindings & Optional Returns

**Problem**: Returning multiple values safely without error-prone output pointers or boilerplate structs.

**Solution**:

```cpp
// Structured bindings (C++17)
auto [name, age] = std::make_pair("John", 25);
for (const auto& [key, value] : map) { /* ... */ }

// std::optional (C++17)
std::optional<User> findUser(int id) {
    if (exists) return User{...};
    return std::nullopt;
}

// Concepts (C++20)
template<typename T>
concept Numeric = std::is_arithmetic_v<T>;

template<Numeric T>
T add(T a, T b) { return a + b; }

// Ranges (C++20)
auto result = numbers
    | std::views::filter([](int n) { return n % 2 == 0; })
    | std::views::transform([](int n) { return n * 2; });
```

### RAII Pattern

**Problem**: Manual resource management risks leaks when exceptions interrupt execution flow.

**Solution**:

```cpp
class FileHandle {
public:
    explicit FileHandle(const char* path)
        : file_(std::fopen(path, "r")) {
        if (!file_) throw std::runtime_error("Cannot open file");
    }

    ~FileHandle() { if (file_) std::fclose(file_); }

    // Delete copy
    FileHandle(const FileHandle&) = delete;
    FileHandle& operator=(const FileHandle&) = delete;

    // Allow move
    FileHandle(FileHandle&& other) noexcept : file_(other.file_) {
        other.file_ = nullptr;
    }

private:
    FILE* file_;
};
```

## Best Practices

**Do**:

- Use Smart Pointers (`std::unique_ptr`, `std::shared_ptr`): Completely avoid raw `new` and `delete` expressions.
- Pass Heavy Read-Only Objects by `const&`: Prevent accidental copy overhead (`void process(const std::string& data)`).
- Use `std::string_view` and `std::span`: Reference continuous memory without copying or allocating heap strings.
- Enable Clang-Tidy & AddressSanitizer in CI: Enforce modern standards and catch memory leaks automatically.

**Don't**:

- Use C-style casts (`(int)x`): Use explicit C++ casts (`static_cast`, `reinterpret_cast`) to retain compiler safety checks.
- Return references to local stack variables: Returning local references causes dangling pointers and immediate undefined behavior.
- Use macros (`#define`) for constants: Use `constexpr` or `inline constexpr` variables.

## Troubleshooting

| Error              | Cause                           | Solution                       |
| ------------------ | ------------------------------- | ------------------------------ |
| Segmentation fault | Null pointer or buffer overflow | Use sanitizers, smart pointers |
| Memory leak        | Missing delete                  | Use RAII, smart pointers       |
| Undefined behavior | Dangling reference              | Ensure lifetime validity       |

## References

- [C++ Reference](https://en.cppreference.com/)
- [ISO C++ Guidelines](https://isocpp.github.io/CppCoreGuidelines/)

Wersje

RepozytoriumWynikLicencja
Ta strona · G1Joshi/Agent-Skills100MIT
ericrisco/rsc-harness100MIT
crazyguitar/cppcheatsheet100MIT
nimadorostkar/Claude-Skills-collection100MIT
lynricsy/hyperskills100MIT
claude-dev-suite/claude-dev-suite95MIT
dkbnull/hello-skill86MIT

Migawka bazy z 13.11.2026 · wersja paczki 065a4a6281cb (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 95cpp-smart-pointers
    Opisuje inteligentne wskaźniki C++ (unique_ptr, shared_ptr, weak_ptr) do automatycznego zarządzania pamięcią zgodnie z RAII.
  • 91cpp-smart-pointers
    Wspiera bezpieczne zarządzanie pamięcią w C++ przez unique_ptr, shared_ptr, weak_ptr i wzorce RAII.
  • 90cpp-pro
    Pisze idiomatyczny kod C++ z nowoczesnymi funkcjami, RAII, inteligentnymi wskaźnikami i algorytmami STL, także przy refaktoryzacji.
  • 95lang-cpp
    Pisze i przegląda nowoczesny C++ w standardach C++17, C++20 i C++23: RAII, inteligentne wskaźniki, semantykę przenoszenia i CMake.
  • 100cpp-expert
    Wspiera nowoczesny C++ (17/20/23): bezpieczny i wydajny kod, RAII, semantykę przeniesienia, szablony i koncepty oraz diagnozę niezdefiniowanego zachowania i problemów z pamięcią.
  • 100cpp-idioms
    Podaje idiomy nowoczesnego C++ (17/20/23): RAII, inteligentne wskaźniki, semantyka wartości, Rule of Zero i Five, koncepty i obsługa błędów przez std::expected, przy pisaniu, refaktoryzacji i przeglądzie.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.