Featured
Delegating Constructor
Reduce constructor boilerplate by delegating to another constructor in the same class.
class Foo { Foo(int x) : Foo(x, 'y') {} Foo(int x, char y) : x(x), y(y) {} };Member Initialiser List
Initialise class member variables before the constructor body runs.
class Foo { Foo(int arg) : val(arg) {} int val; };Structured Binding
Unpack pairs, tuples, and aggregates cleanly.
auto [x, y] = std::pair#include <utility>{1, 2};
Recently Updated
See moreObject Slicing
Copying a derived object into a base object loses the derived part.
Derived d; Base b = d; // Sliced. Base& r = d; // Not sliced.I/O Manipulators
Format stream output with width, fill, precision, base, and more.
#include <iomanip> std::cout#include <iostream> << std::fixed#include <iostream> << std::setprecision#include <iomanip>(2) << 3.14159; // 3.14Boolalpha
Print booleans as "true"/"false" strings instead of the default 1/0.
std::cout#include <iostream> << std::boolalpha#include <iostream> << true << "\n" << false << "\n";Operator Overload
Define what operators do for a class.
Point operator+(const Point& a, const Point& b) { return Point(a.x + b.x, a.y + b.y); } Point c = a + b;Range
Work with whole containers and compose lazy views.
#include <ranges> std::vector#include <vector><int> v = {1, 2, 3}; auto odds = v | std::views::filter#include <ranges>(is_odd); // odds is {1, 3}.Move Semantics
Transfer an object's resources to another object instead of copying them.
std::vector#include <vector><int> a = {1, 2, 3}; std::vector#include <vector><int> b = std::move#include <utility>(a); // b owns the array and a is empty.Weak Pointer
Non-owning reference to an object managed by a shared pointer.
#include <memory> auto s = std::make_shared#include <memory><int>(5); std::weak_ptr#include <memory><int> w = s; if (auto p = w.lock()) { *p; // 5 }Unique Pointer
Smart pointer that is the sole owner of its managed resource.
#include <memory> std::unique_ptr#include <memory><int> p = std::make_unique#include <memory><int>(5); *p; // 5 // Deleted when p goes out of scope.
For Beginners
See moreAccess Specifier
Set class member accessibility.
class Example { public: protected: private: };Auto
Automatic type deduction of an object or expression at compile time.
auto x = 123; // int auto y = x + 456; // int auto z = "str"; // const char*Boolalpha
Print booleans as "true"/"false" strings instead of the default 1/0.
std::cout#include <iostream> << std::boolalpha#include <iostream> << true << "\n" << false << "\n";Namespace
Groups identifiers to a named scope to prevent name collisions.
namespace GroupA { int var = 1; } GroupA::var;Range-Based For Loop
Loop over containers without writing indices or iterators.
for (auto& element : container) { // Do something with element. }