Add origin field to all skill files to track their source repository.
This enables users to identify where distributed skills originated from.
Fixesaffaan-m/everything-claude-code#246
C++ coding standards based on the C++ Core Guidelines (isocpp.github.io). Use when writing, reviewing, or refactoring C++ code to enforce modern, safe, and idiomatic practices.
ECC
C++ Coding Standards (C++ Core Guidelines)
Comprehensive coding standards for modern C++ (C++17/20/23) derived from the C++ Core Guidelines. Enforces type safety, resource safety, immutability, and clarity.
When to Use
Writing new C++ code (classes, functions, templates)
Reviewing or refactoring existing C++ code
Making architectural decisions in C++ projects
Enforcing consistent style across a C++ codebase
Choosing between language features (e.g., enum vs enum class, raw pointer vs smart pointer)
When NOT to Use
Non-C++ projects
Legacy C codebases that cannot adopt modern C++ features
Embedded/bare-metal contexts where specific guidelines conflict with hardware constraints (adapt selectively)
Cross-Cutting Principles
These themes recur across the entire guidelines and form the foundation:
// Weak interface: unclear ownership, unclear units
doubleboil(double*temp);// Non-const global variable
intg_counter=0;// I.2 violation
Functions (F.*)
Key Rules
Rule
Summary
F.1
Package meaningful operations as carefully named functions
F.2
A function should perform a single logical operation
F.3
Keep functions short and simple
F.4
If a function might be evaluated at compile time, declare it constexpr
F.6
If your function must not throw, declare it noexcept
F.8
Prefer pure functions
F.16
For "in" parameters, pass cheaply-copied types by value and others by const&
F.20
For "out" values, prefer return values to output parameters
F.21
To return multiple "out" values, prefer returning a struct
F.43
Never return a pointer or reference to a local object
Parameter Passing
// F.16: Cheap types by value, others by const&
voidprint(intx);// cheap: by value
voidanalyze(conststd::string&data);// expensive: by const&
voidtransform(std::strings);// sink: by value (will move)
// F.20 + F.21: Return values, not output parameters
structParseResult{std::stringtoken;intposition;};ParseResultparse(std::string_viewinput);// GOOD: return struct
// BAD: output parameters
voidparse(std::string_viewinput,std::string&token,int&pos);// avoid this
Pure Functions and constexpr
// F.4 + F.8: Pure, constexpr where possible
constexprintfactorial(intn)noexcept{return(n<=1)?1:n*factorial(n-1);}static_assert(factorial(5)==120);
Anti-Patterns
Returning T&& from functions (F.45)
Using va_arg / C-style variadics (F.55)
Capturing by reference in lambdas passed to other threads (F.53)
Returning const T which inhibits move semantics (F.49)
Classes & Class Hierarchies (C.*)
Key Rules
Rule
Summary
C.2
Use class if invariant exists; struct if data members vary independently
C.9
Minimize exposure of members
C.20
If you can avoid defining default operations, do (Rule of Zero)
C.21
If you define or =delete any copy/move/destructor, handle them all (Rule of Five)
C.35
Base class destructor: public virtual or protected non-virtual
C.41
A constructor should create a fully initialized object
C.46
Declare single-argument constructors explicit
C.67
A polymorphic class should suppress public copy/move
C.128
Virtual functions: specify exactly one of virtual, override, or final
Rule of Zero
// C.20: Let the compiler generate special members
structEmployee{std::stringname;std::stringdepartment;intid;// No destructor, copy/move constructors, or assignment operators needed
};
Rule of Five
// C.21: If you must manage a resource, define all five
classBuffer{public:explicitBuffer(std::size_tsize):data_(std::make_unique<char[]>(size)),size_(size){}~Buffer()=default;Buffer(constBuffer&other):data_(std::make_unique<char[]>(other.size_)),size_(other.size_){std::copy_n(other.data_.get(),size_,data_.get());}Buffer&operator=(constBuffer&other){if(this!=&other){autonew_data=std::make_unique<char[]>(other.size_);std::copy_n(other.data_.get(),other.size_,new_data.get());data_=std::move(new_data);size_=other.size_;}return*this;}Buffer(Buffer&&)noexcept=default;Buffer&operator=(Buffer&&)noexcept=default;private:std::unique_ptr<char[]>data_;std::size_tsize_;};
Class Hierarchy
// C.35 + C.128: Virtual destructor, use override
classShape{public:virtual~Shape()=default;virtualdoublearea()const=0;// C.121: pure interface
};classCircle:publicShape{public:explicitCircle(doubler):radius_(r){}doublearea()constoverride{return3.14159*radius_*radius_;}private:doubleradius_;};
Anti-Patterns
Calling virtual functions in constructors/destructors (C.82)
Using memset/memcpy on non-trivial types (C.90)
Providing different default arguments for virtual function and overrider (C.140)
Making data members const or references, which suppresses move/copy (C.12)
Use unique_ptr or shared_ptr to represent ownership
R.21
Prefer unique_ptr over shared_ptr unless sharing ownership
R.22
Use make_shared() to make shared_ptrs
Smart Pointer Usage
// R.11 + R.20 + R.21: RAII with smart pointers
autowidget=std::make_unique<Widget>("config");// unique ownership
autocache=std::make_shared<Cache>(1024);// shared ownership
// R.3: Raw pointer = non-owning observer
voidrender(constWidget*w){// does NOT own w
if(w)w->draw();}render(widget.get());
RAII Pattern
// R.1: Resource acquisition is initialization
classFileHandle{public:explicitFileHandle(conststd::string&path):handle_(std::fopen(path.c_str(),"r")){if(!handle_)throwstd::runtime_error("Failed to open: "+path);}~FileHandle(){if(handle_)std::fclose(handle_);}FileHandle(constFileHandle&)=delete;FileHandle&operator=(constFileHandle&)=delete;FileHandle(FileHandle&&other)noexcept:handle_(std::exchange(other.handle_,nullptr)){}FileHandle&operator=(FileHandle&&other)noexcept{if(this!=&other){if(handle_)std::fclose(handle_);handle_=std::exchange(other.handle_,nullptr);}return*this;}private:std::FILE*handle_;};
Anti-Patterns
Naked new/delete (R.11)
malloc()/free() in C++ code (R.10)
Multiple resource allocations in a single expression (R.13 -- exception safety hazard)
shared_ptr where unique_ptr suffices (R.21)
Expressions & Statements (ES.*)
Key Rules
Rule
Summary
ES.5
Keep scopes small
ES.20
Always initialize an object
ES.23
Prefer {} initializer syntax
ES.25
Declare objects const or constexpr unless modification is intended
ES.28
Use lambdas for complex initialization of const variables
C-style casts (ES.48 -- use static_cast, const_cast, etc.)
Casting away const (ES.50)
Magic numbers without named constants (ES.45)
Mixing signed and unsigned arithmetic (ES.100)
Reusing names in nested scopes (ES.12)
Error Handling (E.*)
Key Rules
Rule
Summary
E.1
Develop an error-handling strategy early in a design
E.2
Throw an exception to signal that a function can't perform its assigned task
E.6
Use RAII to prevent leaks
E.12
Use noexcept when throwing is impossible or unacceptable
E.14
Use purpose-designed user-defined types as exceptions
E.15
Throw by value, catch by reference
E.16
Destructors, deallocation, and swap must never fail
E.17
Don't try to catch every exception in every function
Exception Hierarchy
// E.14 + E.15: Custom exception types, throw by value, catch by reference
classAppError:publicstd::runtime_error{public:usingstd::runtime_error::runtime_error;};classNetworkError:publicAppError{public:NetworkError(conststd::string&msg,intcode):AppError(msg),status_code(code){}intstatus_code;};voidfetch_data(conststd::string&url){// E.2: Throw to signal failure
throwNetworkError("connection refused",503);}voidrun(){try{fetch_data("https://api.example.com");}catch(constNetworkError&e){log_error(e.what(),e.status_code);}catch(constAppError&e){log_error(e.what());}// E.17: Don't catch everything here -- let unexpected errors propagate
}
Anti-Patterns
Throwing built-in types like int or string literals (E.14)
Catching by value (slicing risk) (E.15)
Empty catch blocks that silently swallow errors
Using exceptions for flow control (E.3)
Error handling based on global state like errno (E.28)
Constants & Immutability (Con.*)
All Rules
Rule
Summary
Con.1
By default, make objects immutable
Con.2
By default, make member functions const
Con.3
By default, pass pointers and references to const
Con.4
Use const for values that don't change after construction
Con.5
Use constexpr for values computable at compile time
// Con.1 through Con.5: Immutability by default
classSensor{public:explicitSensor(std::stringid):id_(std::move(id)){}// Con.2: const member functions by default
conststd::string&id()const{returnid_;}doublelast_reading()const{returnreading_;}// Only non-const when mutation is required
voidrecord(doublevalue){reading_=value;}private:conststd::stringid_;// Con.4: never changes after construction
doublereading_{0.0};};// Con.3: Pass by const reference
voiddisplay(constSensor&s){std::cout<<s.id()<<": "<<s.last_reading()<<'\n';}// Con.5: Compile-time constants
constexprdoublePI=3.14159265358979;constexprintMAX_SENSORS=256;
Concurrency & Parallelism (CP.*)
Key Rules
Rule
Summary
CP.2
Avoid data races
CP.3
Minimize explicit sharing of writable data
CP.4
Think in terms of tasks, rather than threads
CP.8
Don't use volatile for synchronization
CP.20
Use RAII, never plain lock()/unlock()
CP.21
Use std::scoped_lock to acquire multiple mutexes
CP.22
Never call unknown code while holding a lock
CP.42
Don't wait without a condition
CP.44
Remember to name your lock_guards and unique_locks
CP.100
Don't use lock-free programming unless you absolutely have to
Safe Locking
// CP.20 + CP.44: RAII locks, always named
classThreadSafeQueue{public:voidpush(intvalue){std::lock_guard<std::mutex>lock(mutex_);// CP.44: named!
queue_.push(value);cv_.notify_one();}intpop(){std::unique_lock<std::mutex>lock(mutex_);// CP.42: Always wait with a condition
cv_.wait(lock,[this]{return!queue_.empty();});constintvalue=queue_.front();queue_.pop();returnvalue;}private:std::mutexmutex_;// CP.50: mutex with its data
std::condition_variablecv_;std::queue<int>queue_;};
Multiple Mutexes
// CP.21: std::scoped_lock for multiple mutexes (deadlock-free)
voidtransfer(Account&from,Account&to,doubleamount){std::scoped_locklock(from.mutex_,to.mutex_);from.balance_-=amount;to.balance_+=amount;}
Anti-Patterns
volatile for synchronization (CP.8 -- it's for hardware I/O only)
Use .cpp for code files and .h for interface files
SF.7
Don't write using namespace at global scope in a header
SF.8
Use #include guards for all .h files
SF.11
Header files should be self-contained
NL.5
Avoid encoding type information in names (no Hungarian notation)
NL.8
Use a consistent naming style
NL.9
Use ALL_CAPS for macro names only
NL.10
Prefer underscore_style names
Header Guard
// SF.8: Include guard (or #pragma once)
#ifndef PROJECT_MODULE_WIDGET_H
#define PROJECT_MODULE_WIDGET_H
// SF.11: Self-contained -- include everything this header needs
#include<string>#include<vector>namespaceproject::module{classWidget{public:explicitWidget(std::stringname);conststd::string&name()const;private:std::stringname_;};}// namespace project::module
#endif // PROJECT_MODULE_WIDGET_H
Naming Conventions
// NL.8 + NL.10: Consistent underscore_style
namespacemy_project{constexprintmax_buffer_size=4096;// NL.9: not ALL_CAPS (it's not a macro)
classtcp_connection{// underscore_style class
public:voidsend_message(std::string_viewmsg);boolis_connected()const;private:std::stringhost_;// trailing underscore for members
intport_;};}// namespace my_project
Anti-Patterns
using namespace std; in a header at global scope (SF.7)
Headers that depend on inclusion order (SF.10, SF.11)
Hungarian notation like strName, iCount (NL.5)
ALL_CAPS for anything other than macros (NL.9)
Performance (Per.*)
Key Rules
Rule
Summary
Per.1
Don't optimize without reason
Per.2
Don't optimize prematurely
Per.6
Don't make claims about performance without measurements
Per.7
Design to enable optimization
Per.10
Rely on the static type system
Per.11
Move computation from run time to compile time
Per.19
Access memory predictably
Guidelines
// Per.11: Compile-time computation where possible
constexprautolookup_table=[]{std::array<int,256>table{};for(inti=0;i<256;++i){table[i]=i*i;}returntable;}();// Per.19: Prefer contiguous data for cache-friendliness
std::vector<Point>points;// GOOD: contiguous
std::vector<std::unique_ptr<Point>>indirect_points;// BAD: pointer chasing
Anti-Patterns
Optimizing without profiling data (Per.1, Per.6)
Choosing "clever" low-level code over clear abstractions (Per.4, Per.5)
Ignoring data layout and cache behavior (Per.19)
Quick Reference Checklist
Before marking C++ work complete:
No raw new/delete -- use smart pointers or RAII (R.11)
Objects initialized at declaration (ES.20)
Variables are const/constexpr by default (Con.1, ES.25)
Member functions are const where possible (Con.2)
enum class instead of plain enum (Enum.3)
nullptr instead of 0/NULL (ES.47)
No narrowing conversions (ES.46)
No C-style casts (ES.48)
Single-argument constructors are explicit (C.46)
Rule of Zero or Rule of Five applied (C.20, C.21)
Base class destructors are public virtual or protected non-virtual (C.35)
Templates are constrained with concepts (T.10)
No using namespace in headers at global scope (SF.7)
Headers have include guards and are self-contained (SF.8, SF.11)
Locks use RAII (scoped_lock/lock_guard) (CP.20)
Exceptions are custom types, thrown by value, caught by reference (E.14, E.15)