원클릭으로
cpp
C/C++, CMake, modern C++. Use when working on cpp tasks, related files, debugging, implementation, review, or verification workflows.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
C/C++, CMake, modern C++. Use when working on cpp tasks, related files, debugging, implementation, review, or verification workflows.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Framework-agnostic website security audit and authorized pentest methodology (OWASP, red-team attacker mindset, white-hat reporting). Use for web pentest, vulnerability assessment, attack-surface review, bug bounty prep, or security audit of any web stack.
Critical path identification, risk-adjusted effort sizing, complexity detection, and execution strategy selection. Use when scoping a task, deciding direct-vs-planned execution, breaking down large work, or assessing how many steps something really needs.
Multi-phase workflows, state machines, DAG task execution, checkpoint/resume, and saga patterns for complex multi-step or multi-session work. Use when a task spans 5+ steps, multiple files, multiple sessions, or has irreversible phases.
Understanding legacy and unfamiliar code, git blame/history analysis, dependency archaeology, and reconstructing intent behind existing code. Use when working in unfamiliar codebases, investigating "why was this written this way", or before changing code you didn't write.
Retry strategies, rollback protocols, circuit breakers for delegations, escalation chains, and failure budgets. Use when verification fails, a fix doesn't work, a sub-agent returns weak output, or you are stuck in a failure loop.
Production incident triage, rollback procedures, blast radius assessment, severity classification, and post-mortem templates. Use when production is down, a deploy broke something, users are impacted, or you need to stabilize before fixing root cause.
| name | cpp |
| description | C/C++, CMake, modern C++. Use when working on cpp tasks, related files, debugging, implementation, review, or verification workflows. |
Trigger this skill when:
.c, .cpp, .cc, .cxx, .h, .hpp, .hxxCMakeLists.txt, CMakePresets.json, Makefile, meson.build#include, std::, namespaceWhich standard to target?
+-- New project, full control? -> C++23 (modules, std::expected, std::print)
+-- Cross-platform library? -> C++20 (concepts, ranges, coroutines)
+-- Embedded / constrained? -> C++17 (optional, variant, string_view)
+-- Legacy codebase? -> Match existing, modernize incrementally
Which build system?
+-- Industry standard, broad support? -> CMake (with presets)
+-- Simpler syntax, faster? -> Meson
+-- Header-only library? -> CMake interface library
+-- Package management?
+-- System-level, binary caching? -> Conan 2
+-- Microsoft ecosystem, vcpkg.json manifest? -> vcpkg
+-- Single dependency? -> CMake FetchContent
How to handle errors?
+-- Expected failure (file not found, parse error)? -> std::expected<T, E>
+-- Precondition violation (programmer bug)? -> assert / contract (C++26)
+-- Resource acquisition? -> RAII (constructor throws or returns expected)
+-- Performance-critical hot path? -> Error codes (no exceptions)
+-- Library boundary? -> std::expected (no exception ABI issues)
#include <expected>
#include <print>
#include <ranges>
#include <string_view>
#include <generator> // C++23 std::generator
// std::expected — Result type (replaces exceptions for expected failures)
enum class ParseError { InvalidFormat, OutOfRange, Empty };
std::expected<int, ParseError> parse_int(std::string_view sv) {
if (sv.empty()) return std::unexpected(ParseError::Empty);
int result{};
auto [ptr, ec] = std::from_chars(sv.data(), sv.data() + sv.size(), result);
if (ec == std::errc::invalid_argument) return std::unexpected(ParseError::InvalidFormat);
if (ec == std::errc::result_out_of_range) return std::unexpected(ParseError::OutOfRange);
return result;
}
// Monadic operations on expected
auto process(std::string_view input) {
return parse_int(input)
.transform([](int n) { return n * 2; })
.transform_error([](ParseError e) { return format_error(e); });
}
// std::print — type-safe formatted output (replaces printf/iostream)
std::print("Hello, {}! You have {} messages.\n", user.name, count);
std::println("Point({}, {})", x, y); // with newline
// std::generator — stackless coroutine generator
std::generator<int> fibonacci() {
int a = 0, b = 1;
while (true) {
co_yield a;
auto next = a + b;
a = b;
b = next;
}
}
// Usage with ranges
for (auto n : fibonacci() | std::views::take(20)) {
std::println("{}", n);
}
// Deducing this (C++23) — CRTP replacement
struct Widget {
template<typename Self>
auto&& get_name(this Self&& self) {
return std::forward<Self>(self).name_;
}
private:
std::string name_;
};
// Multidimensional subscript operator
template<typename T>
class Matrix {
std::vector<T> data_;
size_t cols_;
public:
T& operator[](size_t row, size_t col) { return data_[row * cols_ + col]; }
const T& operator[](size_t row, size_t col) const { return data_[row * cols_ + col]; }
};
// math.cppm — module interface unit
export module math;
export namespace math {
constexpr double pi = 3.14159265358979323846;
template<std::floating_point T>
constexpr T clamp(T value, T lo, T hi) {
return std::max(lo, std::min(value, hi));
}
class Vector3 {
public:
float x{}, y{}, z{};
constexpr float length() const { return std::sqrt(x*x + y*y + z*z); }
constexpr Vector3 normalized() const;
};
}
// main.cpp — consuming module
import math;
import std; // C++23: import entire standard library
int main() {
auto v = math::Vector3{1.0f, 2.0f, 3.0f};
std::println("Length: {}", v.length());
}
#include <concepts>
#include <ranges>
// Custom concept — constrain template parameters
template<typename T>
concept Serializable = requires(T t, std::ostream& os) {
{ t.serialize(os) } -> std::same_as<void>;
{ T::deserialize(std::declval<std::istream&>()) } -> std::same_as<T>;
};
template<typename C>
concept Container = requires(C c) {
typename C::value_type;
{ c.begin() } -> std::input_iterator;
{ c.end() } -> std::sentinel_for<decltype(c.begin())>;
{ c.size() } -> std::convertible_to<size_t>;
};
// Ranges — composable, lazy pipelines
auto active_user_emails(const std::vector<User>& users) {
return users
| std::views::filter(&User::is_active)
| std::views::transform(&User::email)
| std::views::take(100)
| std::ranges::to<std::vector>(); // C++23 materialize
}
// Range adaptors with projection
std::ranges::sort(users, std::less{}, &User::last_name);
auto it = std::ranges::find(users, target_email, &User::email);
// unique_ptr — sole ownership, zero overhead
auto connection = std::make_unique<DbConnection>(config);
// shared_ptr — shared ownership (use sparingly)
auto cache = std::make_shared<LRUCache<std::string, Data>>(capacity);
// Custom deleter for C resources
auto file = std::unique_ptr<FILE, decltype(&fclose)>(
fopen("data.bin", "rb"), &fclose);
// RAII scope guard (C++23 or custom)
class ScopeGuard {
std::function<void()> cleanup_;
public:
explicit ScopeGuard(std::function<void()> fn) : cleanup_(std::move(fn)) {}
~ScopeGuard() { if (cleanup_) cleanup_(); }
ScopeGuard(const ScopeGuard&) = delete;
void dismiss() { cleanup_ = nullptr; }
};
// Usage
void process() {
auto* resource = acquire_resource();
ScopeGuard guard([&] { release_resource(resource); });
// ... work with resource, guard releases on any exit path
}
cmake_minimum_required(VERSION 3.25)
project(myapp VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Library target
add_library(mylib STATIC
src/core/engine.cpp
src/core/parser.cpp
)
target_include_directories(mylib PUBLIC include)
target_compile_features(mylib PUBLIC cxx_std_23)
# Executable
add_executable(myapp src/main.cpp)
target_link_libraries(myapp PRIVATE mylib)
# FetchContent for dependencies
include(FetchContent)
FetchContent_Declare(fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt
GIT_TAG 11.0.0
)
FetchContent_Declare(googletest
GIT_REPOSITORY https://github.com/google/googletest
GIT_TAG v1.15.0
)
FetchContent_MakeAvailable(fmt googletest)
target_link_libraries(mylib PRIVATE fmt::fmt)
# Compiler warnings (strict)
target_compile_options(mylib PRIVATE
$<$<CXX_COMPILER_ID:GNU,Clang>:-Wall -Wextra -Wpedantic -Werror>
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
)
# Sanitizers for debug builds
add_compile_options($<$<CONFIG:Debug>:-fsanitize=address,undefined>)
add_link_options($<$<CONFIG:Debug>:-fsanitize=address,undefined>)
# Testing
enable_testing()
add_executable(tests tests/test_parser.cpp tests/test_engine.cpp)
target_link_libraries(tests PRIVATE mylib GTest::gtest_main)
include(GoogleTest)
gtest_discover_tests(tests)
// CMakePresets.json — reproducible builds
{
"version": 6,
"configurePresets": [
{
"name": "dev",
"binaryDir": "build/dev",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
}
},
{
"name": "release",
"binaryDir": "build/release",
"cacheVariables": { "CMAKE_BUILD_TYPE": "Release" }
}
],
"buildPresets": [
{ "name": "dev", "configurePreset": "dev" },
{ "name": "release", "configurePreset": "release" }
],
"testPresets": [
{ "name": "dev", "configurePreset": "dev", "output": { "outputOnFailure": true } }
]
}
#include <gtest/gtest.h>
TEST(ParserTest, ParsesValidInteger) {
auto result = parse_int("42");
ASSERT_TRUE(result.has_value());
EXPECT_EQ(result.value(), 42);
}
TEST(ParserTest, ReturnsErrorForEmpty) {
auto result = parse_int("");
ASSERT_FALSE(result.has_value());
EXPECT_EQ(result.error(), ParseError::Empty);
}
// Parameterized tests
class FibonacciTest : public testing::TestWithParam<std::pair<int, int>> {};
TEST_P(FibonacciTest, ReturnsCorrectValue) {
auto [input, expected] = GetParam();
EXPECT_EQ(fib(input), expected);
}
INSTANTIATE_TEST_SUITE_P(Values, FibonacciTest, testing::Values(
std::pair{0, 0}, std::pair{1, 1}, std::pair{10, 55}
));
| Anti-Pattern | Problem | Solution |
|---|---|---|
Raw new/delete | Memory leaks, double-free | make_unique / make_shared exclusively |
reinterpret_cast | Undefined behavior | std::bit_cast (C++20) or redesign |
| Exceptions in destructors | std::terminate called | Mark destructors noexcept, handle errors before dtor |
using namespace std; in headers | Name collisions for all includers | Qualify names or using in .cpp only |
C-style casts (int)x | No compile-time checking | static_cast, dynamic_cast explicitly |
std::endl in loops | Flushes buffer every iteration (slow) | Use '\n' or std::print |
| Returning raw pointers for ownership | Unclear ownership semantics | Return unique_ptr or expected |
| No sanitizers in CI | Memory bugs found in production | ASan + UBSan in debug CI builds |
Before considering C++ work done:
cmake --preset dev && cmake --build --preset dev-Wall -Wextra -Wpedantic -Werrorctest --preset devclang-tidy passes with project checksnew/delete — smart pointers onlystd::expected used for fallible operations (not exceptions)constexpr applied where possiblenoexcept on move constructors and destructors