Monthly Archives: February 2018


code
Syntax [crayon-5d5e8d029e749835631610/] std::optional behaves as a variant of a type T and the value std::nullopt. We can set the value as we would do with any other type, but we can also assign it to std::nullopt – instead of returning nullptr, -1, 0, “”, or whatever we’d expect to receive […]

Library feature: std::optional


code
Nested namespaces is a tiny feature but i find it very useful. Before C++17, using multi-level namespaces was irritating both to read and to write. [crayon-5d5e8d029faab428721242/] We could have improve the indentation by having everything in one line, but that looks horrible as well. [crayon-5d5e8d029fab4837338894/] Luckily, C++17 now let’s you […]

Language feature: Nested namespaces


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