One of a powerful uses of std::variant is to implement State Machines. Some time ago I showed a simple example, but today we have something bigger. In today’s article by Nikolai Wuttke you’ll see how to leverage std::variant and build a space game!
This article is a guest post from Nikolai Wuttke
If you have a map of strings, like std::map<std::string, int> m; and you want to find some element by m.find("abc"). Do you have to pay the price and construct a std::string object? Can you optimize it?
Let’s have a look at one feature enabled in C++14 that might help optimize such container access.
Lambda expressions are one of the most powerful additions to C++11, and they continue to evolve with each new C++ language standard. In this article, we’ll go through history and see the evolution of this crucial part of modern C++.
The second part is available:
Lambdas: From C++11 to C++20, Part 2
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.
“C++ Attributes… what?”
There were almost 40% votes like that in my recent Twitter survey. Maybe It would be good to introduce that little-known feature?
There’s even a good occasion, as in C++17 we’ll get even more useful stuff connected with attributes.
Interested?
Intro Have you ever used __declspec, __attribute or #pragma directives in your code?
In May 2017 we got one more book about Modern C++! A Few weeks ago I got a copy from Packt Publishing, and today I’d like to write a few words about the book. In short: it’s a very good book! :)
But let’s see what’s inside…
The Book < a href=“http://amzn.
Some time ago I covered how to use custom deleters with smart pointers. The basic idea is to specify a dedicated method that will be called when a pointer is released. One logical application of custom deleters might be resource handles like files or the WinApi HANDLE type. Let’s see how can we implement such thing.
Maybe I’ll be boring with this note, but again I need to write that this was another good year for C++!
Here’s a bunch of facts:
Visual Studio 2015 was released with great support for C++14⁄17 and even more experimental features. Long-awaited GCC 5.0 was released at the beginning of the year.
This was a good year for C++!
Short summary (language features):
Clang supports C++14 GCC supports C++11 and most of C++14 (Full support in upcoming GCC 5.0) Intel 15.0 supports C++11 (some features on Linux/OSX only) Visual Studio tries to catch up with C++11, but it also introduces C++14 features as well… and it become (almost) free!
Some time ago I’ve seen an inspiring talk from CppCon 2013: “C++ Seasoning” by Sean Parent. One of the main points of this presentation was not to use raw loops. Instead, prefer to use existing algorithms or write functions that ‘wraps’ such loops. I was curious about this idea and searched for nice code examples.
C++11 conformance
GCC 4.81 - 100% Clang 3.3 - 100% Intel 14.0 - 84% Visual C++ 2013 - 66% Another year is almost over so it is a good time to check what is going on with C++. This time more stats and real data compared to my post from the previous year.