C++11


code
Syntax [crayon-5d134eaf32ca1558895133/] 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


array
Syntax Defined in header <array> [crayon-5d134eaf343db597618871/] 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


code
Syntax [crayon-5d134eaf34aa7307266754/] Usage / Usability Using braces, specifying the initial contents of a container is easy [crayon-5d134eaf34aaf934657517/] Constructor calls with empty braces [crayon-5d134eaf34ab2389301828/] 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



code
Syntax [crayon-5d134eaf35092217427625/] 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


code
Syntax [crayon-5d134eaf35478904820050/] 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




code
Syntax [crayon-5d134eaf35cdb206686878/] 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-5d134eaf35ce2372488221/]   Suppose we have […]

Miscellaneous: Reference Qualifiers


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

STL Containers: Tuple


code
Syntax [crayon-5d134eaf36570367639328/]   [crayon-5d134eaf36577086390455/] 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



code
Syntax [crayon-5d134eaf3697a251813315/] 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


fw_list
Syntax Defined in header <forward_list> [crayon-5d134eaf36d9c362331034/] Definitions List definition [crayon-5d134eaf36da3321044262/] Forward list definition [crayon-5d134eaf36da7840014839/] 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


code
Syntax [crayon-5d134eaf37166021042962/] 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-5d134eaf3716d267295802/] bind returns a new function object with a different prototype because […]

Miscellaneous: Function / Bind