Package management with CMake’s CPM

I’ve used conan and vcpkg with varying levels of success. Recently, I came across CPM.cmake and it works quite well with the projects I have used it in. For getting CPM.cmake in your own CMake project, you have to download the CPM.cmake code: The above code will download the CMake module and after that, you … Read more

clang static analyzer

I used Xcode and loved the static analyzer. Then I switched to Visual Studio Code to do my C++ programming and wanted the static analysis done on my own code. To do this with the LLVM tools, you use the tool scan-build. You have to call that CLI first before cmake, and you should use … Read more

C++ std::erase and rbegin/rend

Once. Only once have I done this. I had to traverse a std::vector in reverse, and at some point, I had to call std::erase. I thought, “Ok, this should work” and instead, something bad happened. I little digging around, and a stackoverflow.com answer later, I saw an answer that left me scratching my head. The … Read more

Mandelbrot Set

I’m quite fascinated with the image that the Mandelbrot Set produces, but admittedly, I didn’t understand how to implement the function from the description on Wikipedia. Thankfully, there are 2 really good videos that give an overview and an in depth explanation of the function, which you can watch at: Mandelbrot back to basics: https://youtu.be/FFftmWSzgmk … Read more

C++ std::next

Another way to increment an iterator, and preferred if you’re using std::move in your code, is to use std::next over ++. Here’s an example: Now, since we are not modifying anything in our string, we could also use const iterators, simply replacing begin and end with cbegin and cend : Languages:C++11, C++17 Refs: https://en.cppreference.com/w/cpp/iterator/next https://en.cppreference.com/w/cpp/iterator/begin

C++20 std::source_location

This is a compile time utility, which replaces macros like FILE and LINE. I’m partial to using functions over macros, and this compile time utility looks nice: This is weak example of what you can do with the above class, but you get the idea.

Canonicalizing a URL path using std::filesystem::canonical

More specially, a file path where we are trying to remove .. and . So, if you have “projects/vectorization/../gitstuff/./../../something/index.html” canonicalizing the string would reduce it to “something/index.html” We have a couple of options to do this. Option 1 – use std::filesystem Since C++17, you can take a path, and canonicalize it using std::filesystem::canonical. For paths … Read more

C++ std::rotate

This is an interesting template function, defined in , which moves elements of a container class, much in the same way when you rotate the number wheel on a luggage combination lock: rotate the wheel to the left, all of the numbers move along with that rotation; rotate the wheel to the right and the … Read more

C++ stack

In some sample code, you may see a reference to stack. This is a type of data structure, that according to cpp-reference : This is actually a wrapper for another container class. An example of it’s use is:

Using C++ std::merge

There have been a few times that I needed 2 vectors to be … merged… and they had to be ordered. It’s simple when you have a plain old type, and are using the back_inserter to append the contents of each vector to the end of the merged vector, but what if you want to … Read more