# C++ Language Reference
## Languages — The Codex Coding
**URL:** https://thecodex.expert/coding/languages/cpp/
**Type:** language-reference | **Confidence:** high | **Last verified:** 2026-06-01

## CANONICAL DEFINITION
C++ is a general-purpose, statically typed, compiled programming language that extends C with classes, templates, RAII-based resource management, and the Standard Template Library — providing zero-overhead abstractions for systems programming, game engines, and high-performance applications.

## QUICK FACTS
- **Created:** 1979 (C with Classes); C++98 standardised 1998; by Bjarne Stroustrup at Bell Labs
- **Current standard:** C++23 (ISO/IEC 14882:2024); C++20 widely deployed
- **Typing:** Static, strong
- **Execution:** Native compiled (GCC, Clang, MSVC)
- **Memory:** Manual + RAII; smart pointers (unique_ptr, shared_ptr, weak_ptr)
- **Paradigms:** Procedural, OOP, generic (templates), functional

## CRITICAL NOTES
- **C and C++ are different languages** — not all C is valid C++; different idioms, object model, stdlib
- **new/delete are obsolete** in modern C++ — use `std::make_unique<T>()` and `std::make_shared<T>()`
- **Templates are reified** — compiler generates code per type (unlike Java generics which are erased)
- **Exceptions have near-zero cost** on happy path but significant cost when thrown; some codebases disable
- **Inherits C's undefined behaviour** — signed overflow, OOB, use-after-free are all UB

## RAII
"Resource Acquisition Is Initialisation" — the central C++ idiom
- Acquire resource in constructor; release in destructor
- Destructor called automatically at scope end — even during exception stack unwinding
- Smart pointers are RAII wrappers: `unique_ptr` (single owner), `shared_ptr` (ref-counted)
- Never use raw new/delete in modern C++ — use make_unique/make_shared

## RULE OF FIVE
If you define any of: destructor, copy constructor, copy assignment, move constructor, move assignment
→ you must define ALL FIVE (or explicitly = default / = delete each one)

## MOVE SEMANTICS (C++11+)
- `&&` = rvalue reference — binds to temporary or `std::move()`-d object
- Move constructor/assignment: transfer (steal) resources instead of copying
- `std::move(x)` casts x to rvalue — does NOT move by itself; move happens in the constructor/assignment
- After move, source object is in valid but unspecified state

## STL CONTAINERS
- `std::vector<T>` — dynamic array (amortised O(1) push_back)
- `std::map<K,V>` — sorted tree map (O(log n)) | `std::unordered_map<K,V>` — hash map (O(1) avg)
- `std::set<T>` — sorted set | `std::unordered_set<T>` — hash set
- `std::list<T>` — doubly linked | `std::deque<T>` — double-ended queue
- `std::array<T,N>` — fixed-size array (prefer over C arrays)
- `std::span<T>` (C++20) — non-owning view (prefer over raw pointer + size)

## MODERN C++ VERSIONS
- C++11: auto, range-for, lambdas, move semantics, smart pointers, constexpr, thread, nullptr
- C++17: structured bindings, if constexpr, std::optional, std::variant, std::filesystem
- C++20: concepts, ranges, coroutines (co_await), modules, std::format, std::span, <=>
- C++23: std::expected, std::print, std::stacktrace, std::generator, import std

## NOTABLE USES
Unreal Engine, Unity runtime, Chromium, Firefox, GCC, Clang, MySQL, MongoDB, HFT systems, PlayStation/Xbox SDKs

## SOURCES
- ISO C++20: iso.org/standard/79358.html
- Stroustrup (2013): The C++ Programming Language (4th ed.)
- Meyers (2014): Effective Modern C++
- Core Guidelines: github.com/isocpp/CppCoreGuidelines
- cppreference.com: en.cppreference.com

*The Codex Coding — thecodex.expert/coding/ — Free forever — Mumbai, India*
