C++26 to Feature Compile-Time Reflection: Goodbye Boilerplate, Hello High Performance

2025-06-22

Herb Sutter has announced that C++26 will include compile-time reflection, a game-changer for C++ development. Compile-time reflection provides access to a program's own structure, enabling tasks like enumerating a class's methods. This is particularly impactful for libraries like simdjson, allowing high-speed conversion between custom data structures and JSON strings without boilerplate code. The article demonstrates generating efficient SQL insert statements using compile-time reflection, reducing boilerplate and improving code reusability and safety. While the code might look complex, the performance gains and code simplification are significant.

Read more

Optimizing Integer Division in C++: Templates, Lambdas, and Metaprogramming

2025-03-16

This article explores several approaches to optimizing integer division in C++. Direct integer division can be inefficient, especially when the divisor is known at compile time. It starts by demonstrating the use of C++ template functions, allowing the compiler to optimize when the divisor is a compile-time constant. However, template functions can increase code complexity. The article then attempts to simplify the code using lambda expressions and template lambda expressions, but encounters issues with directly using template lambdas, requiring the use of `operator()` for invocation. Finally, it compares the pros and cons of various methods, including simple lambdas and more advanced template metaprogramming techniques, suggesting the most suitable approach depending on the context.

Read more