How to Write a C++ Test Framework
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.
[C++] Lets Review my Article on Type Erasure
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.
Crafting a Cucumber Interpreter in C/C++
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.
[C++] A std::tuple To Concatenate Validation Criteria
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
[C++] Use Type Erasure To Get Dynamic Polymorphic Behavior
This is a simple and short example to understand the idea of type erasure. In this article we create a simple class which can erase your concrete types and illustrates the general behavior and what it requres to have polymorphic behavior at runtime. For a more comprehensive understanding and include tests, I recommend watching Klaus Iglbergers talk about this topic from CppCon 2022.
[C++] A Boost Asio Server-Client Example
A simple server-client example in C++ with Boost Asio. Here I create a server which can accept multiple clients. For the demonstration purpose we send a simple string to the server which is then printed to stdout. This is a really simple example but it helps especially when you start with Boost Asio and networking.
[C++] Static, Dynamic Polymorphism, CRTP and C++20’s Concepts
C++20 offers really nice features and a very great one is concepts. In this article I compare existing techniques to implement interfaces (dynamic polymorphism, CRTP) to a new approach by using concepts. With concepts we have a lot of advantages and it affects the current way we write code. It’s clearer and it’s better to understand.
[C++] Building And Publishing Conan Packages
Conan is a nice tool to manage packages and dependencies in C++ projects. I already wrote two articles about getting started and how to use Conan with google protobuffer. In this article I create an own library and publish it pre-build on the Artifactory. Now we can access own dependencies from our own Artifactory.
[C++] Start Using Cucumber
The Cucumber Framewrok enables behavior driven development in your projects. Add tests in a given-when-then style which are readable for basically everyone. In this post we setup cucumber for C++ on a ubuntu machine with it’s dependencies. We’ll use googletest as testframework underneath
[C++] A C++17 Statemachine using std::tuple and std::variant
One of my favorite design patterns is the state machine pattern. I used to do this pattern with an abstract where then all concrete states inherit from. During runtime I was able to assign new states to a state machine, let’s do this in another way to get rid of dynamic allocation with C++17
[C/C++] A Lua C API Cheat Sheet
A cheat sheet for the Lua C API with 11 examples to pass variables, functions, tables, arrays, etc. from Lua to C and vice versa. This is a tutorial about the C API and explains how to work with the Lua stack. This is a guide to understand Lua in C and prepares to start writing on Lua bindings.
[C++] An Eventsystem Without std::bind / std::function
An eventsystem written in C++ without using std::bind and std::function. Define specific events and dispatch them to desired functions. A nice way to handle events and pass them to different locations in your code.
[C++] Typed Tests For Interfaces With Googletest
Typed tests with googletest are useful when we want to test interfaces. Typed testing avoids writing redundand tests for each implementation and guarantee that the all derived classes will run the same tests.
Use Frameworks But Don’t Marry Them
Using a frameworks has many benefits and takes a lot of work from you, but don’t marry the framework and avoid a hard dependency.
[C++] Protobuf: Project Setup With Conan and CMake
Creating a clean project to use protobuf with Conan and CMake