« Back to Search  |  Reader Mode  |  Switch to Full Retro Site View Links: Stay in Reader  |  Retro Mode: ON  |  Original »
hacking C++ · André Müller · Extracted in 2510 ms

C++ Cheat Sheets & Infographics

Source: https://hackingcpp.com/cpp/cheat_sheets

Standard Algorithms

Quick Overview

Algorithms Gallery ...

Non-Modifying Operations

Copying  / Sampling / Moving

Reordering Elements

Modifying Elements

Numeric Operations

Standard Views

std::span
C++20

std::string_view
C++17

Composable Range Views Ranges
C++20/23

Standard Containers

std:: Sequence Containers

std::vector<ValueType>

std::deque<ValueType>

std::list<ValueType>

std::forward_list<ValueType> std::forward_list<T>

std::string Interface & Utilities Overview

std:: Associative Containers

std::set<KeyType,Compare>

std::map<KeyType,MappedType,KeyCompare>

std::unordered_set<KeyType,Hash,KeyEqual>

std::unordered_map<KeyType,MappedType,Hash,KeyEqual>

std:: Special Containers

Iterators

click to go to page "Iterators (Introduction)"

Iterator Range

click to go to page "Iterators (Introduction)"

end-of-range iterator q points one behind the last element in the range

Iterator Range Examples

click to go to page "Iterators (Introduction)"

Which Sequence Container Should I Use?

vector Growth Scheme

click to go to page "std::vector"

vector Memory Layout (typical)

Example: vector object w on the stack

vector<int> w {0,1,2,3,4};
w.reserve(8);
click to go to page "std::vector"

Standard Randomness

Standard Random Distributions
C++11

Standard Random Sampling Distributions
C++11

Standard Utilities

std::numeric_limits<T>

Language Rules & Mechanisms

Build Model / Compiling A Project

The "Usual Arithmetic Conversions "

Lambda Expression s

Lambda Expression Syntax

Variables in C++


Reference Binding Rules


Reference Collapsing  C++11

for template arguments


Perfect Forwarding C++11
of template arguments Forwarding


Non-Standard Libraries

{fmt} v8.0 - Printing & Formatting

{fmt} v8.0 - Time & Date Formatting

std::format and std::strftime use the same formatting tokens

Design Guidelines

Function Parameters & Return Values Fn Interfaces
C++17

  • prefer specific types over general-purpose types
  • don't use getter/setter pairs for classes
  • use descriptive action names ( verbs ) for mutating member functions
  • avoid direct mutable access to class member variables from the outside

String(-Like) Function Parameters

click to go to page "Strings: Which Function Parameter Type?"

Don't Throw Exceptions in Destructors!

Parent (of type A) gets destroyed and the destructor of one child (type B) throws an exception ⇒ resources may leak!

click to go to page "Exceptions"

Engineering

Binary Representations of Numeric Values

Terminology

Function Contracts

click to go to page "Functions (Basics)"