142 Topics
Getting started with C++ Introduction Topic
std::vector All Versions
A vector is a dynamic array with automatically handled storage. The elements in a vector can be accessed just as efficiently as those in an array with the advantage being that vectors can dynamically change in size. In terms of storage the vector data is (usually)...
Returning several values from a function All Versions
There are many situations where it is useful to return several values from a function: for example, if you want to input an item and return the price and number in stock, this functionality could be useful. There are many ways to do this in C++, and most involve the...
Lambdas C++11C++14C++17
The Rule of Three, Five, And Zero All Versions
Undefined Behavior All Versions
What is undefined behavior (UB)? According to the ISO C++ Standard (§1.3.24, N4296), it is behavior for which this International Standard imposes no requirements. This means that when encountering UB the compiled program is allowed to do whatever it wants. This...
std::string All Versions
Strings are objects that represent sequences of characters. The standard string class provides a simple, safe and versatile alternative to using explicit arrays of chars when dealing with text and other sequences of characters. The C++ string class is part of the std...
Compiling and Building All Versions
Programs written in C++ need to be compiled before they can be run. There is a large variety of compilers available depending on your operating system.
Smart Pointers C++11C++14C++17
File I/O All Versions
C++ file I/O is done via streams. The key abstractions are: std::istream for reading text. std::ostream for writing text. std::streambuf for reading or writing characters. Formatted input uses operator>>. Formatted output uses operator. Streams use std::locale,...
Metaprogramming All Versions
In C++ Metaprogramming refers to the use of macros or templates to generate code at compile-time. In general, macros are frowned upon in this role and templates are preferred, although they are not as generic. Template metaprogramming often makes use of...
Threading C++11C++14C++17
Templates All Versions
Classes, functions, and (since C++14) variables can be templated. A template is a piece of code with some free parameters that will become a concrete class, function, or variable when all parameters are specified. Parameters can be types, values, or themselves...
SFINAE (Substitution Failure Is Not An Error) All Versions
Preprocessor All Versions
The C preprocessor is a simple text parser/replacer that is run before the actual compilation of the code. Used to extend and ease the use of the C (and later C++) language, it can be used for: a. Including other files using #include b. Define a text-replacement...
Build Systems All Versions
C++, like C, has a long and varied history regarding compilation workflows and build processes. Today, C++ has various popular build systems that are used to compile programs, sometimes for multiple platforms within one build system. Here, a few build systems will be...
Namespaces All Versions
Used to prevent name collisions when using multiple libraries, a namespace is a declarative prefix for functions, classes, types, etc.
Curiously Recurring Template Pattern (CRTP) All Versions
A pattern in which a class inherits from a class template with itself as one of its template parameters. CRTP is usually used to provide static polymorphism in C++.
Loops All Versions
A loop statement executes a group of statements repeatedly until a condition is met. There are 3 types of primitive loops in C++: for, while, and do...while.