CppCon 2024 Guide to Linear Algebra With the Eigen C++ Library -- Daniel Hanson

guidetolinear-hanson.pngRegistration is now open for CppCon 2025! 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 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 2025!

Guide to Linear Algebra With the Eigen C++ Library

by Daniel Hanson

Summary of the talk:

Linear algebra is an essential part of scientific programming, particularly in domains such as quantitative finance, data science, physics, and medical research.  It is also relevant to imaging in game development.  As C++ did not have all the convenient built-in multidimensional array capabilities and supporting libraries that came with typical Fortran platforms, scientific programmers making the transition to C++ back in the late 1990’s and early 2000's often found themselves in an inconvenient situation with limited options.  These included building up this functionality mostly from scratch, wrestling with interfaces to numerical Fortran libraries such as BLAS and LAPACK, or somehow convincing management to invest in a third-party commercial C++ linear algebra library.

The situation has improved substantially over the years with the development of several well-regarded open-source linear algebra libraries for C++.  One in particular that has become popular, first released in 2006, is the Eigen library.  It has been adopted for use within both the TensorFlow machine learning library and the Stan Math Library, as well as at CERN, and it can also be found in the implementation of high-performance quantitative trading strategies in C++.

In this talk, we will examine the setup and basics of the Eigen library, followed by a discussion of some of its more advanced features, including applications of matrix decompositions frequently used in quantitative work, as well as its compatibility with STL algorithms.  It will conclude with an overview of how it can be used within the context of the C++26 BLAS interface proposal (P1673), via an interface with std::mdspan now available in C++23.

Using C++ type aliasing to avoid the ODR problem with conditional compilation part 1 -- Raymond Chen

RaymondChen_5in-150x150.jpgC++’s One Definition Rule (ODR) can cause subtle and hard-to-detect issues when compile-time switches lead to inconsistent definitions across translation units. However, by using type aliases and template instantiation, we can sidestep these violations—giving each module its own definition without triggering undefined behavior.

Using C++ Type Aliasing to Avoid the ODR Problem with Conditional Compilation, Part 1

by Raymond Chen

From the article:

Some time ago, I discussed the C++ concept of ill-formed no diagnostic required (IFNDR). A common accidental source of this is violating the One Definition Rule (ODR) by defining a class or function differently based on compile-time switches.

// widget.h

struct Widget
{
    Widget();

    void SetName(std::string const& name);

    ⟦ more stuff ⟧

#ifdef EXTRA_WIDGET_DEBUGGING
    Logger m_logger;

    void Log(std::string const& message) {
        m_logger.log(message);
    }
#else
    void Log(std::string const& message) {
        // no extra logging
    }
#endif

    std::string m_name;
};

If one .cpp file is compiled with extra widget debugging enabled, but another is compiled with extra widget debugging disabled, and they are linked together, then you have a One Definition Rule violation because the Widget structure and the Widget::Log method have conflicting definitions.

But all is not lost.

CppCon 2024 Amortized O(1) Complexity in C++ -- Andreas Weis

amortized-weis.pngRegistration is now open for CppCon 2025! 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 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 2025!

Lightning Talk: Amortized O(1) Complexity in C++

by Andreas Weis

Summary of the talk:

We will take a quick look at how amortized analysis for algorithms works. We will use two examples from the standard library to demonstrate this and show how in one place, the standard's interpretation of amortized constant complexity is at odds with the usual use of the term.

CppCon 2024 Using PMR in C++ Embedded Systems for Functional Safety -- Scott Dixon

pmr-dixon.pngRegistration is now open for CppCon 2025! 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 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 2025!

Lightning Talk: Using PMR in C++ Embedded Systems for Functional Safety

by Scott Dixon

Summary of the talk:

Dynamic memory is often disallowed in high-assurance, c++ embedded systems but, when examining the reasons why, C++17 Polymorphic Memory Resources emerge as an unexpected solution to enable the use of C++ standard library constructs for such projects. My talk will explore how PMR can be used to meet functional safety requirements and to build embedded systems that are robust, performant, and testable.

C++26: More constexpr in the Standard Library -- Sandor Dargo

SANDOR_DARGO_ROUND.JPGHere are the standard library features that will soon be usable at compile time. One topic is missing: exceptions. As they need both core language and library changes, I thought they deserved their own post.

C++26: More constexpr in the Standard Library

by Sandor Dargo

From the article:

P2562R1constexpr stable sorting

This paper proposes making std::stable_sortstd::stable_partitionstd::inplace_merge, and their ranges counterparts usable in constant expressions. While many algorithms have become constexpr over the years, this family related to stable sorting had remained exceptions — until now.

The recent introduction of constexpr containers gives extra motivation for this proposal. If you can construct a container at compile time, it’s only natural to want to sort it there, too. More importantly, a constexpr std::vector can now support efficient, stable sorting algorithms.

A key question is whether the algorithm can meet its computational complexity requirements under the constraints of constant evaluation. Fortunately, std::is_constant_evaluated() provides an escape hatch for implementations. For deeper details, check out the proposal itself.

CppCon 2024 Back to Basics: Unit Testing in C++ -- Dave Steffen

unittesting-steffen.pngRegistration is now open for CppCon 2025! 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 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 2025!

Back to Basics: Unit Testing in C++

by Dave Steffen

Summary of the talk:

Unit Testing is a big, complicated subject. With good advice coming in from books, conference talks, and blog posts beyond count, it's a daunting topic even for experienced developers.  Can we make the subject more approachable?

Yes we can.  If we look a little deeper, there are some fundamental principles behind the advice. Further, these principles seem to belong to a small number of "domains", each addressing a very different aspect of unit testing and software development.

For example, "Test error conditions separately", "Tests should be easy to read", and "Write the unit tests first" are all great advice, but each is aiming for a very different goal.

In this talk, we'll survey these domains of unit testing practice, identify some of the basic practices involved in each, and put the larger discussion of unit testing into a more useful context.  We will also see how some unit testing practices enhance or conflict with others, and how these controversies reveal deep philosophical questions that have real consequences for how we go about the day-to-day activity of testing our code.

The voting on the talks for Meeting C++ 2025 has begun!

This week the voting for the talks at Meeting C++ 2025 starts!

The voting on the talks for Meeting C++ 2025 has begun!

by Jens Weller

From the article:

Once again its time for the C++ community to take a look at the submitted talks for Meeting C++ 2025! Thanks to all folks who have submitted a talk to this years conference! Your contribution will create another great conference in Berlin and online! And special thanks to all folks who have bought tickets already for the conference, you'll have a bit more weight in the voting to shape this years program!

With your voting session you can contribute to the talk selection for this years conference. In total 107 talks are submitted by 73 speakers. With this year the call for talks closes earlier than in the past, when for a few years it had extended to match the submission date with CppCon. Since last year CppCon has moved its deadline into early/mid May, which is a bit too early. For the future I plan to have the call for talks close around the beginning of June. A period of 2 months to submit should be enough, also this allows for an earlier release of the program. This than gives speakers more time to get their talks ready and Meeting C++ more time to advertise the program...

 

CppCon 2024 The Main Points in C++ - Dots in C++ -- Miodrag Misha Djukic

mainpoints-djukic.pngRegistration is now open for CppCon 2025! 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 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 2025!

Lightning Talk: The Main Points in C++ - Dots in C++

by Miodrag Misha Djukic

Summary of the talk:

A simple element of punctuation marks -- a point (dot) -- but used for so much. What are the all the ways a point is used in C++? Can you list them all? One point (dot), two points (colon), three points (ellipsis), four points (double colon). Let’s quickly go over all the usages: a well known ones, but also some that are encountered not so often.

Fixing exception safety in our task_sequencer -- Raymond Chen

RaymondChen_5in-150x150.jpgSome time ago, we developed a task_sequencer class for running asynchronous operations in sequence. There’s a problem with the implementation of Queue­Task­Async: What happens if an exception occurs?

Fixing Exception Safety in our task_sequencer

by Raymond Chen

From the article:

Let’s look at the various places an exception can occur in Queue­Task­Async.

    template<typename Maker>
    auto QueueTaskAsync(Maker&& maker) ->decltype(maker())
    {
        auto current = std::make_shared<chained_task>();
        auto previous = [&]
        {
            winrt::slim_lock_guard guard(m_mutex);
            return std::exchange(m_latest, current); ← oops
        }();

        suspender suspend;

        using Async = decltype(maker());
        auto task = [](auto&& current, auto&& makerParam,
                       auto&& contextParam, auto& suspend)
                    -> Async
        {
            completer completer{ std::move(current) };
            auto maker = std::move(makerParam);
            auto context = std::move(contextParam);

            co_await suspend;
            co_await context;
            co_return co_await maker();
        }(current, std::forward<Maker>(maker),
          winrt::apartment_context(), suspend);

        previous->continue_with(suspend.handle);

        return task;
    }

If an exception occurs at make_shared, then no harm is done because we haven’t done anything yet.

If an exception occurs when starting the lambda task, then we are in trouble. We have already linked the current onto m_latest, but we will never call continue_with(), so the chain of tasks stops making progress.

To fix this, we need to delay hooking up the current to the chain of chained_tasks until we are sure that we have a task to chain. 

CppCon 2024 Cost of C++ Abstractions in C++ Embedded Systems -- Marcell Juhasz

abstractions-juhasz.pngRegistration is now open for CppCon 2025! 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 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 2025!

Cost of C++ Abstractions in C++ Embedded Systems

by Marcell Juhasz

Summary of the talk:

This session will feature detailed case studies that measure the overhead associated with common programming abstractions in the context of embedded systems. By examining both compile-time and run-time implications, attendees will gain valuable insights into how these abstractions impact system resources like memory usage and execution speed.

Key areas of exploration will include:

Encapsulation: Assessing the cost of data hiding and interface protection depending on implementation strategies.
Inheritance: Evaluating the costs and benefits of using class hierarchies in environments where memory and processing power are limited.
Polymorphism: Comparing run-time polymorphism via virtual functions to compile-time alternatives like templates and concepts, analyzing their respective impacts on performance and flexibility.

Through empirical data and performance metrics, participants will observe how traditional object-oriented techniques affect resource utilization. The discussion will also cover the advantages and trade-offs of these techniques, providing a balanced view of their impact on embedded systems.

Designed for developers and system architects working within the constraints of embedded systems, this talk aims to provide valuable insights into making informed decisions about when and how to use specific programming abstractions. Attendees will leave with a clearer perspective on optimizing their code for maximum efficiency, armed with practical knowledge about the trade-offs involved in adopting various software design paradigms.