Coding With Thomas
Hi there and welcome to my software blog, where I write about C/C++ and general software topics. Enjoy!
Latest Articles:
A long time ago I had a question about how Googletest or Catch2 implement their macros to run all the unit tests they write. While writing the implementation for CWT-Cucumber: A C++ Cucumber Interpreter, I needed the same mechanism to achieve this particular behaviour. Registering functions before main is executed. In this article I write a proof of concept for a C++ test framework.
I have implemented a Cucumber interpreter in C++20. CWT-Cucumber: A C++ Cucumber interpreter is my project for this and except for the rules I have implemented all Cucumber features to the best of my knowledge. In addition, there is a Conan recipe to create a Conan package. This means that there is now a native C++ Cucumber interpreter available without third party dependencies.
Someone pointed out that my type erasure example in the other article was broken and called a destructor twice. I investigated this and modified the example, adding an emplace method. In the end it still seems understandable to me, so lets check out this C++ Type Erasure.
I created a C/C++ Cucumber interpreter, based on “Crafting Interpreters” by Robert Nystrom. It compiles a feature file into byte code which is then executed by a vm. The interpreter implementation is C and there are no third party libraries needed to compile and use it. In addition I created C++ bindings to make it easier to use. Check out this article for my initial thoughts and check out the GitHub repository with the project and its examples.
This is my personal best practice and guide so far about Sphinx documentations. We create a Sphinx documentation from scratch, add some C++ and JavaScript source code documentation, include doxygen and finally publish it on GitHub pages. In the first place it looks quite a lot but after working some time with it this is a really good and nice looking way to have a documentation.
In my last example i started to create something similar to C++23 std::optional's .andthen(..) / .orelse(..) for std::find / std::find_if. I tried to achieve something similiar and write a bit less code with this. Unfortunately it turned out it does not improve my code. But it wasn’t for nothing, because I got one use case with maps where I could at least use my approach.
Finding values in C++ containers can make large if statements or checking iterators often at end(). With C++23's std::optional there are new wrapper functions like .and_then(..). You can pass a lambda and it will only be called if there is a value. I try to do the same with find, which frees me from always checking an iterator.
In this article we go over an easy example to create a static interface. Instead of using a interface with virtual methods, we use a template. This gives flexibility and creates an easy way to change the interface. It also removes the dynamic polymorphism. For the clients we use template meta programming and concepts to check if the interface signatures are correct.
I recently had this problem that I need to store multiple validation functions which returned a bool and I didn’t want to use std::vector or any other runtime container. Concatenating if statements weren’t a good solution either. Ultimately I came up with a solution where I used std::tuple in combination with std::apply
Recently I was given the task of transposing the Abstract Syntax Tree (AST) from GCC to another file format (such as json or xml). To do this I needed a way to access the AST and so I used GCC's plugin system where you can apply customizations to the compilation. In this blog post I will start using GCC's API to create the plugin accordingly. This focuses on accessing the AST itself, there are other ways, such as accessing the gimple representation, which comes later in GCC's compilation process. Check out this article to get started with GCC's plugin system.