Syntax [crayon-5c6d2c706f1f8679536019/] 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-5c6d2c7070826617598551/] 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-5c6d2c707577f437088876/] Usage / Usability Using braces, specifying the initial contents of a container is easy [crayon-5c6d2c707578e847845516/] Constructor calls with empty braces [crayon-5c6d2c7075794399208780/] 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-5c6d2c7075ebe542328080/] 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-5c6d2c70764c6811393216/] 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-5c6d2c7076de8667158570/] 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-5c6d2c7076df2111587349/]   Suppose we have […]

Miscellaneous: Reference Qualifiers

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

STL Containers: Tuple

Syntax [crayon-5c6d2c70777b8605114463/]   [crayon-5c6d2c70777c1116655142/] 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-5c6d2c7077b56780612436/] 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-5c6d2c7077f98827891019/] Definitions List definition [crayon-5c6d2c7077fa1432312762/] Forward list definition [crayon-5c6d2c7077fa7246809613/] 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-5c6d2c70783b3265307665/] 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-5c6d2c70783bc291579208/] bind returns a new function object with a different prototype because […]

Miscellaneous: Function / Bind