Syntax [crayon-5d5c85d4d9af6957550345/] The purpose of raw string literals is to no longer have the need to escape characters such as \ ? ” by using another slash before that character (eg. \\ \? \”) PROS Code is clearer CONS The syntax is not very friendly: R”(example)”   Paranthesis? Why we […]

Miscellaneous: Raw string literals

Syntax Defined in header <array> [crayon-5d5c85d4db24d551330396/] Usage / Usability std::array is a container that encapsulates fixed size arrays. Element access at – access specified element with bounds checking operator[] – access specified element front – access the first element back – access the last element data – direct access to the […]

STL Containers: Array

Syntax [crayon-5d5c85d4db87e315545100/] Usage / Usability Using braces, specifying the initial contents of a container is easy [crayon-5d5c85d4db88c096943360/] Constructor calls with empty braces [crayon-5d5c85d4db894579724512/] No arguments ? => default construction Empty initializer list ? => construction of init list with no elements Calling a ctor with an empty initializer_list You need […]

General features: Uniform initialization

Syntax [crayon-5d5c85d4dc1d0552641825/] Functionality If the using-declaration refers to a constructor of a base class (e.g. using Base::Base;), constructors of that base class are inherited. The inherited constructors are equivalent to user-defined constructors with an empty body and with a member initializer list consisting of a single nested-name-specifier, which forwards all […]

Classes: Inheriting constructors

Syntax [crayon-5d5c85d4dc79b081282521/] Usage / Usability Already had the stl call: for_each(begin, end, func) Still have to say the begin and the end iterators: but more flexible Hard for cases when you want to do more things in a for (with for_each we need to have it in a function – […]

General features: Ranged-based for loop

Syntax [crayon-5d5c85d4dd61e787747353/] Usage / Usability Member function reference qualifiers make it possible to treat lvalue and rvalue objects (*this) differently. Member functions must not be virtual to use them Member function reference qualifiers make it possible to treat lvalue and rvalue objects (*this) differently.   [crayon-5d5c85d4dd62c111305033/]   Suppose we have […]

Miscellaneous: Reference Qualifiers

Syntax Before C++11 we had only pair as a structure, which contains two types. [crayon-5d5c85d4ddd83952880477/] C++11 added tuple, which is an extended pair. [crayon-5d5c85d4ddd90351281913/] Accessing data from a tuple [crayon-5d5c85d4ddd99200271719/] Unpacking from a tuple [crayon-5d5c85d4ddda0708626981/] std::ignore Can be used to ignore one or multiple unpacking parameters [crayon-5d5c85d4ddda7647378287/]  

STL Containers: Tuple

Syntax [crayon-5d5c85d4de517336567961/]   [crayon-5d5c85d4de524251915641/] Variadic templates essentially allow recursion to be replaced by iteration Variadic templates needs an end function – usually it’s a specialization for the last remaining parameter, in order to stop the recursion. This has changed in C++17 and is no longer needed.

Meta programming: Variadic templates

Syntax [crayon-5d5c85d4def71448967940/] Provide default values Useful for providing default values for its members. This also reduce the number of members that needs to be initialized per constructor. In case the member contains a default initialization and is also set on constructor, the constructor will override the value.   Pitfalls Initialization […]

Classes: In-class member initializers

Syntax Defined in header <forward_list> [crayon-5d5c85d4df633079964678/] Definitions List definition [crayon-5d5c85d4df640423033106/] Forward list definition [crayon-5d5c85d4df648814367112/] The main difference between a list and a forward list is the pointer to the previous node.   About forward list is a container that supports fast insertion and removal of elements from anywhere in the […]

STL Containers: Forward list

Syntax [crayon-5d5c85d4dfcc8669329569/] std::function is a wrapper to a simple function, to a functor or to a lambda expression. std::bind is a template function that returns a std::function object that binds a set of arguments to a function.   [crayon-5d5c85d4dfcd4077779818/] bind returns a new function object with a different prototype because […]

Miscellaneous: Function / Bind