Welcome to the 6th episode of C++ Links available for C++ Stories subscribers.
See the best C++ stories from the past month.
Here’s the plan for today:
C++23 progress Parsing Command Line Arguments 3 New articles at C++stories in November + 8 Hot C++ News How to write a custom iterator in C++20 Read till the end to see an additional bonus :) Let’s start!
New Standard, new ways to initialize objects!
With C++20, we get a handy way of initializing data members. The new feature is called designated initializers and might be familiar to C programmers.
Let’s have a look at this small feature:
The basics Designated Initialization is a form of Aggregate Initialization.
Would you like to gain 20…35 or even 50% speed improvements when searching in associative containers? In this blog post, we’ll explore a technique called “heterogenous access” that offers such impressive speedups. We’ll explore ordered containers, and the support for unordered collections added recently in C++20.
Recap on heterogeneous lookup in ordered containers Let’s bring the example and have a look at how this feature works for ordered containers.
In the first part of our refactoring series, we covered (smart) pointers inside a function body; today, I’d like to show you cases for return types, data members, and a few others.
Let’s jump in and replace some new() and delete!
See the first part This article is the second in the series about refactoring with unique_ptr.
Smart pointers are very versatile and can hold pointers not only to single instances but also to arrays. Is that only a theoretical use case? or maybe they might be handy in some cases? Let’s have a look.
Smart pointers for T At C++ Stories, you can find lots of information about smart pointers - see this separate tag for this area.
In legacy code, you can often spot explicit new and delete lurking in various places and waiting to produce pointer-related issues. This blog post shows six patterns to improve that erroneous style and rely on modern techniques, especially unique_ptr and other helper standard types.
Bonus point 1: if possible, we’ll also look at some existing code from open source projects!
While learning how to use the new C++ Standard, I encountered several intriguing cases with smart pointers. Casting? Array handling? Passing to functions?
Let’s review some common concerns so that we don’t shoot yourself in the foot :)
I created this post back in 2013, and I updated it in 2014 and recently in 2021.
Smart pointers available since C++11 are an essential foundation for writing secure code in Modern C++. Thanks to RAII (Resource Acquisition Is Initialization), they allow you to work with pointers to allocate memory or other managed objects efficiently.
This blog post will show you the core points for working with those handy types.
What should happen when the data returned from a function is not valid? It might be an error or just how the system operates (embedded environment, a timeout). In this article, you’ll see a practical example from the robotics area where the vocabulary types from C++17 play important roles.
This is a guest post written by Rud Merriam:
Two keywords, constexpr and virtual - can those two work together? Virtual implies runtime polymorphism, while constexpr suggests constant expression evaluation. It looks like we have a contradiction, does it?
Read on and see why those conflicting terms might help us get simpler code.
A basic example Imagine that you work with some product list, and you want to check if a product fits in a given box size:
constexpr started small in C++11 but then, with each Standard revision, improved considerably. In C++20, we can say that there’s a culmination point as you can even use std::vector and std::string in constant expressions!
Let’s look at use cases, required features to make it work, and finally, one significant limitation that we might want to solve in the future.
C++20 added a couple of new attributes in the form of [[attrib_name]]. One of them - [[no_unique_address]] - can have surprising effects on the code! In this blog post, you’ll learn how to optimize your classes' layout and make some data members “disappear”. In most cases, it will be just one line of C++20 code.