Tag C++

Boost ASIO basics

Boost ASIO library is the defacto standard for network and low-level I/O programming. It has a great documentation available online, but there are a lot of methods and classes in the library. Therefore, if it is your first attempt to use it, it can be a bit challenging. Since there is a lot of ground to cover in the Boost ASIO library, I will only cover the work scheduler and the synchronous methods in this post. The asynchronous methods and timers will be covered in following posts. During this... (read more)

Thread, future and promise

In the C++11 standard several concurrency related classes were added. I will talk about thread, future and promise. Yes, I know there are others more useful than these three. However, I think that it is really important to know well the bases to be able to use the more complex ones properly. As usual, I am working from an Arch Linux computer. Therefore, I can install Clang and the tools from the repository (clang). For other distributions you can find the information in the documentation. As always,... (read more)

Clang sanitizers

Clang is a compiler front end for the C, C++, Objective-C and Objective-C++ programming languages. It uses LLVM as its back end. In this post I talk about some of the sanitizers available in Clang (some are avilable in GCC as well). They help you detect problems at run time (dynamic analysis). As usual, I am working from an Arch Linux computer. Therefore, I can install Clang and the tools from the repository (clang). For other distributions you can find the information in the documentation. As always,... (read more)

Lambda expression comparison between C++11, C++14 and C++17

In this post I talk about what has been added in the C++ standard regarding lambda expressions since they were introduced in C++11. All the code and configuration files used in this post are available in this repo in GitHub. What is a lambda expression? A lambda expression is a simplified notation for defining and using an anonymous function object. Instead of defining a named class with an operator(), later making an object of that class and finally invoking it.[^1] I do not explain all the options... (read more)

Prefix trees: Comparison between Trie, Ternary Search Tree and Radix Tree

In this post I talk about three data structures I implemented to compare their performance in different scenarios. The three data structures are Trie, Ternary Search Tree and Radix Tree. All the code for the data structures as well as the tested scenarios are available in this repo in GitHub. Introduction What is a prefix tree? It is an ordered tree data structure that is used to store a dynamic set of elements where the key is a string. All the data structures that I implemented have the following... (read more)

Clang tools: clang-format, clang-tidy and clang-modernize

Clang is a compiler front end for the C, C++, Objective-C and Objective-C++ programming languages. It uses LLVM as its back end. There are also several awesome tools build on top of Clang and I am going to show the three of them I use the most. As usual, I am working from an Arch Linux computer. Therefore, I can install Clang and the tools from the repository (clang, clang-tools-extra). For other distributions you can find the information in the documentation. As always, all the code used in this... (read more)

Unit test with Google Mock for C++

This post is a continuation from a previous post called Unit test with Google Test for C++, but in this post we are going to use Google Mock, that extends the functionality of Google Test. Google Mock is one of the available frameworks for C++ to mock objects in unit tests. In this example I will use the same technologies as for the previous one: CMake to configure the project and build it, for the dependency manager I will use the new and shiny conan. All the code and configuration files used in... (read more)

rr debugger, record once, replay tens of times

rr is a debugging tool from Mozilla that enhances the behaviour of GDB. It can be found in GitHub, but my recomendation is to go first to the website of the project. In the website you can find really useful information and documentation. As usual, I am working from an Arch Linux computer. Therefore, I can install rr from the AUR repository (rr). For other distributions you can find the information in the documentation. As always, all the code used in this post is available in this repo. The videos... (read more)

Cling a C++ interpreter based on Clang

Cling is an interactive C++ interpreter, built on top of Clang and LLVM compiler infrastructure. It can be found in GitHub (Note: Lately there has not been that much development on it). Since I use Arch Linux I am lucky to have cling in the AUR repository (cling-git). For other ones you can use the cling-all-in-one repo that contains a script to download all dependencies, compile and build cling for you. As always, all the code used in this post is available in this repo The videos are made with... (read more)

Unit test with Google Test for C++

Google Test is one of the available Frameworks to create unit test for C++. In this example I will use CMake to configure the project and build. Furthermore, for the dependency manager I will use the new and shiny conan. Before starting, why use a dependency manager such as conan or software to configure and build such as CMake? Because these technologies are widely use it in real projects. All the code and configuration files used in this post are available in this repo in GitHub. Step 1 Install... (read more)