Reflection-based JSON in C++ at Gigabytes per Second -- Daniel Lemire

portrait2018.jpgJSON is a widely-used format for data exchange, but in C++, handling JSON efficiently can be challenging. While current solutions like simdjson offer high-speed processing, upcoming features in C++26, such as powerful reflection, promise to simplify and accelerate the serialization and deserialization of JSON, making it both faster and more convenient for developers.

Reflection-based JSON in C++ at Gigabytes per Second

by Daniel Lemire

From the article:

JSON (JavaScript Object Notation) is a popular format for storing and transmitting data. It uses human-readable text to represent structured data in the form of attribute–value pairs and arrays. E.g., {"age":5, "name":"Daniel", toys:["wooden dog", "little car"]}. Ingesting and producing JSON documents can be a performance bottleneck. Thankfully, a few JSON parsers such as simdjson have shown that we can process JSON at high speeds, reaching gigabytes per second.

However, producing and ingesting JSON data can remain a chore in C++. The programmer often needs to address potential errors such as unexpected content.

Yet, often, the programmer only needs to map the content to and from a native C/C++ data structure.

User-Defined Formatting in std::format – Part 3 -- Spencer Collyer

logo.pngWe’ve seen formatting for simple classes and more complicated types. Spencer Collyer finishes his series by showing us how to apply specific formatting to existing classes.

User-Defined Formatting in std::format – Part 3

by Spencer Collyer

From the article:

In the previous articles in this series [Collyer24a], [Collyer24b] I showed how to write classes to format user-defined classes and container classes using the std::format library.

In this article I will show you how to create format wrappers, special purpose classes that allow you to apply specific formatting to objects of existing classes.

A note on the code listings: The code listings in this article have lines labelled with comments like // 1. Where these lines are referred to in the text of this article it will be as ‘line 1’ for instance, rather than ‘the line labelled // 1’.

Format wrappers

I’d now like to introduce a type of class which I call ‘format wrappers’. A format wrapper is a very simple class which wraps a value of another type. They exist purely so that we can define a formatter for the format wrapper. The idea is that the formatter will then output the wrapped value using a specific set of formatting rules. Hopefully this will become clearer when we discuss the Quoted format wrapper later.

A format wrapper is a very simple class, which normally consists of just a constructor taking an object of the wrapped type, and a public member variable holding a copy or reference to that value. They are intended to be used in the argument list of one of std::format’s formatting functions, purely as a way to select the correct formatter.

Adding trainings to Meeting C++ 2024

Meeting C++ now offers 4 trainings that align with Meeting C++ 2024, and will be held in the last week of November.

Adding C++ trainings to Meeting Cpp 2024

by Jens Weller

From the article:

Trainings listing

    C++ for C Developers - Migrating from C to C++ - a two day training by Slobodan Dmitrovic starting November 25th
    Program with GUTs - a half day training by Kevlin Henney on November 25th
    Generic programming in C++ with templates and auto - full day training by Nicolai Josuttis on November 28th
    Concepts, Ranges, and Views - The New Way of Programming in C++ - full day training by Nicolai Josuttis on November 29th

These 4 trainings focus on various important current aspects of C++. From the migration to C++ from C, which is also a great course if you migrate to Modern C++ from "C with classes" like code. Or a refresher on unit testing by Kevlin Henney himself. Nicolai Josuttis gives a two day training, which is also available as single days: on the first day generic programming with templates and auto is bringing you a referesher, while focusing on C++20 Concepts, Ranges and Views on the next day. I've made the decision that prices for trainings are now fixed, half/full day trainings are 499 € and two day trainings are 999 €, this already includes taxes and all fees from the ticketshop. Attending the trainings will let you learn great new ways to think about your code and it gives support Meeting C++!

Parsing C++

The PVS-Studio Team invite you to the webinar. Date: October 10, 2024, 12:00 PM UTC+1.

Parsing C++

by Yuri Minaev

Summary of the talk:

In this webinar, we will discuss grammars in С++ and how they work. We will talk about different kinds of parsers and why С++ is difficult to parse. We will also share some tricks to avoid extreme slowdown. Speaker: Yuri Minaev.

CppCon 2024 High-Performance Numerical Integration in the Age of C++26 -- Vincent Reverdy

Registration is now open for CppCon 2024! The conference starts on September 15 and will be held in person in Aurora, CO. To whet your appetite for this year’s conference, we’re posting some upcoming talks that you will be able to attend this year. Here’s another CppCon future talk we hope you will enjoy – and register today for CppCon 2024!

High-Performance Numerical Integration in the Age of C++26

Friday, September 20 13:30 - 14:30 MDT

by Vincent Reverdy

Summary of the talk:

Could we revisit numerical integrators in the light of C++26 and bring more genericity, performance, and expressivity to the domain? In this talk, we will explore how modern C++ techniques can add something new and relevant to one of the oldest and most basic task of scientific computing: the integration of systems of equations. We will examine, in particular, how most numerical integrators can be derived from a small set of first principles that can be easily mapped onto C++ concepts and composable algorithmic building blocks. One of the goal of the approach introduced in this presentation will be to achieve as much as possible with the simplest and smallest amount of code. C++23 and C++26 programming techniques, including reflection, will be leveraged to transfer some of the burden of implementation to the compiler while still ensuring maximum performance.

In practice, the talk will combine aspects of high-performance computing, numerical methods, and software architecture. We will start by summarizing recent discoveries made in applied mathematics on Runge-Kutta methods, linear multistep methods, and general linear methods to see how it can help design better abstractions that can be translated into C++ concepts. We will then examine how a few carefully crafted algorithmic building blocks can be combined to generate the whole diversity of numerical integrators from first principles. The automation of this approach using C++23 and C++26's reflection to make the compiler generate highly efficient code will be then discussed in great length. Next, we will dive into parallelization strategies, including distributed ones as well as heterogenous computing. Some perspectives will also be given on the possibility for the compiler to branch on the best integrator given the mathematical properties of a system of equations as well as ways to derive new integrators at compile-time.

To illustrate our approach, we will examine the behavior and performance of numerous integrators on several real-world problems including a supercomputing N-body code for cosmology that simulates the gravitational dynamics of large scale astrophysical structures in an expanding Universe. A great care will be taken to make all the code and examples as reproducible and standalone as possible so that most of the presented content can simply be copied and pasted to make it work everywhere. Finally, even if the talk will focus on the particular case of numerical integration, the methodology presented in this talk will be applicable everywhere in scientific computing and beyond to achieve better software architecture in technical contexts.


Vincent Reverdy is a Full Researcher in Computer Science and Astrophysics at French Center for Scientific Research (CRNS) and located at the Annecy Laboratory for Particle Physics (LAPP) in the French Alps. He also is a member of the French delegation to the C++ Standards Committee. After a PhD at the Paris Observatory in 2014 on the topic of numerical cosmology and general relativity for which he explored extensively advanced metaprogramming techniques, he joined the University of Illinois at Urbana-Champaign in the US. There, he led an interdisciplinary research group in both computer science and computational astrophysics, trying to bridge the gap between programming languages and computational sciences. In late 2019 he moved back to France to continue to work on software architecture aspects related to astrophysics, and joined CNRS in January 2022 to lead long-term research aiming at building bridges between theoretical computer science including type theory and category theory on one side, and computational sciences with a focus on numerical astrophysics on the other side. Finally, as a member of the C++ committee, he has been working extensively on low-level programming components, including bit manipulation, as well as mathematical abstractions.

C++ programmer's guide to undefined behavior: part 5 of 11

Your attention is invited to the fifth part of an e-book on undefined behavior. This is not a textbook, as it's intended for those who are already familiar with C++ programming. It's a kind of C++ programmer's guide to undefined behavior and to its most secret and exotic corners. The book was written by Dmitry Sviridkin and edited by Andrey Karpov.

C++ programmer's guide to undefined behavior: part 5 of 11

by Dmitry Sviridkin

From the article:

However, all this fuss with removing and adding const anywhere in the code eliminates this set of optimizations. So, a repeated access by a constant reference to the same data member or member function doesn't need to be cached at all. Note. It's worth mentioning that programmers have unrealistic expectations about the compiler optimizing code when they add more const. Here's a good note on the topic: "Why const Doesn't Make C Code Faster".

CppCon 2024 Contracts for C++ -- Timur Doumler

Registration is now open for CppCon 2024! The conference starts on September 15 and will be held in person in Aurora, CO. To whet your appetite for this year’s conference, we’re posting some upcoming talks that you will be able to attend this year. Here’s another CppCon future talk we hope you will enjoy – and register today for CppCon 2024!

Contracts for C++

Wednesday, September 18 14:00 - 15:00 MDT

by Timur Doumler

Summary of the talk:

Design by Contract is a very effective approach for writing safer, more correct programs. It has been successfully implemented in programming languages like Eiffel and Ada. Attempts to add a Contracts facility to C++ have a long and storied history spanning two decades. Since the last attempt to standardise Contracts (for the C++20 Standard) has failed, SG21 — the Contracts Study Group on the C++ Standard Committee – has been working on a new design, the so-called Contracts MVP, which is now essentially feature-complete and on track to make it into the upcoming C++26 Standard.

In this talk, we present the current design of the Contracts MVP targeting C++26. We discuss preconditions, postconditions, assertions, contract-violation handling and much more. We consider how the Contracts MVP provides a superior replacement for custom assertion macros and, when used correctly, can significantly improve the safety and correctness of your code.


Timur Doumler is the co-host of CppCast and an active member of the ISO C++ standard committee, where he is currently co-chair of SG21, the Contracts study group. Timur started his journey into C++ in computational astrophysics, where he was working on cosmological simulations. He then moved into the audio and music technology industry, where he has been working for over a decade and co-founded the music tech startup Cradle. In the past, Timur also worked for JetBrains, first as a developer on CLion's C++ parser and later as a Developer Advocate for C++ developer tools. Currently, Timur lives in Finland, where he is organising the monthly C++ Helsinki meetup. Timur is passionate about clean code, good tools, low latency, and the evolution of the C++ language.

Qt and Trivial Relocation (Part 5) -- Giuseppe D'Angelo

In previous posts, we've explored relocation, trivial relocation, and their use in optimizing data structures like vector-like containers. We've also examined how trivial relocation relates to move assignments, enabling further optimization of operations like swaps and algorithms such as std::sort and std::rotate.

Qt and Trivial Relocation (Part 5)

by Giuseppe D'Angelo

From the article:

Is trivial relocation allowed in Standard C++?

That’s probably a question we should have asked as soon as we started this journey. Of course, the answer is no, it is not allowed!

Remember how trivial relocation works: we use memcpy a source object(‘s representation) into some storage, and claim that operation realizes the equivalent of move-constructing the source into that storage, plus destroying the source.

The problem is that one can’t just put data into some storage and pretend that an object exists in there. This is only allowed for a specific set of types, such as trivially copyable types. (Note that if a type is trivially copyable, then Qt automatically considers it trivially relocatable.)

However, as we have discussed, many interesting types (QStringstd::vectorstd::unique_ptr, …) are not trivially copyable, but they would still benefit from trivial relocatability.

CppCon 2024 Data Structures That Make Video Games Go Round -- Al-Afiq Yeong

Registration is now open for CppCon 2024! The conference starts on September 15 and will be held in person in Aurora, CO. To whet your appetite for this year’s conference, we’re posting some upcoming talks that you will be able to attend this year. Here’s another CppCon future talk we hope you will enjoy – and register today for CppCon 2024!

Data Structures That Make Video Games Go Round

Friday, September 20 14:45 - 15:45 MDT

by Al-Afiq Yeong

Summary of the talk:

Modern video games are complex beasts that contains multiple systems interacting with one another storing, transferring and processing large sets of data in real time. While some data structures from the standard library such as the std::vector gets you by 90% of the time you need to store and process data, there will be the occasional 10% that requires a unique take.

This presentation aims to discuss the unique data structures that are commonly used in video games / game engines that caters to the occasional 10%. We will go over several systems outlining their requirements, constraints and present custom data structures that gets the job done.


Al-Afiq Yeong is a Software Engineer currently working in the Engine team at Criterion. His day to day involves performance monitoring games, making sure memory gets managed efficiently and developing new technologies that will empower future games developed with Frostbite. Prior to games, he was a full stack developer maintaining and building web apps in the service, nuclear and finance industry. Outside work, he spends most of his time writing his own rendering engine while trying to avoid the allure of the games sitting in his Steam library.

Understanding the inner workings of C++ smart pointers -- Andreas Fertig

me.pngPreviously, we explored a basic implementation of unique_ptr in "Understanding the Inner Workings of C++ Smart Pointers - The unique_ptr." Now, let's enhance that model by incorporating a custom deleter, similar to what the Standard Library provides.

Understanding the Inner Workings of C++ Smart Pointers - The Unique_ptr with Custom Deleter

by Andreas Fertig

From the article:

Let's first establish why somebody would want a custom deleter.

One example is that the object was allocated via a local heap, and such must be returned by calling the corresponding deallocation function.

Another example is fopen. This function returns a FILE* object that you are supposed to delete by calling fclose. A classic job for a unique pointer. But you cannot call delete on the FILE pointer.

Here are two examples of using a unique_ptr with a custom deleter.

void MyDeleter(Object* ptr)
{
  delete ptr;
}

unique_ptr<Object> alfred{new Object{}};
static_assert(sizeof(alfred) == sizeof(void*));

unique_ptr<Object, decltype(MyDeleter)> robin{new Object{}, &MyDeleter};
static_assert(sizeof(robin) == sizeof(void*) * 2);
 
Oh yes, the first object, alfred, doesn't provide a custom deleter. Only robin does. Behind the curtains, both do. Let's look at a modified unique_ptr implementation that handles the custom deleter case.