Articles & Books

Simple Usage of C++20 Modules -- Victor Zverovich

SimpleUsage-Zverovich.jpgIn my previous post I showed how to compile {fmt} as a C++20 module with clang. Although taking only two commands, ideally it’s not something you should be doing manually. So in this post, I’ll talk about module support in CMake, everyone’s favorite not a build system.

Simple Usage of C++20 Modules

by Victor Zverovich

From the article:

My first attempt was to use the CMake’s built-in functionality advertised in “import CMake; C++20 Modules”. And after some struggle I made it to work with clang but unfortunately it was very limited. Here are some of the problems and limitations that I discovered:

  1. It only worked with ninja and while I don’t have anything against this build system it’s an extra hassle to get this additional dependency installed while make is usually available by default. This restriction also likely means that you cannot use such a CMake config with IDEs.
  2. Native CMake support only worked with clang 16 while the fmt module can be built manually with clang 15.
  3. It required the latest version of CMake and a lot of ceremony to set up, including some incomprehensible things.
  4. There were issues in dynamic dependency extraction both in clang-scan-deps and CMake itself.

 

Functional Exception-less Error Handling with C++23’s Optional and Expected -- Sy Brand

This post is an updated version of an article from five years ago, now that everything Sy talked about is in the standard and implemented in Visual Studio.

Functional Exception-less Error Handling with C++23’s Optional and Expected

by Sy Brand

From the article:

In software things can go wrong. Sometimes we might expect them to go wrong. Sometimes it’s a surprise. In most cases we want to build in some way of handling these misfortunes. Let’s call them disappointments.

std::optional was added in C++17 to provide a new standard way of expressing disappointments and more, and it has been extended in C++23 with a new interface inspired by functional programming.

C++23’s New Fold Algorithms -- Sy Brand

This post explains the benefits of the new “rangified” algorithms, talks you through the new C++23 additions, and explores some of the design space for fold algorithms in C++.

C++23’s New Fold Algorithms

by Sy Brand

From the article:

C++20’s algorithms make several improvements to the old iterator-based ones. The most obvious is that they now can take a range instead of requiring you to pass iterator pairs. But they also allow passing a “projection function” to be called on elements of the range before being processed, and the use of C++20 concepts for constraining their interfaces more strictly defines what valid uses of these algorithms are. These changes allow you to make refactors like:

// C++17 algorithm
cat find_kitten(const std::vector<cat>& cats) {
    return *std::find_if(cats.begin(), cats.end(),
        [](cat const& c) { return c.age == 0; });
}

// C++20 algorithm
cat find_kitten(std::span<cat> cats) {
    return *std::ranges::find(cats, 0, &cat::age);
}

Broker -- Rainer Grimm

The Broker Pattern structures distributed software systems that interact with remote service invocations. It is responsible for coordinating the communication, its results, and exceptions.

Broker

by Rainer Grimm

From the article:

The Broker Pattern from the book  "Pattern-Oriented Software Architecture, Volume 1" helps solve many challenges of distributed systems, such as finding the appropriate service provider, communicating with them securely, using the right programming language, or dealing with errors. This will not go into the details. It should only provide you with a rough idea of the Broker Pattern. For further information, study the pattern in the book "Pattern-Oriented Software Architecture, Volume 1".

C++20 Lambda Extensions: Lambda Default Constructors -- Gajendra Gulgulia

GajendraGulgulia.pngIn this article, I cover Default constructuctible lambdas.

C++20 Lambda Extensions: Lambda Default Constructors

by Gajendra Gulgulia

From the article:

1. Default construction: Very short background

In C++ objects are default constructible if they satisfy certain conditions. The set of conditions vary and I’ll not go into all the details of what they are as it will be out of the scope of this article. Consider the Person class with default constructor in line 3. 

class Person{
    public:
         Person() = default;   //default constructor
         Person(std::uint32_t age, std::string name):
         age_{age}, name_{name}
         { /*empty body */ }

         std::string getName()  const { return name_;}
         std::uint32_t getAge() const { return age_; }
        
        void setAge(const std::uint32_t age) {age_ = age;}
        void setName(const std::string& name){name_ = name;}
   private:
       std::uint32_t age_{};
       std::string name_{};
};

C++23’s New Fold Algorithms -- Sy Brand

If you want to find out more about the std::ranges::fold_* algorithms in C++23, here's a new post for you.

C++23’s New Fold Algorithms

By Sy Brand

From the article:

C++20 added new versions of the standard library algorithms which take ranges as their first argument rather than iterator pairs, alongside other improvements. However, key algorithms like std::accumulate were not updated. This has been done in C++23, with the new std::ranges::fold_* family of algorithms.

Announcing Meeting C++ 2023

Today this years edition of the Meeting C++ conference has been announced:

Announcing Meeting C++ 2023

by Jens Weller

From the article:

This years Meeting C++ conference will be held in Berlin on the 12th - 14th November!

Like in the previous year, we will be hosting 3 tracks on site and plan for a prerecorded online track. The online part also will include live streams from all onsite talk tracks.

Tickets are available via event brite...

 

Layers -- Rainer Grimm

The layers pattern splits a task into horizontal layers. Each layer has a specific responsibility and provides a service to a higher layer.

Layers

by Rainer Grimm

From the article:

The Layers Pattern is an architectural pattern that helps, according to the book "Pattern-Oriented Software Architecture, Volume 1", to bring structure into the mud.

Although not specified, most layered architectures consist of three or four layers. Each layer is independent of the other layer. In the pure version, a layer can only access its layer below. A layer can not access its upper layer because it would create additional dependencies and complicates the control structure. Additionally, another application cannot easily use a layer that depends on an upper layer. A layer often provides its functionality by implementing the Facade Pattern. The Facade Pattern provides a simplified interface to a complex system.

C++20 Lambda Expressions, Non-type Template Parameters, Constraints and Concepts -- Gajendra Gulguli

How to write a class and fuction template declaration which uses functions and lambda expressions as non-type template parameter.

C++20 Lambda Expressions, Non-type Template Parameters, Constraints and Concepts

by Gajendra Gulgulia

From the article:

In this article I will explain how to write a class and fuction template declaration which uses functions and lambda expressions as non-type template parameter.

Function as Non-Type-Template-Parameter ( NTTP henceforth) looks like below in class and function template as of C++17.

template<auto FunctionType> class Foo{
// ...
};

template<atuo FunctionType>
void foo();