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.
C++ has many dark corners and many caveats that can cause you to scratch your head in confusion. One of the issues we had until C++17 was the evaluation order of expressions. In this blog post, I’ll show you the new rules that we got in C++17 that made this complicated term much simpler and practical.
At C++Stories (and in my C++17 book) you can find several articles on Parallel Algorithms introduced in C++17. The examples included in those posts were usually relatively straightforward. How about writing something larger?
In this text, you’ll see how to build a tool that works on CSV files, parses lines into sales records and then performs calculations on the data.
I’m happy to announce that after few months of work, the C++ Lambda Story book got translation into Spanish!
Have a look at the background story and learn more about Lambdas :)
This post is possible with the effort of Javier Estrada.
Javier is a software developer living in sunny Southern California, and while he has flirted with Java and Python in the past, his true love is C++.
In April, we got a new book - from two Polish authors - Piotr and Adrian - on C++ Software Architecture. This one is fascinating and refreshing. While it won’t teach you all the latest C++ features or low-level tricks in our favorite language, it will move you to a higher level with architecture, building, patterns, design, and development for the cloud.
The work on C++23 continues! Without the face-to-face meetings, the Committee gathers online and discusses proposals and new additions to the language. See my latest report on what changed in C++ in April, May, and June 2021.
Disclaimer: the view presented here is mine and does not represent the opinion of the ISO C++ Committee.
More than a year ago I started my Patreon page! It was an experiment, and I’m pleased that it has a lot of benefits. In this short blog post, I’d like to make a small summary, share my thoughts and plans for the next year.
You can also learn how to get “one year” of my extra C++ content!
std::visit from C++17 is a powerful utility that allows you to call a function over a currently active type in std::variant.
In this post, I’ll show you how to leverage all capabilities of this handy function: the basics, applying on multiple variants, and passing additional parameters to the matching function.
Back in 2016, an intriguing article appeared on Reddit: “Do Experienced Programmers Use Google Frequently?”.
The author discussed if expert programmers use google more often than novice coders. He mentioned that using google is a good thing. It helps to find the best solutions, validate ideas, speed the development. Google nowadays seems to be a crucial part of any developer toolbox.
This blog post will show you how to create a robust and scalable logging library using lots of Modern C++ techniques. The author successfully used this code on Arduino embedded environment and various other production areas.
Let’s dive right in.
Written by Stephen Dolley
Stephen works with C++ commercial and government development teams to upgrade their skills and improve the expressiveness and robustness of their code.