MSVC (VS 2017 15.7, end of June 2018) is as far as I know the only major compiler/STL implementation that has parallel algorithms. Not everything is done, but you can use a lot of algorithms and apply std::execution::par on them!
Have a look at few examples I managed to run.
Two weeks ago I asked you for help: I wanted to build a wall of examples of std::optional. I’m very grateful that a lot of you responded and I could move forward with the plan!
You’re amazing!
Let’s dive in the examples my readers have sent me!
A Reminder To remind, I asked for some real-life examples of std::optional.
Around the time C++17 was being standardized I saw magical terms like “discriminated union”, “type-safe union” or “sum type” floating around. Later it appeared to mean the same type: “variant”.
Let’s see how this brand new std::variant from C++17 works and where it might be useful.
The Basics In my experience, I haven’t used unions much.
Show me your code!
I’d like to run a little experiment.
Let’s build a wall of examples of std::optional!
Intro In the last three articles of my C++17 STL series I’ve been discussing how to use std::optional. I can talk and talk… or write and write… but I’m wondering how do you use this wrapper type?
In my last two posts in the C++17 STL series, I covered how to use std::optional. This wrapper type (also called “vocabulary type”) is handy when you’d like to express that something is ‘nullable’ and might be ‘empty’. For example, you can return std::nullopt to indicate that the code generated an error… but it this the best choice?
Let’s take a pair of two types <YourType, bool> - what can you do with such composition?
In this article, I’ll describe std:optional - a new helper type added in C++17. It’s a wrapper for your type and a flag that indicates if the value is initialized or not. Let’s see where it can be useful and how you can use it.
There are many situations where you need to express that something is “optional” - an object that might contain a value or not. You have several options to implement such case, but with C++17 there’s probably the most helpful way: std::optional.
For today I’ve prepared one refactoring case where you can learn how to apply this new C++17 feature.
Let’s have a quick overview of another book related to Modern C++ and The Standard Library. This time I picked Rainer Grimm’s book the author of the modernescpp blog.
Read more if you’d like to win C++ book bundle! :)
The book The C++ Standard Library
What every professional C++ programmer should know about the C++ standard library
Before C++17 we had a few, quite ugly looking, ways to write static if (if that works at compile time) in C++: you could use tag dispatching or SFINAE (for example via std::enable_if). Fortunately, that’s changed, and we can now take benefit of if constexpr!
Let’s see how we can use it and replace some std::enable_if code.
Saying that C++ has simple rules for variables initialization is probably quite risky :) For example, you can read Initialization in C++ is Bonkers : r/cpp to see a vibrant discussion about this topic.
But let’s try with just a small part of variables: static variables.
How are they initialized?
In Poland, it’s only a few hours until the end of the year, so it’s an excellent chance to make a summary of things that happened to C++! As you might guess the whole year was dominated by the finalization and publication of C++17. Yet, there are some other “big” things that happened.
Modern C++ stresses the use of RAII objects to manage resources. One of the easiest ways is just to start using unique_ptr across your code.
Let’s see how we can leverage this smart pointer type. I’ve come up with 5 (or more?) reasons where unique_ptr shines.
Intro One of my favourite features of modern C++ is smart pointers.