Category Archives: Programming

Implementing a std::function<>-like wrapper in C++, part 2: generalizing the return type and arguments

Introduction Previously, we’ve seen a way to implement our own version of std::move_only_function<>. The implementation we ended up with is as follows: This works for any movable function, for example: Unfortunately, it is restricted to the function prototype int fn(int, … Continue reading

Posted in Programming | Tagged | Leave a comment

Implementing a std::function<>-like wrapper in C++, part 1: type erasing

Introduction Recently, a chat with a friend peeked my interested: how would you store an arbitrary function and call it, similar to std::function<>. It turned out a plain C function pointer would suffice for this specific use-case, but I got … Continue reading

Posted in Programming | Tagged | Leave a comment

Behind the magic of magic_enum

Recently, a coworker pointed me towards a C++17 library to convert enumeration values to strings and vice versa. The library called magic_enum (https://github.com/Neargye/magic_enum) and it indeed feels like magic. I was immediately curious: how did they pull this off? The … Continue reading

Posted in Programming | Tagged | Leave a comment