Each programmer should at least play around (or get confortable) with multiple programming languages and tools, in order to notice the differences between them and be able to choose the one that fits the best for the task they have. The list is for juniors or for anyone who did […]

Practical work: Mentoring activities

String conversions using stringstream Stringstream can be used to get values from a string, by using stringstream as adaptor. Stringstream also has the operator << for adding a string into its stream. In case the conversion fails (trying to add “abc” into an int for example), the value of the […]

Conversions using std::to_string and “from_string”

Definition Clamp is an algorithm added in C++17 that is used to limit a value in a given range.  If value > max, value is set to max If value < min, value is set to min Syntax Before C++17, we were relying on the following code (or similar) to […]

Library Feature: std::clamp

lightning talk
Lambda under the hood What if we capture by reference instead? [&] vs [=] Lambda template Move cannot move if const C++17: Clamp Before C++17, we were relying on the following code (or similar) to clamp a value. Now, with C++17, we can simply use std::clamp. Reverse Unique Sort Algos […]

Lightning talk #7 – C++ functionality: Did you know… ...

lightning talk
Paranthesis [crayon-5c6ab410cdaa0985073265/] Returning non-bools [crayon-5c6ab410cdab3898005270/] Returning bools [crayon-5c6ab410cdaba023669629/] Reusing data Similar behavior in if/else branches [crayon-5c6ab410cdac0628885155/] Similar behavior in if/else branches [crayon-5c6ab410cdac6848332663/] Same behavior on both branches – move it outside the branches. [crayon-5c6ab410cdacb101353398/] Condition that appears on all steps – Check it only once. [crayon-5c6ab410cdad1260581971/]

Lightning talk #6 – Refactoring steps

Definition [crayon-5c6ab410ce003979019487/] Fills the range [first, last) with sequentially increasing values, starting with value and repetitively evaluating ++value.   Syntax [crayon-5c6ab410ce00c343434252/] But now let’s create a custom incrementable class. Iota is working with a T type, so we only need to overload the ++ operator. [crayon-5c6ab410ce012022905123/] So what do we have here? I’ve added a […]

std::iota and custom incrementable

trip report
A few days ago there was the WG21 meeting in San Diego and the committee have some excellent news for the upcoming C++20 and C++23. From the major features: Ranges, Concepts, and Contracts were merged into the C++20 standard. Modules and Coroutines will most likely be added in C++23. For […]

(C++20) 2018 San Diego ISO C++ Committee Trip Report : ...

Syntax [crayon-5c6ab410ce441800807344/]   Tuples and data fetching Tuples are suggested for returning multiple values from a function. They are in a strong relation with std::tie, which is used for retrieving the values. The only problem is that we have to have all those variables previously declared. [crayon-5c6ab410ce44a982553612/] But what if […]

Language feature: Structured binding

Below you’ll find a list of problems I’ve made for testing the modern C++ knowledge. There are no hints here, so this is a knowledge check. Refactor as much as you want. All the answers are in my other posts, feel free to check them here. [crayon-5c6ab410ce9b7770542662/]  

Practical work: Refactoring old code to Modern C++ (11 / ...

Syntax [crayon-5c6ab410cedd3353034710/] std::quoted was added in C++14 and it is used to take care of escaping quotes and backslashes in output streams, and unescaping them in input streams. This is handy for example if we want to use it in an SQL statement, in both ways (either add the escaping, […]

std::quoted and the “friendly” delimiters