Self-Implementation of C++17 Any Class

Self-Implementation of C++17 Any Class

Self-Implementation of C++17 Any Class 1. Introduction The Any class is a standard class introduced in C++17, included in the header file , with the core functionality of storing a single piece of data of any type, while the type does not need to be determined at compile time. It implements type erasure, making it … Read more

Analysis of the Underlying Principles of std::function in C++: How to Use It with Callback Functions?

Analysis of the Underlying Principles of std::function in C++: How to Use It with Callback Functions?

Have you ever experienced this: writing a GUI button click callback using function pointers is quite cumbersome — trying to bind a lambda with captures results in an error, and binding a class member function requires passing the ‘this’ pointer, leading to increasingly messy code; until you switch to std::function, and suddenly realize that whether … Read more

C++ std::function: From Type Erasure Implementation to High-Performance Practices

C++ std::function: From Type Erasure Implementation to High-Performance Practices

Before the advent of the C++11 standard, developers faced a tricky problem: how to store, pass, and invoke different types of callable entities in a unified manner? Ordinary function pointers cannot adapt to member functions (which require binding the <span><span>this</span></span> pointer), the type closure of functors (function objects) prevents cross-type generality, and the implementation of … Read more

C++ Type Erasure Technology

C++ Type Erasure Technology

1 Type Erasure1.1 OverviewC++ is a strongly typed language, but when it comes to abstract design, the hard coding caused by strong typing can become a hassle. This is where we need the help of type erasure technology. Type erasure is a programming technique that allows you to operate on various concrete types through generic … Read more