Tag Archive for C++23

“Professional C++, 6th Edition” Released

I’m proud to announce that the new edition of my book “Professional C++, 6th Edition” is finished 🙂
It has been updated to the C++23 standard and uses certain C++23 features throughout all examples.

It is published by Wiley/Wrox, and available on Amazon.

Official Description

Expand your C++ knowledge quickly and efficiently with this advanced resource

In the newly revised sixth edition of Professional C++, veteran software engineer and developer Marc Gregoire delivers yet another volume that raises the bar for advanced programming manuals. Covering almost all features of the new C++ standard codenamed C++23, the book offers case studies with working code that’s been tested on Windows and Linux.

As the leading resource for dedicated and knowledgeable professionals seeking to advance their C++ skills, this book provides resources that help readers:

  • Master new features of the latest standard, C++23
  • Maximize C++ capabilities with effective design solutions
  • Discover little-known elements and learn about pitfalls and what practices to avoid
  • Grasp testing and debugging best practices
  • Learn about tips and tricks for efficiency and performance

C++ is a complex language. Professional C++, 6th Edition, allows dedicated practitioners to remain current and abreast of the latest developments and advances.


Slides of My Presentation at CppCon 2023: C++23 An Overview of Almost All New and Updated Features

This year at CppCon 2023, I gave the following session:

  • “C++23 An Overview of Almost All New and Updated Features”

You can find the slides of the session below.


Next BeCPP UG Meeting Planned for May 11th, 2023

I’m happy to announce that the next meeting of the Belgian C++ Users Group is planned for Thursday May 11th, 2023 at 18:00 at Twikit.

Twikit ( https://www.twikit.com/ ) is sponsoring this event by providing the location, drinks and catering.

Twikit Logo

The agenda is as follows:

  • 18:00: Reception with food.
  • 18:30: Session 1: C++23 – What’s in it for You? (Marc Gregoire)
    C++23, the next release of the C++ standard, introduces new features to the core language and to the Standard Library. This session will bring you up to date with the latest features coming with this new release.
    The session includes core language topics such as consteval if statements, multidimensional subscript operators, decay copy, unreachable code, and more. New Standard Library features that will be shown include monadic operations for std::optional, std::flat_map, std::flat_set, a stacktrace library, changes to the ranges library, improvements to std::format, std::expected, and many more.
  • 19:30: Break
  • 19:45: Session 2: Emscripten, what and how? (Dave De Breuck)
    This talk will give a brief introduction of Emscripten itself and explain how Emscripten, an LLVM-based compiler, converts C++ to JavaScript, which lets you run a C++ codebase on the web at near-native speed.
  • 20:45: Introduction to Twikit, followed by a drink.

The event is free for everyone, but you need to register for it.

There are 60 seats available for this event.

Note: The deadline for registrations is May 9th, 2023!


C++23: Multidimensional Subscript Operator

When you have a class representing multidimensional data, providing access to a specific element in this multidimensional space is often done by providing an operator() with as many parameters as there are dimensions. You had to resort to operator(), because operator[] only supported a single index.

That’s now history, as C++23 introduces the multidimensional subscript operator. Providing such an operator for your class is straightforward:

import std;

template <typename T>
class Matrix
	Matrix(std::size_t rows, std::size_t cols)
		: m_rows{ rows }, m_cols{ cols }
		m_data.resize(rows * cols);

	T& operator[](std::size_t x, std::size_t y) { return m_data[x + y * m_cols]; }

	std::size_t m_rows;
	std::size_t m_cols;
	std::vector<T> m_data;

The class can be tested as follows:

const std::size_t Rows{4};
const std::size_t Cols{4};
Matrix<int> m{ Rows, Cols };
std::size_t counter{ 0 };
for (std::size_t y{ 0 }; y < Rows; ++y)
	for (std::size_t x{ 0 }; x < Cols; ++x)
		m[x, y] = ++counter;

for (std::size_t y{ 0 }; y < Rows; ++y)
	for (std::size_t x{ 0 }; x < Cols; ++x)
		std::print("{} ", m[x, y]);

C++23: “Hello World!” with Modern C++23

Whenever you learn a new programming language, the first program you write is often a “Hello World!” program that simply prints out “Hello World!” to the console. Up to now, for C++, this usually was something along the following lines:

#include <iostream>

int main()
    std::cout << "Hello World!" << std::endl;

This code snippets imports the required header, <iostream>, and uses std::cout to output text to the standard console.

With modern C++23, this simple program looks quite a bit different:

import std;

int main()
    std::println("Hello World!");

What has changed?

  • Instead of including the exact headers that are required, you simply import a single named module, std, provided by the standard.
  • Instead of using std::cout, stream insertion operators, and std::endl, you simply use std::println().

Unfortunately, at the time of this writing, there are no compilers yet supporting all the above new features, but soon there will be.

For the time being, if your compiler doesn’t support the named module std yet, you can simulate it yourself by writing your own named module called std. You can do this by writing a code file called std.cppm with the following contents:

export module std;

export import <iostream>;

You can extent this std.cppm named module with whatever header you need in your program.

Secondly, if your compiler does not support std::println() yet, you can simulate it with your own print module in a print.cppm file, e.g.:

export module print;

import <string_view>;
import <iostream>;
import <format>;

namespace std
    export template <typename... Args>
    void println(std::string_view sv, Args&&... args)
        std::cout << std::vformat(sv, std::make_format_args(args...)) << std::endl;

Warning: this is a very basic simulation of std::println(), which does not support all the features of the real std::println()!.


Slides of My Presentation at CppCon 2022

This year at CppCon 2022, I gave the following session:

  • “C++23 What’s In It For You?”

You can find the slides of the session below.


Slides of My Presentation at CppEurope 2022 – A Look Ahead At C++23

On 24th of May 2022 I gave the following session at CppEurope 2022:

  • “A Look Ahead At C++23”

You can find the slides of the session below.

Here’s the official announcement slide: