Coding With Thomas
Hi there and welcome to my software blog, where I write about C/C++ and general software topics. Enjoy!
Latest Articles:
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
This is a basic example of how to render a triangle into a framebuffer with OpenGL / GLFW and display this in a Dear ImGui window. This is a basic example in C++, which renders a green triangle into a framebuffer and creates a texture of it. Finally this will be displayed in a Dear ImGui window.
Create a good notation to convert units, like seconds or ms. I used C++11 User-Defined Literals and a specific time type to handle my time units. This approach can also be applied to other units, like meters. Now the code appears more clear because I have a specific notation to distinguish times and can also compare my values correctly without casting it on clients side.
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.