The above field is supplemented with consent to receive a newsletter containing information and marketing content about the cppstories.com portal from Bartłomiej Filipek codebf based in Krakow. The consent may be withdrawn at any time. See the full Privacy Policy.
I’m happy to announce that my new book on C++ Initialization is published and finished!
Have a look at the background story and how to get it.
Updates: Go to the latest updates from 23rd Dec here, 30 new pages added!
Note: Initially, the book was called “Data Member Initialization in Modern C++”, but in September 2022, I updated it heavily and changed the title.
Structured bindings are a C++17 feature that allows you to bind multiple variables to the elements of a structured object, such as a tuple or struct, in a single declaration. This can make your code more concise and easier to read, especially when working with complex data structures. In this blog post, we will look at the basic syntax of this cool feature, its use cases, and even some real-life code examples.
It’s almost the end of the year! As usual, I started writing my “year” summary that I will publish on the 31st of December.
The survey has completed, thank your for 649 votes!
Stay tuned for the annual summary article on Dec 31st!
Yet, this article won’t be possible without your input!
As of C++20, we have four keywords beginning with const. What do they all mean? Are they mostly the same? Let’s compare them in this article.
const vs constexpr const, our good old fried from the early days of C++ (and also C), can be applied to objects to indicate immutability.
In this text you’ll learn about a few techniques and experiments with constexpr and constinit keywords. By exploring the string implementation, you’ll also see why constinit is so powerful.
What is SSO Just briefly, SSO stands for Short String Optimization. It’s usually implemented as a small buffer (an array or something similar) occurring in the same storage as the string object.
If you have a class with a regular data member like an integer or string, you’ll get all special member functions out of the box. But how about different types? In this article, we’ll look at other categories of members like unique_ptr, raw pointers, references, or const members.
Introduction In my book on “C++ Initialization” I recently wrote a chapter about so-called non-regular data members.
In September and October, I had the pleasure of running two meetings about C++20 features for my local Cracow C++ User Group!
Here are the slides and additional comments from the presentation.
The Talk Initially I did one presentation using my article on smaller C++ 20 features (20 Smaller yet Handy C++20 Features - C++ Stories).
The ISO Committee accepted and published the C++17 Standard in December 2017. In this mega-long article, I’ve built (with your help!) a list of all major features of the new standard.
Please have a look and see what we get!
Language Features New auto rules for direct-list-initialization static_assert with no message typename in a template template parameter Removing trigraphs Nested namespace definition Attributes for namespaces and enumerators u8 character literals Allow constant evaluation for all non-type template arguments Fold Expressions Unary fold expressions and empty parameter packs Remove Deprecated Use of the register Keyword Remove Deprecated operator++(bool) Removing Deprecated Exception Specifications from C++17 Make exception specifications part of the type system Aggregate initialization of classes with base classes Lambda capture of *this Using attribute namespaces without repetition Dynamic memory allocation for over-aligned data __has_include in preprocessor conditionals Template argument deduction for class templates Non-type template parameters with auto type Guaranteed copy elision New specification for inheriting constructors (DR1941 et al) Direct-list-initialization of enumerations Stricter expression evaluation order constexpr lambda expressions Different begin and end types in range-based for [[fallthrough]] attribute [[nodiscard]] attribute [[maybe_unused]] attribute Ignore unknown attributes Pack expansions in using-declarations Structured Binding Declarations Hexadecimal floating-point literals init-statements for if and switch Inline variables DR: Matching of template template-arguments excludes compatible templates std::uncaught_exceptions() constexpr if-statements SFINAE Tag dispatching if constexpr Library Features Merged: The Library Fundamentals 1 TS (most parts) Removal of some deprecated types and functions, including std::auto_ptr, std::random_shuffle, and old function adaptors Merged: The Parallelism TS, a.
In this short article, I’ll show you several techniques to improve raw loops. I’ll take an example of a reverse iteration over a container and then transform it to get potentially better code.
The loop expression is an essential building block of programming. When you iterate over a container in C++20, we have the following options:
In this article, I’ll show another technique that avoids mixing signed and unsigned types.
In my article Integer Conversions and Safe Comparisons in C++20 we learned about cmp_* integer comparison functions that allow us to compare various types of integer types. The functions are safe because they help with mixing signed and unsigned types.
Sometimes, If you mix different integer types in an expression, you might end up with tricky cases. For example, comparing long with size_t might give different results than long with unsigned short. C++20 brings some help, and there’s no need to learn all the complex rules :)
Conversion and Ranks Let’s have a look at two comparisons:
C++ is famous… or infamous for its complex initialization syntax. In this article, I’ll show you around 20 ways to initialize simple std::string variables. Can we somehow make it easier to understand?
Default values Have a look:
void foo() { std::string str0; std::string str1 {}; } We have two local variables (with automatic storage duration), str0 is default initialized, while str1 is value initialized.