News

Reactor -- Rainer Grimm

Event-driven applications, such as GUIs or servers, often apply the architecture pattern Reactor. A Reactor can accept multiple requests simultaneously and distribute them to different handlers.

Reactor

by Rainer Grimm

From the article:

The Reactor Pattern is an event-driven framework to concurrently demultiplex and dispatch service requests to various service providers. The requests are processed synchronously.

Problem

A server should

  • be extendable to support new or improved services
  • be performant, stable, and scalable
  • answer several client requests simultaneously

The application should be hidden from multi-threading and synchronization challenges

Solution

  • Each supported service is encapsulated in a handler
  • The handlers are registered within the Reactor
  • The Reactor uses an event demultiplexer to wait synchronously on all incoming events
  • When the Reactor is notified, it dispatches the service request to the specific handler

CppCon 2022 Best Practices Every C++ Programmer Needs to Follow -- Oz Syed

Cpp22-Syed.pngRegistration is now open for CppCon 2023! The conference starts on October 1 and will be held in person in Aurora, CO. To whet your appetite for this year’s conference, we’re posting videos of some of the top-rated talks from last year's conference. Here’s another CppCon talk video we hope you will enjoy – and why not register today for CppCon 2023!

Lightning Talk: Best Practices Every C++ Programmer Needs to Follow

by Oz Syed

Summary of the talk:

In this session, learn some of the best practices that every C++ programmer needs to ensure successful completion of a project. Learn tips and tricks to speed up your workflow, prevent errors and improve performance.

Q&A - C++ Initialization -- Bartlomiej Filipek

Last time I showed a couple of questions about initialization. Try them here if you haven’t already. In this article, I’ll show you the answers and add more notes about initialization in C++.

Q&A - C++ Initialization

by Bartlomiej Filipek

From the article:

Will this code work in C++11?
struct User { std::string name = "unknown"; unsigned age { 0 }; };
User u { "John", 101 };
  1. Yes, the code compiles in C++11 mode.
  2. The code compiles starting with C++14 mode.
  3. The code doesn’t compile even in C++20.

CppCon 2022 C++ in Constrained Environments -- Bjarne Stroustrup

Cpp22-Stroustrup.pngRegistration is now open for CppCon 2023! The conference starts on October 1 and will be held in person in Aurora, CO. To whet your appetite for this year’s conference, we’re posting videos of some of the top-rated talks from last year's conference. Here’s another CppCon talk video we hope you will enjoy – and why not register today for CppCon 2023!

C++ in Constrained Environments

by Bjarne Stroustrup

Summary of the talk:

C++ is widely used in constrained and/or critical applications and infrastructure components. How do we manage to use a large multi-purpose language in such environments? How can we better use facilities and techniques from modern C++ (C++11, C++14, C++17, C++20, and beyond)? The best answer is not “use only facilities available in C and C++ in 1985.”

This talk focuses on a top-down approach to achieve simplicity, maintainability, performance, and various forms of safety. It touches upon the C++ Core Guidelines, compile-time computation, type-and-resource safety, type deduction, the span and chrono standard libraries, and error handling.

The Obvious Final Step -- Andrzej KrzemieĊ„ski

During the construction of an XML file when you write an element, it is obvious that the last thing that you do is to write the closing tag. By obvious we mean: writing it down adds no new information (there is no other possible final instruction for this task), and it would be a bug if this instruction wasn’t there.

The Obvious Final Step

by Andrzej Krzemieński

From the article:

The title may be misleading, as I had to invent a new short term for the pattern that occurs in the code once in a while. Example first:

// write an element of an XML file

xml.begin_element("port");
xml.attribute("name", name);
xml.attribute("location", loc);
xml.end_element("port");  // <-- the obvious final step

Defining Interfaces in C++: Concepts Versus Inheritance -- Daniel Lemire

DanielLemire.pngIn a previous blog post, Daniel Lemire showed how you could define ‘an interface’ in C++ using concepts and stated that he did not take into account inheritance as a strategy. He does so here.

Defining Interfaces in C++: Concepts Versus Inheritance

by Daniel Lemire

From the article:

In a previous blog post, I showed how you could define ‘an interface’ in C++ using concepts. For example, I can specify that a type should have the methods has_next, next and reset:

template <typename T>
concept is_iterable = requires(T v) {
                        { v.has_next() } -> std::convertible_to<bool>;
                        { v.next() } -> std::same_as<uint32_t>;
                        { v.reset() };
                      };

CppCon 2022 Dependency Injection for Modern C++ -- Tyler Weaver

Cpp22-Weaver.pngRegistration is now open for CppCon 2023! The conference starts on October 1 and will be held in person in Aurora, CO. To whet your appetite for this year’s conference, we’re posting videos of some of the top-rated talks from last year's conference. Here’s another CppCon talk video we hope you will enjoy – and why not register today for CppCon 2023!

Lightning Talk: Dependency Injection for Modern C++

by Tyler Weaver

Summary of the talk:

DI is a fancy OO term with an even more complex set of tooling to solve a problem that higher order functions solve in a nicer way. In this talk I'll demonstrate using std::function for dependency injection and talk about how taking functions as a parameter is nicer and more first class in C++ than inheritance or complex mocking libraries.

Basic HTTP and WebSocket Programming with Boost.Beast -- Richard Thomson

Utah C++ Programmers has released a new video:

Basic HTTP and WebSocket Programming with Boost.Beast

by Richard Thomson

From the video description:

Boost.Beast is a C++ header-only library serving as a foundation for writing interoperable networking libraries by providing low-level HTTP/1, WebSocket, and networking protocol vocabulary types and algorithms using the consistent asynchronous model of Boost.Asio.

This month, Richard Thomson will give us an introduction to Beast and the facilities it provides for HTTP and WebSocket applications. We will look at an example of implementing a REST API for a simple CRUD (Create, Read, Update, Delete) style database. We will revisit the comic book database example we have used in previous REST API presentations.

https://www.youtube.com/watch?v=gVmwrnhkybk

The Case of string_view and the Magic String -- Giovanni Dicanio

Someone learned about std::string_view, and started replacing instances of std::string const& with string_views in their C++ code base. As a result of that, a subtle bug shows up!

The Case of string_view and the Magic String

by Giovanni Dicanio

From the article:

(...) The code is recompiled and executed. But, unfortunately, now the output has changed! What’s going on here? Where does that “magic string” come from?

Sign Up for the free Pure Virtual C++ 2023 Conference -- Sy Brand

PureVirtualC++.pngEvery year we run Pure Virtual C++: a free one-day virtual conference for the whole C++ community. Next month we’re doing it again! Sign-up for free to get access to our five live sessions and a host of pre-conference content.

Sign Up for the free Pure Virtual C++ 2023 Conference

by Sy Brand

From the article:

The live event will run June 6th 13:00-16:00 UTC. Videos will be available to stream for free on YouTube after the conference.

The live sessions will be:

  • C++ Compiler Errors for Humans with Sy Brand
  • Address Sanitizer continue_on_error with Jim Radigan
  • Value-Oriented Programming with Tony Van Eerd
  • Productive Cross-Platform and Game Development in Visual Studio with Sinem Akinci and David Li
  • Build Time Reflection with C++ in Year 2023 with Gabriel Dos Reis