SFINAE and Concepts in C++

SFINAE and Concepts in C++

In C++, SFINAE and Concepts are both core techniques in C++ template metaprogramming, used to constrain and filter template parameters at compile time, enabling more flexible and safer generic programming. 1. SFINAE (Substitution Failure Is Not An Error) 1. Definition SFINAE is a compile-time mechanism in C++ template programming, which means: When template parameter substitution … Read more

Key Features of C++20

Modules Brief overview Constraints and Concepts Brief overview Coroutines Using stackless coroutines offers great performance, but they are quite complex to understand. Three-way Comparison Operator <=> <span>auto operator<=>(const C&)const=default;</span> will automatically generate comparison operators within class C, including<span>==, !=, <, <=, >, and >=</span> If you need to customize<span>operator<=></span>, you must also implement<span>operator==</span> The return … Read more

Building a High-Performance Iterable Circular Buffer with Modern C++ (Complete Code Included)

In embedded systems, network programming, or real-time data stream processing, we often need a fixed-capacity queue structure that supports overwrite. A typical representative of this structure is the Circular Buffer. This article will guide you through implementing a modern C++ style circular buffer from scratch, supporting: ✅ Compile-time fixed capacity✅ Automatic overwrite of the oldest … Read more

Exploring C++20 Coroutines: How to Make Asynchronous Code as Simple as Synchronous Code with Just One Line?

Have you ever found yourself trapped in the “callback hell” of asynchronous programming? Have you lost the logic of your code in layers of nested lambdas? C++20 coroutines were born to rescue you from this predicament. 1. What Are We Talking About When We Talk About Asynchronous Programming? Consider a simple requirement: asynchronously read data … Read more

In-Depth Analysis of C++20 Features: Design Motivation and Application Strategies of [[no_unique_address]]

1. Introduction: The Mystery of Empty Type Space In the object model of the C++ language, an “empty class”—that is, a type that contains no non-static member variables, virtual functions, or base classes—should theoretically have zero size. However, the C++ standard states: Every complete object must have a unique address. This means that even if … Read more

Designated Initializers in C++ 20

C++ supports direct assignment initialization for aggregate types, in the form of: T object = { arg1, arg2, … }; Starting from C++11, list initialization was introduced, which is also applicable to aggregate types: T object { arg1, arg2, … }; C++20 introduces a new form of initialization for aggregate types, known as designated initialization … Read more

sml2: A Powerful C++20 State Machine Library

sml2: A Powerful C++20 State Machine Library

sml2: A Powerful C++20 State Machine Library In modern software development, state machines are a crucial design pattern that helps developers better manage and organize complex program logic. sml2 is a state machine library based on C++20 that offers powerful features and efficient performance while maintaining simplicity and ease of use. Features Based on UML-2.5 … Read more

C++20 Overloading the Spaceship Operator for Comparing DirectX Vector Values

C++20 Overloading the Spaceship Operator for Comparing DirectX Vector Values

The C++20 standard introduces a comparison operator “<=>” (Spaceship operator), which is used to compare two values and return the result of the comparison. Compared to sequential size checks, the “Spaceship operator” simplifies the process of comparing values, making the code more concise.The result returned by the Spaceship operator belongs to strong_ordering, partial_ordering, and weak_ordering. … Read more

Understanding the Underlying Principles of static_assert in C++

Understanding the Underlying Principles of static_assert in C++

Today, I would like to share a very practical yet often overlooked feature in C++11— the underlying principles of static_assert. This question is frequently asked in interviews at large companies. This article will systematically analyze the essence of static_assert from four dimensions: syntax evolution, compilation mechanism, practical comparisons, and advanced features, covering key content such … Read more

Bext-UT: A Lightweight Unit Testing Framework for C++ Developers

Bext-UT: A Lightweight Unit Testing Framework for C++ Developers

Bext-UT: A Lightweight Unit Testing Framework for C++ Developers In the process of C++ development, unit testing is an important means to ensure code quality. Bext-UT (also known as UT/μt) is a modern, lightweight C++20 unit testing framework that provides developers with an efficient and easy-to-use testing solution through its concise design and powerful features. … Read more