Blog Reboot

It’s been a while

  • 3 minutes to read

It’s been a long time since I’ve last updated this blog – and I think I’m finally ready to reboot it.

A lot has changed since my last article nearly 3 years ago:

  • I changed jobs a number of times, and am now begrudgingly working as a Go

    developer professionally.

  • I found new love of the Rust programming language and started writing rust projects in my spare time.
  • I’ve learned a lot about working in domains ranging from GCP to working embedded on Texas Instruments SoCs .
  • I haven’t written any practical C++ in nearly a year.

I have a lot to talk about, and hope to use this blog as somewhere I can share my knowledge and experiences with others that hope to learn and grow from them.

Continue reading

Reflecting Over Members of an Aggregate

Implementing ‘reflection’ qualities using standard C++

  • 8 minutes to read

A little while back a friend of mine and I were talking about serialization of struct objects as raw bytes. He was working with generated objects that contain padding, but the objects needed to be serialized without the padding; for example:

struct Foo
{
  char data0;
  // 3 bytes padding here
  int data1;
};

In the case he described, there are dozens of object types that need to be serialized, and all are:

  • Generated by his organization (so they can’t be modified), and
  • Are guaranteed to be aggregates

Being a template meta-programmer, I thought it would be a fun challenge to try to solve this in a generic way using c++17 – and in the process I accidentally discovered a generic solution for iterating all members of any aggregate type.

Continue reading

Getting an Unmangled Type Name at Compile Time

A really useful and obscure technique

  • 10 minutes to read

Getting the name of a type in C++ is a hassle. For something that should be trivially known by the compiler at compile-time, the closest thing we have to getting the type in a cross-platform way is to use std::type_info::name which is neither at compile-time, nor is it guaranteed to be human-readable.

In fact, both GCC and Clang actually return the compiler’s mangled name rather than the human-readable name we are used to. Let’s try to make something better using the modern utilities from c++17 and a little creative problem solving!

Continue reading

Builder Pattern: Expressing ownership transfer

A simple underused approach to express moving members out of an object

  • 7 minutes to read

The Builder pattern is a common design in software development for late-binding inputs to allow for iterative construction. This pattern, when applied in c++, leaves one very obvious question: Can we present this to consumers in an optimal way?

More specifically: when we call build(), should we be moving any temporary internal state, or copy it? Can we express both in a safe and idiomatic way to consumers?

Continue reading

Final Poetry

An entry in the C++wtf segment

  • 2 minutes to read

Note The C++WTF segment shines a light on the dark and esoteric corners of the C++ language for fun and profit The C++ standards committee is very strongly against producing any kind of breaking changes when considering new language features – especially keywords. Over the course of standardization, this has lead to terms like auto being repurposed, or awkward keywords like co_await and co_yield being introduced in C++20 to avoid breaking a handful of projects in the world that might possibly be using await or yield in their vocabulary.

Continue reading

Creating a Fast and Efficient Delegate Type (Part 1)

A simple solution to lightweight function binding

  • 10 minutes to read

It’s often desirable when working in C++ to create callbacks that never leave a certain lifetime, and only bind functions or function pointers. The C++ standard only offers std::function and std::packaged_task, both of which are more heavy than they need to be. We can do better. Lets produce a better alternative to the existing solutions that could satisfy this problem in a nice and coherent way.