A highly relevant group of professionals to review this topic is Senior C++ Library Developers and Template Metaprogramming Specialists.
Abstract
This presentation by Joel Falcou details the architectural evolution of high-performance C++ libraries, specifically focusing on the EVE (SIMD abstraction layer) and KIWAKU (multi-dimensional array toolkit) projects. The core objective is to transition from traditional template metaprogramming complexity toward improved API ergonomics by leveraging modern C++20 features.
Falcou outlines design strategies to reduce friction, including using callable objects combined with bracketed options (decorators) to manage instruction variation (e.g., masking and saturation) without creating an exponential number of function overloads. A central finding is the necessity of minimizing compilation time and maximizing error clarity by strategically applying Concepts for API misuse detection at the user call site and reserving if constexpr for internal implementation selection, thereby avoiding lengthy, obfuscated template error cascades. The discussion extends to the use of Class Template Argument Deduction (CTAD) for flexible container construction and concludes with a proposal to reinterpret Object-Orientated SOLID principles within the framework of Generic Programming to ensure long-term library maintainability and extensibility.
Field Report: Ergonomic C++ Library Design
06:48 API Design Complexity: Designing the API is identified as the most challenging aspect of library development, particularly for high-performance, domain-driven applications (HPC) where non-disruptive integration and efficiency are paramount.
11:24 Intuitive Design Principle: A core goal is to design APIs that are easy to use correctly and structurally hard to use incorrectly, necessitating early and clear reporting of incorrect usage, ideally as compilation errors driven by logical constraints.
13:56 EVE Architecture & Overloads: The SIMD abstraction layer (EVE) is built primarily on free functions. Handling variations (e.g., masked or saturated operations) led to an unsustainable number of overloads (up to 55 for basic functions like addition) under legacy systems.
17:45 Decorator Pattern Implementation: Flexibility is achieved by implementing operations as callable objects that can be modified via bracketed option types (e.g., function[option](args)). This pattern avoids combinatorial overload explosion.
20:21 C++20 Feature Leverage: Concepts are used exclusively for ensuring function call validity and dispatching over type capabilities at the high level. (31:28) Implementation details are managed using if constexpr within a single function body to select between intrinsics, emulation, or optimization strategies, thereby minimizing overloads.
33:20 Error Locality is Critical: The library is strictly designed to ensure compilation errors resulting from user misuse are reported at the user's call site, not deep within the library's internal headers. This drastically improves usability and reduces user frustration with "god-tier" error messages.
35:29 Compile-Time Reduction: Refactoring the dispatch mechanism to rely less on automatic type deduction (especially avoiding raw auto return types in public interfaces) reduced compilation time by approximately 50% (from 8.5 seconds to 4.3 seconds in the demonstrated test case).
39:13 The "Ignore Trick" for Assertions: An empty, convertible type (ignore) is used as a placeholder return for unimplemented execution branches. This allows logic errors to be cleanly reported via static_assert without triggering subsequent, cascading compilation failures in dependent code paths.
40:59 Reserved Static Assert Usage:static_assert is reserved specifically for detecting and reporting logical errors known at compile time (e.g., shifting bits beyond the type size), separating its function from type capability validation handled by Concepts.
46:35 KIWAKU Container Design: The multi-dimensional array library, KIWAKU, implements the owning container (Table) as a View over an internal buffer, unifying the core API for both owning and non-owning contexts.
48:49 CTAD Abuse for Construction: Complex configuration of containers is handled by extensively leveraging Class Template Argument Deduction (CTAD) combined with named parameters, allowing the exact required type to be computed at compile time without verbose template arguments.
52:40 Accidental Compilation Optimization: Extensive template nesting resulted in extremely large symbol names. It was discovered that reducing the length of the internal detail namespace (e.g., renaming detail to _) measurably decreased compilation time by reducing the size of symbol table entries.
57:51 Adapting SOLID for Generic Programming: The presentation concludes by proposing a set of equivalent design principles for generic/template programming: Single Type/Function Responsibility, Software Extension via Overloads/Specialization, Refined Concepts complementing Base Concepts, prioritizing specific libraries over monolithic general-purpose ones, and depending on Concepts rather than concrete Types.
1:00:38 Influences: Early inspirations for EVE included std::atomic (for wrapping low-level hardware) and vector libraries from Agner Fog and SDE, with the ultimate goal being a more comprehensive, standardized-feeling SIMD wrapper.