C++: How to Access Private Members VALIDLY

Intro In most contexts, private members are forbidden to access outside its class. But as the title says, I’ll show you a way to validly access them. Valid, here, I mean it’s well-defined according to the standard, and not causing undefined behavior. This post is inspired by a post more than 10 years ago. It introduces this technique but doesn’t explain why. What does the standard say? There’re two places where private are allowed to be used outside its enclosing class,...

August 10, 2022 · Last updated on August 10, 2022 · 3 min

C++: Elegant Ways to Map Runtime Values to Types

This post introduces two elegant ways to dispatch based on runtime values.

July 31, 2022 · Last updated on July 31, 2022 · 3 min

Algorithms behind Popcount

Three algorithms of popcount.

July 17, 2022 · Last updated on July 17, 2022 · 6 min

C++ Virtual Table Tables(VTT)

It’s a detailed explanation about virtual table tables(VTT) in C++.

May 18, 2022 · Last updated on May 18, 2022 · 7 min

What does C++ Object Layout Look Like?

Explain the object memory layout of C++ based on Itanium ABI specification.

May 8, 2022 · Last updated on May 8, 2022 · 12 min

A Subtle Bug Before C++17

This post will show you a subtle performance bug due to unsupport for over-aligned types before C++17.

April 21, 2022 · Last updated on April 21, 2022 · 3 min

Iyengar111 NanoLog Source Code Reading

Overview Iyengar111/NanoLog is a fast and lightweight C++11 logging library. It has only less than a thousand lines of code. It’s less famous than another eponymous version, and this repo seems not under maintenance any longer. I read the source code for learning. This post delves into its technique details. Usage #include "NanoLog.hpp" int main() { nanolog::initialize(nanolog::GuaranteedLogger(), "/tmp/", "nanolog", 1); // nanolog::initialize(nanolog::NonGuaranteedLogger(3), "/tmp/", "nanolog", 1); LOG_INFO << "this is " << 42; return 0; } There are two modes to set when initializing....

April 9, 2022 · Last updated on April 9, 2022 · 11 min

Glog Source Code Reading Notes

A note for reading the source code of glog

March 12, 2022 · Last updated on March 12, 2022 · 12 min

How to Return Values Effectively in C++

This post will tell you the practices for returning values in Modern C++

March 1, 2022 · Last updated on March 1, 2022 · 7 min