cpp

Write modern C++ with RAII, smart pointers, and STL. Use for C++ development, memory safety, or performance optimization.

htlin222/dotfiles130 installsMITSynced Aug 26

Works with

Claude CodeCursorCodex CLIGitHub CopilotGemini CLI
---
name: cpp
description: Write modern C++ with RAII, smart pointers, and STL. Use for C++ development, memory safety, or performance optimization.
license: MIT
---

# C++ Development

Write safe, performant modern C++ code.

## When to Use

- Writing C++ code
- Memory management issues
- Template metaprogramming
- Performance optimization
- Legacy C++ modernization

## Modern C++ Patterns

### Smart Pointers

```cpp
// Unique ownership
auto ptr = std::make_unique<Resource>();
process(std::move(ptr));

// Shared ownership
auto shared = std::make_shared<Resource>();
auto copy = shared;  // Reference count: 2

// Weak reference (no ownership)
std::weak_ptr<Resource> weak = shared;
if (auto locked = weak.lock()) {
    // Use locked
}
```

### RAII

```cpp
class FileHandle {
    FILE* handle_;
public:
    explicit FileHandle(const char* path)
        : handle_(fopen(path, "r")) {
        if (!handle_) throw std::runtime_error("Failed to open");
    }
    ~FileHandle() { if (handle_) fclose(handle_); }

    // Rule of 5
    FileHandle(const FileHandle&) = delete;
    FileHandle& operator=(const FileHandle&) = delete;
    FileHandle(FileHandle&& other) noexcept
        : handle_(std::exchange(other.handle_, nullptr)) {}
    FileHandle& operator=(FileHandle&& other) noexcept {
        std::swap(handle_, other.handle_);
        return *this;
    }
};
```

### Containers and Algorithms

```cpp
std::vector<int> nums = {3, 1, 4, 1, 5};

// Prefer algorithms over raw loops
std::sort(nums.begin(), nums.end());

auto it = std::find_if(nums.begin(), nums.end(),
    [](int n) { return n > 3; });

// Range-based for
for (const auto& num : nums) {
    std::cout << num << '\n';
}

// Structured bindings (C++17)
std::map<std::string, int> scores;
for (const auto& [name, score] : scores) {
    std::cout << name << ": " << score << '\n';
}
```

### Templates

```cpp
// Concepts (C++20)
template<typename T>
concept Numeric = std::integral<T> || std::floating_point<T>;

template<Numeric T>
T sum(const std::vector<T>& values) {
    return std::accumulate(values.begin(), values.end(), T{});
}

// SFINAE (pre-C++20)
template<typename T,
    typename = std::enable_if_t<std::is_arithmetic_v<T>>>
T multiply(T a, T b) { return a * b; }
```

## Best Practices

- Prefer `const` and `constexpr`
- Use smart pointers over raw pointers
- Follow Rule of 0/5
- Prefer STL algorithms
- Use `std::string_view` for read-only strings
- Enable warnings: `-Wall -Wextra -Wpedantic`

## Common Issues

| Issue           | Symptom            | Fix                  |
| --------------- | ------------------ | -------------------- |
| Memory leak     | Growing memory     | Use smart pointers   |
| Dangling ptr    | Crash/UB           | Check lifetime       |
| Buffer overflow | Crash/security     | Use std::vector/span |
| Data race       | Inconsistent state | mutex/atomic         |

## Examples

**Input:** "Fix memory leak"
**Action:** Replace raw pointers with smart pointers, ensure RAII

**Input:** "Modernize this C++ code"
**Action:** Apply C++17/20 features, use STL, improve safety

More Performance skills

seo-audit

coreyhaines31/marketingskills

When the user wants to audit, review, or diagnose SEO issues on their site. Also use when the user mentions "SEO audit," "technical SEO," "why am I not ranking," "SEO issues," "on-page SEO," "meta tags review," "SEO health check," "my traffic dropped," "lost rankings," "not showing up in Google," "site isn't ranking," "Google update hit me," "page speed," "core web vitals," "crawl errors," or "indexing issues." Use this even if the user just says something vague like "my SEO is bad" or "help with SEO" — start with an audit. For building pages at scale to target keywords, see programmatic-seo. For adding structured data, see schema. For AI search optimization, see ai-seo.

195.1k

competitor-profiling

coreyhaines31/marketingskills

When the user wants to research, profile, or analyze competitors from their URLs. Also use when the user mentions 'competitor profile,' 'competitor research,' 'competitor analysis,' 'profile this competitor,' 'analyze competitor,' 'competitive intelligence,' 'competitor deep dive,' 'who are my competitors,' 'competitor landscape,' 'competitor dossier,' 'competitive audit,' or 'research these competitors.' Input is a list of competitor URLs. Output is structured competitor profile markdown files. For creating comparison/alternative pages from profiles, see competitors. For sales-specific battle cards, see sales-enablement.

65.8k

vercel-optimize

vercel-labs/agent-skills

Use for Vercel cost and performance optimization on deployed projects, especially Next.js, SvelteKit, Nuxt, and limited Astro apps. Collect Vercel metrics, usage, project config, and code scan results first; investigate only metric-backed candidates; produce ranked recommendations grounded in verified files and version-aware Vercel/framework docs. Trigger for Vercel bill reduction, slow or expensive routes, caching opportunities, Function Invocations, Build Minutes, Fast Data Transfer, Core Web Vitals, Bot Management, Fluid compute, or cost breakdown requests.

59.3k

← All Performance skills

Check your AI visibility

One URL in, a 0–100 score and the exact fixes out.

RUN THE CHECK

Browse all the tools

15 tools across six categories
13 of them never send your data anywhere

Free · No signup · No trial clock

SEE THE DIRECTORY