Syntax [crayon-5cc0cbe8d9938507967929/] 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-5cc0cbe8db1b8519403803/] 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-5cc0cbe8db62c500302430/] Usage / Usability Using braces, specifying the initial contents of a container is easy [crayon-5cc0cbe8db636293313369/] Constructor calls with empty braces [crayon-5cc0cbe8db63c717830880/] 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-5cc0cbe8dbbc0136609239/] 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-5cc0cbe8dbf7d976938268/] 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-5cc0cbe8dc7be262916767/] 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-5cc0cbe8dc7c7885334270/]   Suppose we have […]

Miscellaneous: Reference Qualifiers

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

STL Containers: Tuple

Syntax [crayon-5cc0cbe8dd0a9970128975/]   [crayon-5cc0cbe8dd0b2195729060/] 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-5cc0cbe8dd443878636142/] 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-5cc0cbe8dd87b673668251/] Definitions List definition [crayon-5cc0cbe8dd884357748334/] Forward list definition [crayon-5cc0cbe8dd88a212835880/] 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-5cc0cbe8ddce6231292605/] 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-5cc0cbe8ddcf1219396656/] bind returns a new function object with a different prototype because […]

Miscellaneous: Function / Bind